This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A migration that will continue to work after refactoring | |
class FutureProofMigration < ActiveRecord::Migration | |
# Redefine models used in the migration as empty inner classes. This removes all validations and magic. | |
class Model < ActiveRecord::Base; end | |
# Either don't rely on associations or declare them as referring to the new inner class | |
class DependentModel < ActiveRecord::Base | |
belongs_to :model, :class_name => "FutureProofMigration::Model" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveSupport::Cache::FileStore.class_eval do | |
def read(name, options = nil) | |
super | |
File.open(real_file_path(name), 'rb') do |f| | |
gz = Zlib::GzipReader.new(f) | |
value = Marshal.load(gz) | |
gz.close | |
value | |
end | |
rescue => e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MemCacheWrapper | |
def initialize(repository) | |
@repository = repository | |
end | |
def self.handle_errors_for(*args) | |
options = args.extract_options! | |
args.each do |method| | |
define_method method do |*x| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include Cash::Extensions after you declare is_cached for a class | |
module Cash | |
module Extensions | |
def self.included(base) | |
base.send(:extend, ClassMethods) | |
base.send(:include, InstanceMethods) | |
end | |
module ClassMethods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterate a list | |
a = [5,6,7,8] | |
a.each_with_index{ |x, i| puts "#{i} => #{x}" } | |
# Conditionally end a loop | |
stop = false | |
while(!stop) do | |
value = rand(5) | |
puts "Picked #{value}" | |
stop = true if 0 == value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec/spec_helper' | |
require 'logger' | |
require 'benchmark' | |
workers = 20 | |
puts "#{workers} workers" | |
#Delayed::Job.logger = Logger.new('/tmp/delayed_job.log') | |
pids = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo; 10000.times{x = Struct.new(:field).new("1")}; end | |
GC.enable_stats | |
GC.start | |
ObjectSpace.live_objects | |
=> 174939 | |
foo | |
GC.start | |
ObjectSpace.live_objects | |
=> 174947 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env ruby | |
base_dir = File.expand_path("../..", __FILE__) | |
NAME="faye" | |
PID="#{base_dir}/tmp/pids/#{NAME}.pid" | |
COMMAND="bundle exec rackup -s thin -E production -p 3001 faye.ru" | |
case ARGV[0] | |
when "start" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Handle mail delivery in the background. Only the minimum amount of data should go in the job not | |
# the fully rendered email content. | |
# I haven't tested this but some variant should work. | |
ActionMailer::Base.class_eval do | |
def self.create_and_deliver!(message, *parameters) | |
new(message, *parameters).deliver! | |
end | |
def method_missing_with_delay(method_symbol, *parameters)#:nodoc: | |
case method_symbol.id2name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queue: ./queue.sh |
OlderNewer