http://blog.bignerdranch.com/835-its-the-endian-of-the-world-as-we-know-it/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function(grunt) { | |
// load all grunt tasks | |
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
// configurable paths | |
var paths = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: &default | |
adapter: postgresql | |
encoding: unicode | |
pool: 5 | |
username: root | |
password: | |
development: | |
<<: *default | |
database: db_development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://smsohan.com/blog/2013/05/09/genereating-and-streaming-potentially-large-csv-files-using-ruby-on-rails/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrafficLight | |
class State | |
def to_s | |
name | |
end | |
def name | |
self.class.name.split('::').last.downcase | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |