Skip to content

Instantly share code, notes, and snippets.

module Papertrail
module Zookeeper
class NodeWatcher
include Watchable
attr_reader :name
def initialize(zk, name, options = {})
@zk = zk
@name = name
@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` "
>>
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))
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;
@eric
eric / bundle-outdated-github.rb
Created March 8, 2012 06:11
Annotate your "bundle outdated" with GitHub compare URLs
#!/usr/bin/env ruby
#
# Annotate your "bundle outdated" with GitHub compare URLs
#
require 'open-uri'
require 'json'
def rubygems_gem_info(gem_name)
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
class KestrelMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
require 'lazy'
require 'system_timer'
class LibratoMetric
COUNT = 10
RESOLUTION = 1
def initialize(metric_name, timeout = 5)
@metric_name = metric_name
@timeout = timeout
require 'lazy'
require 'system_timer'
class LibratoMetric
COUNT = 10
RESOLUTION = 1
def initialize(metric_name, timeout = 5)
@metric_name = metric_name
@timeout = timeout
class KestrelQueueMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
label: Port
notes: Kestrel admin HTTP port
default: 2223
require 'lazy'
require 'system_timer'
class ScoutMetric
M60_ALPHA = (1 - Math.exp(-5.minutes / 1.hour.to_f))
NS_IN_SECONDS = 1000000000
def initialize(metric_id, timeout = 5)
@metric_id = metric_id
@timeout = timeout