Skip to content

Instantly share code, notes, and snippets.

# Extend jQuery objects with Underscore collection methods.
#
# Each collection method comes in two flavors: one prefixed
# with _, which yields a bare DOM element, and one prefixed
# with $, which yields a jQuery-wrapped element.
#
# So if `this` is a jQuery object, instead of:
#
# _.max @, (el) -> $(el).height()
#
@igrigorik
igrigorik / Gemfile
Created August 26, 2011 06:33
HTML5 SSE / EventSource demo with Goliath
source :gemcutter
gem 'goliath', :git => 'git://github.com/postrank-labs/goliath.git'
gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git'
require 'em-http'
EM.run do
def dispatch(uri, retries = 0)
h = EM::HttpRequest.new(uri).get
h.callback { |rep| [:success, rep.response]; EM.stop }
h.errback do |rep|
p [:fail, rep]
@rkh
rkh / sinatra_app_instance_in_spec.rb
Created October 27, 2011 05:45 — forked from duien/sinatra_app_instance_in_spec.rb
Get access to the Sinatra application instance that ran the current test in Rack::Test. Created by @bsiggelkow
describe LeadService do
LeadService.configure(:test) do
before { settings.set(:instance, self) }
end
# Required for Rack::Test
#
def app
LeadService
@eric
eric / lru_generational_hash.rb
Created November 15, 2011 00:18
Generational hash table — useful for in-memory caches
#
# by Eric Lindvall <eric@5stops.com>
#
class LruGenerationalHash
attr_reader :max_size
def initialize(max_size, generations = 2)
@generations = generations.times.collect { Hash.new }
@max_size = max_size
@netshade
netshade / gist:1566141
Created January 5, 2012 17:04
metrics from stdin to instrumental
#!/usr/bin/env ruby
# Provide data over STDIN to Instrumental
# Format of data:
# <metric name> <value> <unix timestamp>
# or
# <metric name> <value>
#
# Second form will assume that the time the
# metric is reported is when the event occurred.
#
@technoweenie
technoweenie / .gitignore
Created February 20, 2012 04:55
quick kestrel zeromq port attempt
node_modules
@technoweenie
technoweenie / heartbeat.rb
Created February 21, 2012 01:59
heartbeat actor w/ celluloid
require 'rbczmq'
require 'fileutils'
require 'celluloid'
class Heartbeat
include Celluloid
def self.start(id = nil, options = nil)
new(ZMQ::Context.new, id, options)
end
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
class KestrelMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
@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)