Skip to content

Instantly share code, notes, and snippets.

View jerhinesmith's full-sized avatar

Justin Rhinesmith jerhinesmith

View GitHub Profile
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@laserlemon
laserlemon / yajl_encoding.rb
Created May 26, 2011 20:40
YAJL encoding initializer
[NilClass, TrueClass, FalseClass].each do |klass|
klass.class_eval do
def as_json(options = nil)
self
end
end
end
ActiveSupport::JSON::Encoding::Encoder.class_eval do
def encode(value, use_options = true)