Skip to content

Instantly share code, notes, and snippets.

View cheeyeo's full-sized avatar
💭
Researching on use of transformers in computer vision

Chee Yeo cheeyeo

💭
Researching on use of transformers in computer vision
View GitHub Profile
class AnonymousUser < User
attr_accessible *ACCESSIBLE_ATTRS, :type, :token, as: :registrant
def register(params)
params = params.merge(type: 'User', token: nil)
self.update_attributes(params, as: :registrant)
end
end
'use strict';
module.exports = function(grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var paths = {
@cheeyeo
cheeyeo / gist:88a05602303a29843712
Last active August 29, 2015 14:01
Autoloading in rails
http://www.zhubert.com/blog/2013/06/02/activemodel-part-1/
http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html
http://guides.rubyonrails.org/plugins.html#generate-a-gemified-plugin
or maybe it needs a railitie:
http://api.rubyonrails.org/classes/Rails/Railtie.html
@cheeyeo
cheeyeo / config.yml
Created May 26, 2014 19:39
YAML loading in ruby 2.1
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: root
password:
development:
<<: *default
database: db_development
@cheeyeo
cheeyeo / gist:f12611c4247288b593c9
Created May 25, 2014 17:03
Streaming csv in ROR
http://smsohan.com/blog/2013/05/09/genereating-and-streaming-potentially-large-csv-files-using-ruby-on-rails/
require 'csv'
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
memstats #4900
CSV.open('visitors.csv', headers: true) do |csv|
visitors = csv.each # Enumerator
memstats # 5164
@cheeyeo
cheeyeo / equi.rb
Created May 15, 2014 20:45
Array equi in ruby
def equi(arr)
return 0 if arr.empty?
left, right = 0, arr.inject{|sum, n| sum + n}
equi_indices=[]
arr.each_with_index do |val,i|
left += val
equi_indices << i if right == left
@cheeyeo
cheeyeo / traffic_light.rb
Created May 12, 2014 20:30
Example of using classes to represent states, removing the need for case statements
class TrafficLight
class State
def to_s
name
end
def name
self.class.name.split('::').last.downcase
end
@cheeyeo
cheeyeo / point.rb
Created May 7, 2014 16:10
Defining idempotent conversion functions
def Point(*args)
respond_to_point = ->(arg){ arg.respond_to?(:to_point) }
respond_to_ary = -> (arg){ arg.respond_to?(:to_ary) }
case args.first
when Integer then Point.new(*args)
when String then Point.new(*args.first.split(':').map(&:to_i))
when respond_to_point
args.first.to_point
when respond_to_ary