Skip to content

Instantly share code, notes, and snippets.

View trak3r's full-sized avatar

Thomas "Teflon Ted" Davis trak3r

View GitHub Profile
doppleganger = Class.new(ActiveRecord::Base)
doppleganger.set_table_name "latest_#{self.class.table_name}"
Object.const_set "Latest#{self.class.name}", doppleganger
doppleganger.find(:first, :conditions => ...)
What's documented:
StreetAddress.find(1, :params => { :person_id => 1 })
# => GET /people/1/street_addresses/1.xml
What actually happens:
StreetAddress.find(1, :params => { :person_id => 1 })
# => GET /street_addresses/1.xml?person_id=1
module Enumerable
def most?(&block)
trues = 0
falses = 0
each do |item|
if yield(item)
trues += 1
else
falses += 1
end
def last_wednesday
today = Date.today
backup = ((4 + today.wday) % 7)
today - backup
end
def remote_file_exists?(full_path)
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end
namespace :remote do
namespace :file do
desc "test existence of missing file"
task :missing do
if remote_file_exists?('/dev/mull')
raise "It's there!?"
ted@ceylon ~/Sites/asm/config/cloud-crowd »crowd load_schema
-- create_table("jobs", {:force=>true})
-> 0.1031s
-- create_table("node_records", {:force=>true})
-> 0.1444s
-- create_table("work_units", {:force=>true})
-> 0.1000s
-- initialize_schema_migrations_table()
-> 0.0009s
-- assume_migrated_upto_version(3)
ted@ceylon ~/Sites/asm/config/cloud-crowd »gem list | grep -i rails
autotest-rails (4.1.0)
rails (2.3.4, 2.3.2, 2.2.2, 1.2.6)
ted@ceylon ~/Sites/asm/config/cloud-crowd »crowd node
Starting CloudCrowd Node on port 9063...
Missing the Rails 2.3.2 gem. Please `gem install -v=2.3.2 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
RAILS_GEM_VERSION = nil
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../../..'))
RAILS_ENV = ENV['RAILS_ENV'] || 'development'
if CloudCrowd.node?
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.logger = Logger.new(STDOUT)
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'environment'))
end
some_variable = begin
if some_condition?
some_value
else
another_value
end
end
class Array
def indifferent_intersection(other)
self.collect{|i| i.to_sym} & other.collect{|i| i.to_sym}
end
end
class Hash
def keyqual?(other)
return true if other.nil?
intersecting_keys = self.keys.indifferent_intersection(other.keys)