Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# gemmate
# open the directory of a rubygem as a project in textmate
# responds to anything that `gem which` can handle
# e.g.:
# gemmate autotest
# => `mate /Library/Ruby/Gems/1.8/gems/ZenTest-3.11.0`
# gemmate active_record
# => `mate /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2`
#!/usr/bin/env ruby
# branchmate
# opens whichever files you've modified in this git branch compared to master
target = ARGV[0] || 'master'
p (cmd = "git diff #{target} --name-only")
files = `#{cmd}`.split.reject {|f| f =~ /^vendor/}
puts files.join("\n")
function git-revert-batch {
echo "$@" | xargs -n1 git revert --no-commit
}
alias grb='git-revert-batch'
# use like:
# grb ee5c95a 981da8b
# list commits in reverse order, and it's ready to make one neat+tidy revert-commit
# debug_in
# call debugger only when the stack trace includes a certain file and/or method
#
# use like:
# debug_in(:file => 'order_test', :method => 'test_taxes_included')
# debug_in(:r => /taxes.*included/)
#
# put in test_helper.rb
def debug_in(options = {})
debugger if caller.detect {|c| c =~ /#{(options[:file].to_s + ".rb") if options[:file]}.*#{("`" + options[:method].to_s + "'$") if options[:method]}/ && c =~ (options[:r] || //)}
include ActiveMerchant::Shipping
usps = USPS.new(:login => '123JAMES4567')
origin = Location.new(:country => 'US', :zip => '90210')
destination = Location.new(:country => 'CA', :postal_code => 'K2P 0K3')
grams = 100
centimetres = [20,10,10]
packages = [Package.new(grams, centimetres)]
<ul>
<r:feed:items
url="http://feeds.boingboing.net/boingboing/iBag"
order="creator ASC">
<li><r:feed:link /></li>
</r:feed:items>
<ul>
<r:feed:items
url="http://feeds.boingboing.net/boingboing/iBag"
order="creator ASC">
<r:feed:header for="creator">
<h2><r:feed:creator /></h2>
</r:feed:header>
function cd {
pushd "$@" > /dev/null
}
function bd {
if [ -z $1 ]; then
n=1
else
n=$1
fi
pushd +$n > /dev/null
}
function fd {
#!/usr/bin/env ruby
# mvln
#
# Usage:
#
# mvln original_location new_location [symlink_location]
#
# moves the file or directory at original_location to new_location,
# then makes a symlink to new_location at symlink_location.