Skip to content

Instantly share code, notes, and snippets.

@jdmaturen
jdmaturen / bucket_client.py
Created April 16, 2011 08:31
riak bucket that manages retries + conflict resolution w/ example increment counter implementation
from riak import RiakError
class Bucket(object):
"""Wrap up retries and conflict resolution"""
def __init__(self, client, name, resolve, retries=5):
self.client = client
self.name = name
self.bucket = client.bucket(name) # base bucket
self.resolve = resolve
self.retries = retries
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
@jbarnette
jbarnette / example.rb
Created April 6, 2011 14:55
A naïve state machine for ActiveRecord. Ruby 1.9.
require "stateful"
class Folder < ActiveRecord::Base
include Stateful
# ...
stateful do
state :active
state :inactive
describe "GET current" do
before do
@request.cookies['hidden_notices'] = "1,#{notices(:permanent).id}"
get :current, :format => 'js'
end
it { should respond_with(:success) }
it { should set_cookie(:hidden_notices).to("#{notices(:permanent).id}") }
it { should render_template('notices/current') }
end
@eric
eric / DISCLAIMER.md
Created March 28, 2011 22:59
Log directly to Papertrail or any remote syslog target from Heroku
@ericmoritz
ericmoritz / counter.py
Created March 22, 2011 21:04
A counter stored in Riak that handles conflict resolutions on read
import logging
import riak
log = logging.getLogger(__name__)
class RiakCounter(object):
def __init__(self, bucket, key):
self.bucket = bucket
self.bucket.set_allow_multiples(True)
self.key = key
module CpuProf
require 'ffi'
extend FFI::Library
ffi_lib FFI::CURRENT_PROCESS
begin
attach_function :start, :ProfilerStart, [:string], :void
attach_function :stop, :ProfilerStop, [], :void
rescue FFI::NotFoundError => e
STDERR.puts "*** Are you sure you preloaded libprofiler?"
@collegeman
collegeman / setup-statsd.sh
Created March 9, 2011 16:12
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
{% line_chart value:calls_per_minute regexp:'Database/Redis/[b-z].*' title:'CPM' %}
{% line_chart value:average_value regexp:'Database/Redis/[b-z].*' title:'Average Time' %}
{% line_chart value:max_value regexp:'Database/Redis/[b-z].*' title:'Max Time' %}
{% line_chart value:calls_per_minute regexp:'Database/Redis/allWeb' title:'Redis Web CPM' %}
{% line_chart value:calls_per_minute regexp:'Database/Redis/allOther' title:'Redis Background CPM' %}
@protocool
protocool / caveatPatchor.js
Created February 14, 2011 02:29
Sample caveatPatchor.js file for use in Propane 1.1.2 and above
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.