Skip to content

Instantly share code, notes, and snippets.

def forked!
ActiveRecord::Base.connection.reconnect!
Rails.cache.instance_variable_get(:@data).reset
Mongoid.config.master.connection.close
load File.join(RAILS_ROOT, 'config/initializers/mongoid.rb')
end
def run(job)
runtime = Benchmark.realtime do
fork do
@saetia
saetia / gist:1623487
Last active April 20, 2025 23:05
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@cypriss
cypriss / README.md
Last active June 18, 2018 11:57
Rails 2.3.14 Ruby 1.9.3 - Monkey Patches

How we upgraded UserVoice, a Rails 2.3.14 app, to Ruby 1.9.3.

Blog post here

#
# Ideas stolen from lograge and brought to Rails 2.3
# https://github.com/mattmatt/lograge/blob/master/lib/lograge/log_subscriber.rb
#
module ImprovedControllerLogging
def self.included(base)
base.alias_method_chain :log_processing, :fixup
base.inject_alias_method_chain :perform_action,
:perform_action_with_benchmark,
@cypriss
cypriss / action_mailer_no_tmail.rb
Created August 14, 2012 17:32
Use TMail -> Mail gem in Rails 2.3
require 'action_mailer'
require 'mail'
module ActionMailer
class Base
def clean_address(str)
EmailAddress.parse(str, :no_default_name => true).quoted rescue str
end
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@funny-falcon
funny-falcon / changes.md
Last active August 15, 2024 15:13
Performace patch for ruby-1.9.3-p327

Changes:

  • this version includes backport of Greg Price's patch for speedup startup http://bugs.ruby-lang.org/issues/7158 .

    ruby-core prefers his way to do thing, so that I abandon cached-lp and sorted-lf patches of mine.

  • this version integrates 'array as queue' patch, which improves performance when push/shift pattern is heavily used on Array.

    This patch is accepted into trunk for Ruby 2.0 and last possible bug is found by Yui Naruse. It is used in production* for a couple of months without issues even with this bug.

@daveyeu
daveyeu / gist:4960893
Created February 15, 2013 15:04
Displays accurate request queue times for New Relic on Heroku Cedar
# Accurate queue times for Heroku Cedar + Rails (or Rack)
#
# For Rails:
#
# Rails::Application.middleware.insert(0, QueueTimeLogger)
#
class QueueTimeLogger
attr_reader :app
def initialize(app, options = {})
@tmm1
tmm1 / rails3_mailer.rb
Created March 27, 2013 23:25
rails3 mailer backport
if Rails.version < '3.0'
require 'mail'
require 'active_support/core_ext/module/attr_internal'
class ActionMailer3
class Collector
attr_reader :responses
def initialize(context, &block)
@context = context
@ryandotsmith
ryandotsmith / log.rb
Last active December 15, 2015 23:49
A simple ruby logger that emits l2met conventional data
def log(data)
result = nil
if data.key?(:measure)
name = data.delete(:measure).insert(0, ENV["APP_NAME"] + ".")
end
if block_given?
start = Time.now
result = yield
elapsed = (Time.now.to_f - start.to_f) * 1000
data.merge!("measure.#{name}" => elapsed.round)