This file contains 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
function barChart() { | |
var margin = {top: 0, right: 10, bottom: 20, left: 40}, | |
width = 960, | |
height = 500, | |
spacing = .1; | |
var key = defaultKey, | |
value = defaultValue, | |
valueFormat = d3.format(",.f"), | |
valueDomain = null; |
This file contains 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
process = (data) -> | |
keyMaker = (d) -> | |
time = d.time | |
if time not instanceof Date | |
time = new Date(time * 1000) | |
+d3.time.day.floor(time) / 1000 | |
nestedData = d3.nest() | |
.key(keyMaker) | |
.rollup((v) -> d3.sum(v, (d) -> d.value)) |
This file contains 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
>> engine = ArelBack::Engine.new(ar.connection, Arel::Visitors::MySQL) | |
>> table = Arel::Table.new(ar.table_name, engine) | |
>> table.project(Arel.sql('*')).to_sql | |
=> "SELECT * FROM `awesome_table` " | |
>> |
This file contains 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
module Papertrail | |
module Zookeeper | |
class NodeWatcher | |
include Watchable | |
attr_reader :name | |
def initialize(zk, name, options = {}) | |
@zk = zk | |
@name = name |
This file contains 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 MultiTimer | |
def initialize(*timers) | |
@timers = [] | |
add_timer(*timers) | |
end | |
def time(callable = nil, &block) | |
callable ||= block | |
context = Metriks::Timer::Context.new(self) |
This file contains 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 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 |
This file contains 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
# 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 |
This file contains 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
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 |
This file contains 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 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 |
This file contains 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
# | |
# 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, |