Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs
jasonroelofs / setup-statsd.sh
Created April 27, 2011 18:25 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.10 EC2 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
@pepijndevos
pepijndevos / lazy_sort.clj
Created May 2, 2011 12:49
Lazy sorting implementations in Clojure
(ns lazy-sort)
(defn qsort [[head & tail]]
(when head
(lazy-cat (qsort (filter #(< % head) tail))
[head]
(qsort (remove #(< % head) tail)))))
(defn merge*
[[f1 & r1 :as l1] [f2 & r2 :as l2]]
@dysinger
dysinger / bootstrap.sh
Created May 13, 2011 08:27
vagrant/ec2 boostrap script
#!/bin/bash -ex
if [ ! -f /usr/bin/chef-solo ]; then
apt-get update
apt-get -y upgrade
@tmcw
tmcw / disconnect.rb
Created July 22, 2011 04:06
bulk-export run data from Garmin Connect
#!/usr/bin/env ruby
## disconnect
# ./disconnect.rb -u yourusername
#
# This is a command-line utility for the bulk-downloading of run data from
# the connect.garmin.com web application, which has lackluster export
# capabilities.
#
@mjackson
mjackson / blocks.rb
Created August 11, 2011 18:30
Demonstrates the difference between Ruby's two different block styles.
def a(*args, &block)
puts "a got a block" if block_given?
end
def b(*args, &block)
puts "b got a block" if block_given?
end
# In this call, `b' is called with the block and the
# return value is given to `a' as an argument.
# https://gist.github.com/1185131
class Array
def next; self[1..-1] end
# returns a function that is the combination of a sequence of function calls
# on some external arguments. the functions combined are the elements of self.
def compose
lambda do |*args|
inject(*args) do |mem, fn|
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end
@raggi
raggi / fiber_race.rb
Created September 15, 2011 23:34
An example race condition using fibers
## SCROLL DOWN FOR THE RACE, THE FOLLOWING IS JUST UTILITY FROM COMMONLY USED CODE.
# Author:: Mohammad A. Ali (mailto:oldmoe@gmail.com)
# Copyright:: Copyright (c) 2008 eSpace, Inc.
# License:: Distributes under the same terms as Ruby
require 'fiber'
class Fiber
@nathanmarz
nathanmarz / gist:1228302
Created September 20, 2011 04:01
Example of defining a topology in Clojure
(use 'backtype.storm.clojure)
(use 'backtype.storm.config)
(require '[backtype.storm [thrift :as thrift]])
(import 'storm.starter.spout.RandomSentenceSpout)
(import 'backtype.storm.LocalCluster)
(defboltfull suffix-bolt ["word"]
:params [suffix]
:let [conf-state (atom nil)]
:prepare ([conf context collector]
@nathanmarz
nathanmarz / gist:1246228
Created September 27, 2011 20:56
Exception cause predicate
;; Determine if any of the causes of the exception was of the specified type
(defn exception-cause? [klass ^Throwable t]
(->> (iterate #(.getCause ^Throwable %) t)
(take-while identity)
(some (partial instance? klass))
boolean))