Skip to content

Instantly share code, notes, and snippets.

@leshill
leshill / 0-readme.md
Created February 2, 2012 18:46 — forked from burke/0-readme.md
ruby-1.9.3-p0 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@leshill
leshill / gist:1684107
Created January 26, 2012 18:10 — forked from justinko/gist:1684051
Methods to aid in testing without loading the Rails environment
def stub_model(model_name)
stub_class model_name, ActiveRecord::Base
end
def stub_class(class_name, super_class = Object)
stub_module class_name, Class.new(super_class)
end
def stub_module(module_name, object = Module.new)
module_name = module_name.to_s.camelize
@leshill
leshill / match_method.rb
Created December 30, 2011 07:13 — forked from avdi/match_method.rb
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"
def update_main_artist
artist = if rovi_artist
Artist.create(:name => rovi_artist.name)
else
artists.first
end
update_attribute :main_artist_id, artist.id
end
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort
class Array
def method_missing(method, *args, &block)
if key_value = dynamic_mapper?(method)
map_dynamically(key_value[1], key_value[2])
else
super
end
end
def dynamic_mapper?(method)
def javascript_confirm(answer)
page.evaluate_script 'window._confirm = window.confirm'
page.evaluate_script "window.confirm = function(x) { return #{answer} }"
yield
page.evaluate_script 'window._confirm && (window.confirm = window._confirm)'
page.evaluate_script 'window._confirm = null'
end