This file contains 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
#Dean's code | |
ACTIVE_RECORD_ENUMS = %w{ | |
AccountType | |
} | |
ACTIVE_RECORD_ENUMS.each do |eclass| | |
eval "class #{eclass} < ActiveRecord::Base; end" | |
eclass.constantize.class_eval do | |
class << self |
This file contains 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
ACTIVE_RECORD_ENUMS = %w{ | |
AccountType | |
} | |
ACTIVE_RECORD_ENUMS.each do |eclass| | |
eclass.constantize = Class.new(ActiveRecord::Base) do | |
def self.id_for(name) | |
ids[name.to_s.strip.humanize.downcase] | |
end | |
This file contains 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 ExternalResourcePersister | |
attr_reader :record, :resource | |
def initialize( resource, record = nil ) | |
@resource = resource | |
@record = record | |
end | |
def create! |
This file contains 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
5a3 | |
{"event":"created","post":{"demographic":{"gender":"female"},"interaction":{"schema":{"version":3},"source":"Twitter for iPhone","author":{"username":"Earth_to_Emily","name":"Emily Thomas","id":55259239,"avatar":"http://pbs.twimg.com/profile_images/378800000303941231/d6aaa986c76bf6c57b59fee0de9da92d_normal.jpeg","link":"http://twitter.com/Earth_to_Emily","language":"en"},"type":"twitter","created_at":"Mon, 13 Jan 2014 18:14:11 +0000","received_at":1389636851.4597,"content":"Today at lunch I was a celebrity. Those were my five minutes of fame.","id":"1e37c7e80361ab80e07493c5fd9ce032","link":"http://twitter.com/Earth_to_Emily/status/422793713887494144","geo":{"latitude":41.36928679,"longitude":-81.84848476},"tags":["139"]},"klout":{"score":34},"language":{"tag":"en","confidence":100},"salience":{"content":{"sentiment":4}},"twitter":{"created_at":"Mon, 13 Jan 2014 18:14:11 +0000","filter_level":"medium","geo":{"latitude":41.36928679,"longitude":-81.84848476},"id":"422793713887494144","lang":"en","place":{"id |
This file contains 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
#rspec testing ActionController::Live | |
#spec/controllers/post_controller_spec.rb | |
require 'spec_helper' | |
describe PostsController do | |
before :each do | |
controller.stub(:authenticate_user!) | |
@now = Time.now | |
Time.stub(:now).and_return(@now) |
This file contains 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
geonameid : integer id of record in geonames database | |
name : name of geographical point (utf8) varchar(200) | |
asciiname : name of geographical point in plain ascii characters, varchar(200) | |
alternatenames : alternatenames, comma separated varchar(5000) | |
latitude : latitude in decimal degrees (wgs84) | |
longitude : longitude in decimal degrees (wgs84) | |
feature class : see http://www.geonames.org/export/codes.html, char(1) | |
feature code : see http://www.geonames.org/export/codes.html, varchar(10) | |
country code : ISO-3166 2-letter country code, 2 characters | |
cc2 : alternate country codes, comma separated, ISO-3166 2-letter country code, 60 characters |
This file contains 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
@array = ["apple" , "orange", "banana"] | |
#Instead of this, | |
@fruit_hash = @array.inject({}) do |hash,fruit| | |
hash[fruit.to_sym] = fruit | |
hash | |
end | |
#How about this | |
@fruit_hash = @array.inject({}) {|hash,fruit| hash.merge(fruit.to_sym => fruit)} |