Skip to content

Instantly share code, notes, and snippets.

@quamen
quamen / gist:2020715
Created March 12, 2012 08:27
Pizza Dough

Plain dough

Makes 170g dough (enough for one 30 cm pizza)

  • 1 teaspoon dried yeast
  • 1 teaspoon salt
  • 100 ml warm water
  • 2 teaspoons olive oil, plus extra, for greasing
  • 160 g plain (all-purpose) flour, sifted
@quamen
quamen / raise_on_insert.rb
Created August 26, 2011 06:18
Raise on INSERT in the PostgreSQLAdapter
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
def execute(sql, name = nil)
if sql.split(' ').include?("INSERT")
raise "\nDon't write to the database in your unit tests\n #{sql}".red
end
log(sql, name) do
if @async
@connection.async_exec(sql)
@quamen
quamen / no_store.rb
Created July 18, 2011 06:14
An empty Active Support Cache store. lib/cache/no_store.rb
module ActiveSupport
module Cache
class NoStore < Store
def read_entry(name, options)
return nil
end
def write_entry(name, value, options)
end
def delete_entry(name, options)
end
@quamen
quamen / gist:997521
Created May 29, 2011 06:35
Rails 3.1 + Devise + bamboo 1.9.2 on heroku
….1/gems/devise-1.3.4/lib/devise/models/registerable.rb: 16:in `new'
….1/gems/devise-1.3.4/lib/devise/models/registerable.rb: 16:in `new_with_session'
…3.4/app/controllers/devise/registrations_controller.rb: 73:in `build_resource'
…3.4/app/controllers/devise/registrations_controller.rb: 8:in `new'
….9.1/gems/rack-mount-0.8.1/lib/rack/mount/route_set.rb: 152:in `block in call'
…ems/rack-mount-0.8.1/lib/rack/mount/code_generation.rb: 93:in `block in recognize'
…ems/rack-mount-0.8.1/lib/rack/mount/code_generation.rb: 110:in `optimized_each'
…ems/rack-mount-0.8.1/lib/rack/mount/code_generation.rb: 92:in `recognize'
….9.1/gems/rack-mount-0.8.1/lib/rack/mount/route_set.rb: 141:in `call'
…ems/ruby/1.9.1/gems/warden-1.0.4/lib/warden/manager.rb: 35:in `block in call'
@quamen
quamen / cached_resource.rb
Created April 29, 2011 02:26
Module that adds read through caching to ActiveResource with fallback to a permanent cache
require 'active_support/concern'
module CachedResource
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :find, :cache
end
@quamen
quamen / gist:888988
Created March 27, 2011 06:34
Module that adds read through caching to ActiveResource
require 'active_support/concern'
module CachedResource
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :find, :read_through_cache
end
class_attribute :cache_for
@quamen
quamen / gist:888985
Created March 27, 2011 06:33
A read through cache implementation of ActiveResource.find
def find_with_read_through_cache(*arguments)
key = cache_key(arguments)
result = Rails.cache.read(key).try(:dup)
unless result
result = find_without_read_through_cache(*arguments)
Rails.cache.write(key, result)
end
result
private
def cache_key(*arguments)
"#{name}/#{arguments.join('/')}".downcase
end
@quamen
quamen / gist:888982
Created March 27, 2011 06:31
Module to demonstrate how we can hijack the ActiveResource find method
require 'active_support/concern'
module CachedResource
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :find, :read_through_cache
end
end
Eshell V5.7.4 (abort with ^G)
1> c(e26).
{ok,e26}
2> e26:ringBenchmark(1000, "Hello", 300).
Sent 300000 messages in time=280 (276) milliseconds
ok
3>