Skip to content

Instantly share code, notes, and snippets.

View dkubb's full-sized avatar
🏠
Working from home

Dan Kubb dkubb

🏠
Working from home
  • Betterment
  • Mission, BC, Canada
  • X @dkubb
View GitHub Profile
# current code:
unless @users = cache_get("active_users")
@users = User.all(:active => true)
cache_set("active_users", @users)
# object caching can be used to avoid pulling huge amounts of data
# from the database.
# you could have calle cache_set with an expiration time as well:
# cache_set("active_users", @users, 10)
end
it 'should save both the object and parent if both are new' do
pending('This is a bug that should be fixed') do
area1 = Area.new(:name => 'area1')
area1.machine = Machine.new(:name => 'machine1')
area1.save
area1.machine_id.should == area1.machine.id
end
end
father = Father.new
child = Child.new(:father => father)
father.save
child.father_id.should == father.id # how? the child references the father, but there's no backlink atm
# ... unless
# inside Rakefile
unless ARGV.any? && ARGV[0][0..3] == 'dm:'
Kernel.send(:undef_method, :repository)
end
@identity_map = Hash.new do |h,model|
resource = h[model.base_model]
# set the IM if the resource's model is an ancestor of model
h[model] = resource if resource.model >= model
end
Merb::BootLoader.after_app_loads do
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, Merb.logger.level)
end
get '/posts/:id' do |id|
# ...
end
resource 'posts/:id' do
get do |id|
# show post id
end
put do |id, post|
# change post id, with the body params in "post"
end
delete do |id|
@dkubb
dkubb / css_coverage.rb
Created October 8, 2008 07:55
Ruby CSS Coverage Tester
#!/opt/local/bin/ruby
# Copyright (c) 2007 Dan Kubb <dan.kubb@gmail.com>
# This tool shows any CSS rules that do not apply to HTML. Accepts a single
# argument on the command line, may be either a URI or an HTML file.
require 'rubygems'
require 'csspool'
require 'hpricot'
def xmlschema_datetime(dt)
string = sprintf '%4d-%02d-%02dT%02d:%02d:%02d', dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec
string << sprintf('.%06d', dt.sec_fraction * 86400 * 10**6) if dt.sec_fraction.nonzero?
string << dt.zone
end