Skip to content

Instantly share code, notes, and snippets.

@kowsik
kowsik / gh-campfire.rb
Created March 22, 2012 19:42
Quick script to go through a bunch of GitHub repos and add campfire notification to them. Turns out campfire notifications created in the past only have the 'push' event in them.
require 'rubygems'
require 'json/ext'
require 'restclient'
require 'pp'
# You'll need to define the following variables and of course change
# 'mudynamics' to your organization name
# user, password (for GitHub credentials)
# room, subdomain, token (your Campfire settings)
@kowsik
kowsik / gist:1628665
Created January 17, 2012 20:21
Monkey patch CouchRest for supporting redis caching
class CouchRest::Database
alias :old_save_doc :save_doc
alias :old_delete_doc :delete_doc
attr_writer :rcache
# Automatically add the created_at and updated_at time fields to the
# document and also save it back to redis with a ttl.
def save_doc doc, bulk = false, batch = false
doc['created_at'] ||= Time.now
doc['updated_at'] = Time.now
@kowsik
kowsik / gist:1628449
Created January 17, 2012 19:49
Using Redis Transactions with CouchDB
def incr_site_stats engine, stats
# Increment the site:stats counters (in redis). We use 'created_at'
# to checkpoint the time we created these stats
redis.multi do
redis.hsetnx 'site:stats', 'created_at', Time.now.utc.to_string
stats.each_pair do |k, v|
redis.hincrby 'site:stats', k, v.to_i
end
end
@kowsik
kowsik / couchdb.conf
Created September 2, 2011 00:10
Upstart script for CouchDB
start on runlevel [2345]
exec su -s /bin/sh -c 'exec "$0" "$@"' couchdb -- /mnt/couch/bin/couchdb
respawn
respawn limit 10 5
@kowsik
kowsik / couchdb-ec2-install.sh
Created August 26, 2011 14:09 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@kowsik
kowsik / nko-blitz.md
Created August 22, 2011 17:29
Node Knockout with http://blitz.io

Node Knockout with blitz.io

blitz.io

What's blitz.io?

blitz.io, powered by Mu Dynamics, is a self-service load and performance testing platform. Built for API, cloud, web and mobile application developers, blitz.io quickly and inexpensively helps you ensure performance and scalabilty. And we make this super fun.

Why Load Test?

@kowsik
kowsik / blitz.scale.tropo.rb
Created April 22, 2011 17:35
Using blitz.io and Tropo for scheduled load tests and alerting
# Try running a Rush (load test) from california
opts = {
:region => 'california',
:url => 'http://www.mudynamics.com',
:pattern => [{ :start => 1, :end => 10000, :duration => 120 }]
}
result = Blitz::Curl::Rush.execute(opts)
last = result.timeline.last
if last.errors or last.timeouts
# Do something about this!
@kowsik
kowsik / blitz.tropo.rb
Created April 22, 2011 17:23
Using blitz.io and Tropo for easy Application Monitoring
require 'rubygems'
require 'restclient'
require 'blitz'
require 'pp'
TROPO_USER = ENV['TROPO_USER']
TROPO_PASS = ENV['TROPO_PASS']
TROPO_APIK = ENV['TROPO_APIK']
TROPO_CALL = ENV['TROPO_CALL']
@kowsik
kowsik / blitz.rb
Created April 20, 2011 23:14
Integrate Blitz into your test frameworks
require 'rubygems'
require 'blitz'
require 'pp'
# Run a sprint
require 'blitz'
sprint = Blitz::Curl.parse('-r california www.example.com')
result = sprint.execute
pp :duration => result.duration
@kowsik
kowsik / gist:792862
Created January 24, 2011 05:03
pong
loop do
76.times do |i|
print " " * i
print "o"
print "\r"
$stdout.flush
sleep 0.05
end
76.times do |i|