Skip to content

Instantly share code, notes, and snippets.

@chrismdp
chrismdp / hamlserve.rb
Created September 16, 2009 15:01
Put this one level above a 'views' directory and run it. haml/sass parsing for quickfire templating... you'll need the haml, sass and sinatra gems.
require 'rubygems'
require 'sinatra'
require 'haml'
require 'sass'
get '/stylesheet.css' do
content_type 'text/css', :charset => 'utf-8'
sass :stylesheet
end
@chrismdp
chrismdp / cycle-metrics.html
Created March 1, 2010 21:51
to use, replace line 47 with your project list, and line 51 with your metrics host...
<html>
<head>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='jquery.cycle.lite.1.0.min.js'></script>
<style>
body { margin: 0 }
li { width: 100% }
h1 {
position: absolute;
font-family: arial;
def authors_from_commit(commit)
authors = []
commit.chomp.split(' and ').map{|a| authors.push a}
authors
end
def authors_from_commits(commits)
authors = []
commits.each do |commit|
authors += authors_from_commit(commit)
@chrismdp
chrismdp / bootstrap_chef.bash
Created June 15, 2011 07:12 — forked from michaelvobrien/bootstrap_chef.bash
Bootstrap Chef Solo on Ubuntu
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='git@example.com:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 )
# You will need to ensure that the ssh key is already set up on the server.
set -e
export CHEF_DIR="${HOME}/chef"
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
@chrismdp
chrismdp / committer_stats.rb
Created June 26, 2011 21:49
Committer stats
committers = `git log --pretty=format:%an`
authors = []
committers.each_line do |commit|
commit.chomp.split(' and ').map{|a| authors.push a}
end
stats = Hash.new(0)
authors.map do |author|
stats[author] += 1
end
Feature: Paul pays employees
In order to retain staff
As Paul the Payroll Manager I want to pay my staff
Scenario:
Given an admin user called "Paul" with a password "password"
And a user called "Bob"
And "Bob" is an employee
And "Bob" gets paid "$2,000" a month
When I visit the homepage
Given /^an employee called "([^"]+)"$/ do |employee_name|
create_employee(employee_name)
end
Then /^I should be able to pay "([^"]+)" his salary$/ do |employee_name|
pay_salary_to(employee_)
end
Given /^an employee called "([^"]+)"$/ do |employee_name|
create_employee(employee_name)
end
Then /^I should be able to pay "([^"]+)" his salary$/ do |employee_name|
pay_salary_to(employee_)
end
@chrismdp
chrismdp / gist:2768532
Created May 22, 2012 11:40
Paypal IPN integration in about 30 lines of Sinatra.
diff --git a/app/account.rb b/app/account.rb
index a108685..c89ad34 100644
--- a/app/account.rb
+++ b/app/account.rb
@@ -1,4 +1,22 @@
+require 'open-uri'
+
module Sol
+ class Url
+ def self.get(url)
@chrismdp
chrismdp / run-changed-tests.sh
Created November 29, 2012 12:00
Handy little command to run all the tests that I've changed since the last commit
git status --porcelain | grep 'test' | grep -v 'factories' | cut -c4- | sort | uniq | xargs zeus test