Skip to content

Instantly share code, notes, and snippets.

Avatar

Brandon Keepers bkeepers

View GitHub Profile
@bkeepers
bkeepers / gist:714255
Created Nov 24, 2010
benchmark for delayed_job
View gist:714255
require 'spec/spec_helper'
require 'logger'
require 'benchmark'
Delayed::Job.create_indexes
Benchmark.bm(10) do |x|
Delayed::Job.delete_all
(500...2000).step(500).each do |n|
View watchr-focused
def run(cmd)
system 'clear'
puts cmd
system cmd
end
cmd = ARGV[1..-1].join(' ')
watch('(app|spec|lib|test)/*') { run cmd }
Signal.trap('QUIT') { run cmd }
View irb
>> u = User.first
=> …
>> p = u.projects.first
=> …
>> p.name # Read from embedded doc
=> "MongoMapper"
>> p.description
=> "A Ruby Object Mapper for Mongo" # loads lazy attribute
@bkeepers
bkeepers / irb.rb
Created Oct 2, 2010
Idea for lazily loading attributes in MM
View irb.rb
>> user = User..first
=>
>> user.collaborators_loaded?
=> false
>> user.collaborators.size # <= loads all lazy fields
=> 30
>> user.collaborators_loaded?
=> true
>> user.time_zone_loaded?
=> true
View gist:588601
trap :CLD do
puts "Reaped #{Process.wait}"
end
loop do
pid = fork { sleep 2 }
puts "Spawned #{pid}"
sleep 1
end
View snippet.txt
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
Benchmark.bm(10) do |x|
x.report do
100.times do
100.times { fork {} }
Process.waitall
end
end
end
View gist:581457
require 'selenium-webdriver'
class Capybara::Driver::Selenium < Capybara::Driver::Base
def self.driver
unless @driver
@driver = Selenium::WebDriver.for :chrome
at_exit do
@driver.quit
end
end
@driver
@bkeepers
bkeepers / be
Created Sep 3, 2010
Command to quickly open the source of a Bundler dependency in TextMate
View be
#!/bin/sh
mate `bundle show $1`
@bkeepers
bkeepers / deploy.rb
Created Aug 30, 2010
Hack to get moonshine to work with Rails 2.3
View deploy.rb
task :install_as_rails_2_3 do
sudo "gem install activesupport --version=2.3.8 --no-rdoc --no-ri"
end
before 'ruby:install_moonshine_deps', 'install_as_rails_2_3'
View erlang.log.5
=ERROR REPORT==== 25-Aug-2010::18:59:16 ===
** State machine <0.1857.0> terminating
** Last event in was {riak_vnode_req_v1,
1205132270528594874568590215453917455783181680640,
{fsm,undefined,<9962.5024.0>},
{riak_kv_get_req_v1,
{<<"moves">>,<<"9273">>},
111118152}}
** When State == active
** Data == {state,1205132270528594874568590215453917455783181680640,