Skip to content

Instantly share code, notes, and snippets.

@joshsusser
joshsusser / Tenderlove Theme Song
Created March 25, 2011 16:14
Tenderlove Theme Song
( roughly to the tune of the Ultraman theme song:
http://www.televisiontunes.com/Ultraman.html )
Tenderlove, Tenderlove
Ruby programming guy
Tenderlove, Tenderlove
he's as awesome as _why
Seattle is his home
he's a Ruby brigadier
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
class Numeric
def to_rad
self * Math::PI / 180
end
end
# http://www.movable-type.co.uk/scripts/latlong.html
# loc1 and loc2 are arrays of [latitude, longitude]
def distance loc1, loc2
lat1, lon1 = loc1
@j05h
j05h / crypto.rb
Created November 4, 2010 18:11
Code to handle Facebook's signed_request on deauthorize.
module Crypto
class UnexpectedAlgorithmException < Exception
end
class << self
def hashtext thing, *extras
Digest::SHA1.hexdigest(([thing] + extras).join(" "))
end
# Always returns a different hex salt, using +extras+ for added
# this is a stupid simple random stringifier
"#{10.times.map{(rand(26) + 97).chr}.join}_#{Time.now.to_i.to_s}"
#=> "qnoqszbiam_1285701912"
@j05h
j05h / gist:469681
Created July 9, 2010 16:27
awk script to parse access logs
awk '{ sub(/([0-9]+\.?)+/, ":id", $3);
sub(/[0-9]+/, ":id", $3);
sub(/=.*&/, "=:param\\&", $3);
sub(/=.*$/, "=:param", $3);
sub(/\?[:a-z0-9]+$/, "", $3);
print $1, $2, $3, $4
}' | sort | uniq -c | sort
@j05h
j05h / test.rake
Created July 2, 2010 14:33
Test Dependency Task
namespace :test do
desc "Ensures there are no dependencies between test classes."
task :each => %w(each:functional each:unit each:integration)
namespace :each do
def each_test(tests)
# This is where the magic happens
ENV['TESTOPTS'] = '--verbose=progress' unless ENV['TESTOPTS']
tests.each do |path|
puts "\n#{path}"