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 <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
@cpatni
cpatni / app.rb
Created November 21, 2011 22:39
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@xaviershay
xaviershay / http_client_spec.rb
Created December 13, 2011 02:19
Running a rack app in a thread for integration tests.
require 'integration_helper'
require 'rack'
require 'rack/handler/webrick'
describe HttpClient do
before :all do
@server = WEBrick::HTTPServer.new(
:Port => 9293,
:Logger => Rails.logger,
:AccessLog => Rails.logger
@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.
#
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@ryandotsmith
ryandotsmith / worker-pattern.md
Created January 23, 2012 05:03
The Worker Pattern

The Worker Pattern

Contents

  • Introduction
  • Definition
  • Examples
  • Links

Introduction

@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@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