Skip to content

Instantly share code, notes, and snippets.

@cball
cball / shell+ruby
Created January 10, 2012 18:13
How to use perftools.rb
# generate profile around a script/test
$ CPUPROFILE=/tmp/my_app_profile RUBYOPT="-r`gem which perftools | tail -1`" ruby -I spec spec/models/user_role_spec.rb
# generate profile using a block
# (this is in ruby obviously)
require 'perftools'
PerfTools::CpuProfiler.start("/tmp/add_numbers_profile") do
5_000_000.times{ 1+2+3+4+5 }
end
@cball
cball / action_mailer.rb
Created November 22, 2011 18:32
Send all email on QA/Staging to alternate address
# add to config/initializers
if hostname =~ /qa/ || Rails.env.staging?
class OverrideMailRecipient
def self.delivering_email(mail)
mail.to = "[email protected]"
end
end
ActionMailer::Base.register_interceptor(OverrideMailRecipient)
end
@cball
cball / gist:1201885
Created September 7, 2011 21:48
Spork & Rspec Guardfile
# More info at https://github.com/guard/guard#readme
guard 'spork', :cucumber => false, :test_unit => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
end