Skip to content

Instantly share code, notes, and snippets.

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;
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))
@eric
eric / _using_it.rb
Created March 16, 2012 20:41
Use Arel in Rails 2.3
>> 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` "
>>
module Papertrail
module Zookeeper
class NodeWatcher
include Watchable
attr_reader :name
def initialize(zk, name, options = {})
@zk = zk
@name = name
class MultiTimer
def initialize(*timers)
@timers = []
add_timer(*timers)
end
def time(callable = nil, &block)
callable ||= block
context = Metriks::Timer::Context.new(self)
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
# 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
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
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
#
# 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,