Skip to content

Instantly share code, notes, and snippets.

@eric
eric / _deploy.rb
Created May 29, 2012 06:00
Capistrano notification for Boundary
# load plugin
load 'boundary'
# Notify boundary with your orgid, apikey
boundary.register 'cdd7261592bca18539eae9bb5f1bcfdd', 'f9e6282c4727c5733585a4be86e0f990'
@eric
eric / crash_a_187.rb
Created May 15, 2012 06:31
segfault in MRI 1.8.7 that I tracked down with @slyphon
require 'thread'
# This seems to crash 1.8.7
10.times { Thread.new { Queue.new.pop } }
Process.waitpid fork { GC.start; puts "In child: #{$$}" }
module Papertrail
module Zookeeper
module Convenience
def assign(key, value, options = {})
set(key, value, options)
rescue ZK::Exceptions::NoNode
begin
create(key, value, options)
rescue ZK::Exceptions::NodeExists
set(key, value, options)
perform_action -> #<(NewRelic::Agent::Instrumentation::ControllerInstrumentation)#perform_action>
perform_action_without_benchmark -> #<(ActionController::Filters::InstanceMethods)#perform_action_without_benchmark>
perform_action_without_filters -> #<ActionController::Base#perform_action_without_filters>
perform_action_without_flash -> #<(ActionController::Rescue)#perform_action_without_flash>
perform_action_without_newrelic_trace -> #<(ActionController::Flash::InstanceMethods)#perform_action_without_newrelic_trace>
perform_action_without_rescue -> #<(ActionController::Benchmarking)#perform_action_without_rescue>
#
# 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,
class Module
# Use this to replace a method in an alias_method_chain
def inject_alias_method_chain(target, method_to_replace, method_to_use)
method_instance_to_replace = instance_method(method_to_replace)
meths = (private_instance_methods | instance_methods).sort.grep(/^#{target}/)
found = meths.detect do |m|
m != method_to_replace.to_s && instance_method(m) == method_instance_to_replace
end
if found
alias_method found, method_to_use
module Resque
module Plugins
# If you want only one instance of your job queued at a time,
# extend it with this module.
#
# For example:
#
# require 'resque/plugins/zookeeper_lock'
#
# class UpdateNetworkGraph
# Wrap tasks in exception notification
def task(*args, &block)
if block
wrapper = proc do |*a|
begin
block.call(*a)
rescue Interrupt, SignalException, SystemExit
raise
rescue Exception => e
Papertrail::ExceptionNotifier.notify(e) rescue nil
class ActionController::TestCase
def assert_select_with_silence_warnings(*args)
silence_warnings do
assert_select_without_silence_warnings(*args)
end
end
alias_method_chain :assert_select, :silence_warnings
end
class MultiTimer
def initialize(*timers)
@timers = []
add_timer(*timers)
end
def time(callable = nil, &block)
callable ||= block
context = Metriks::Timer::Context.new(self)