Skip to content

Instantly share code, notes, and snippets.

@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}"
@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
class A
class B
def self.const_get(n)
self.const_set(n,Class.new(self){
self.const_set("D",Class.new(self))
})
end
end
end
puts A::B::C::D rescue puts $!
# 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 / 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
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

nwcopy/nwpaste

The fool proof network copy & paste program. Well, maybe someday.

Usage

> nwcopy
/Users/josh/Dropbox/nwcopy/f314eee55161b14f140ee07b358ba63ef54112ac
> nwpaste
https://github.com/j05h/nwcopy
@j05h
j05h / verify_gems.rb
Created April 20, 2011 19:13
Checks your Gemfile for public gems on rubygems.org
#!/usr/bin/env ruby
# This class will check search rubygems.org for all gems in a given Gemfile.
# If a given gem is not available on rubygems.org, it will tell you such.
class VerifyGems
def initialize _file, _source
@file = _file || 'Gemfile'
@source = _source || 'http://rubygems.org'
@gems = []
@verbose = false
@j05h
j05h / earthporn.rb
Created October 26, 2011 16:14
Download the imgur.com images from reddpics.com; Great for wallpapers/screensavers
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
def download path, site
url = "http://reddpics.com/moreimages/#{site}/#{path}"
agent = Mechanize.new
page = agent.get url
page.links_with(:href => /i.imgur.com/).map(&:href).uniq.each do |img|
@j05h
j05h / unicorn
Created March 10, 2012 21:23
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##