Skip to content

Instantly share code, notes, and snippets.

class ActionController::Base
alias_method_chain :render, :log
def render_with_log(*args)
old, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ActiveSupport::BufferedLogger.new("fucked_up.log")
render_without_log(args)
ensure
ActiveRecord::Base.logger = old
end
end
class ActiveRecord::Base
extend PoorMigrations
end
class User < ActiveRecord::Base
column :age, :integer
# Always recreate name column
column :name, :string, :force => true
end
@lifo
lifo / gist:11172
Created September 17, 2008 00:53
# Released under WTFPL - http://sam.zoy.org/wtfpl/
module PoorMansMigrations
def self.extended(base)
base.class_inheritable_accessor :migration_columns
base.migration_columns = []
end
def column(name, type, options = {})
self.migration_columns << {:column_name => name, :column_type => type, :options => options}
end
@lifo
lifo / Results
Created September 17, 2008 23:14
Without Block map: allocated: 11992K total in 2040004 allocations, GC calls: 645, GC time: 394 msec
With Block map: allocated: 6992K total in 90004 allocations, GC calls: 10, GC time: 17 msec
Without Block min: allocated: 78K total in 20004 allocations, GC calls: 5, GC time: 4 msec
With Block min: allocated: 78K total in 20004 allocations, GC calls: 4, GC time: 3 msec
actionpack/test/controller/components_test.rb: assert_deprecated do
actionpack/test/controller/render_test.rb: assert_deprecated do
activerecord/test/cases/aggregations_test.rb: assert_deprecated 'conversion block has been deprecated' do
activerecord/test/cases/pooled_connections_test.rb: assert_deprecated('ActiveRecord::Base.allow_concurrency') do
activerecord/test/cases/validations_i18n_test.rb: assert_deprecated('ActiveRecord::Errors.default_error_messages') do
activerecord/test/cases/validations_i18n_test.rb: assert_deprecated('using %s in messages') do
class Object
def try(method, default = nil)
respond_to?(method) ? send(method) : default
end
end
def self.get_object_with_sex(attrs)
new(attrs) do |o|
o.uuid = 'wow'
end
end
require 'performance/test_helper'
class BrowsingTest < ActionController::PerformanceTest
self.profile_options = { :benchmark => false,
:runs => 1000,
:min_percent => 0.01,
:metrics => [:process_time],
:formats => [:graph_html],
:output => 'tmp/performance' }
puts "Hello world"
def hello(proc)
proc.call
end
hello proc{puts "hey"}
hello proc{puts 1+1}