Skip to content

Instantly share code, notes, and snippets.

@eric
eric / lru_generational_hash.rb
Created November 15, 2011 00:18
Generational hash table — useful for in-memory caches
#
# by Eric Lindvall <[email protected]>
#
class LruGenerationalHash
attr_reader :max_size
def initialize(max_size, generations = 2)
@generations = generations.times.collect { Hash.new }
@max_size = max_size
class KestrelQueueMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
label: Port
notes: Kestrel admin HTTP port
default: 2223
module ObjectDiagnostics
extend self
def display(method, options = {})
res = format(method, options)
res.each { |l| puts l }
end
def format(method, options = {})
#!/usr/bin/env ruby
require 'atomic'
atomic1 = Atomic.new([ -1, 0 ])
atomic2 = Atomic.new(0)
array = []
1000.times do |idx|
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
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 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
#
# Created by Eric Lindvall <[email protected]>
#
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)