Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / exit-codes.sh
Created March 9, 2010 19:13
Ruby exit codes
$ ruby -e 'exit'
$ echo $?
0
$ ruby -e 'exit 1'
$ echo $?
1
$ ruby -e 'abort "oh no"'
oh no
$ echo $?
1
@defunkt
defunkt / gemspec
Created March 9, 2010 01:41
Quickly create a gemspec.
#!/usr/bin/env ruby
# Usage: gemspec [-s] GEMNAME
#
# Prints a basic gemspec for GEMNAME based on your git-config info.
# If -s is passed, saves it as a GEMNAME.gemspec in the current
# directory. Otherwise prints to standard output.
#
# Once you check this gemspec into your project, releasing a new gem
# is dead simple:
#
@defunkt
defunkt / gem-man.sh
Created March 7, 2010 02:07
Viewing a RubyGem's manpage
$ gem install gem-man
$ gem install mustache
$ gem man mustache
View which manual?
1. mustache(1)
2. mustache(5)
> 1
( shows manpage )
$ gem man 1 mustache
( shows mustache(1) )
@defunkt
defunkt / installing-Mustache.tmbundle.md
Created March 6, 2010 10:27
Installing Mustache.tmbundle
@defunkt
defunkt / installing-mustache.vim.md
Created March 6, 2010 10:21
Installing mustache.vim

mustache.vim

In your shell:

cd ~/.vim
git clone git://github.com/juvenn/mustache.vim.git
mv mustache.vim/syntax/* syntax/
mv mustache.vim/indent/* indent/
mv mustache.vim/ftdetect/* ftdetect/

rm -rf mustache.vim

@defunkt
defunkt / installing-mustache-mode.el.md
Created March 6, 2010 10:11
Installing mustache-mode.el

https://github.com/mustache/emacs

In your shell:

cd ~/.emacs.d/vendor
curl -O https://github.com/mustache/emacs/raw/master/mustache-mode.el

In your Emacs config:

(add-to-list 'load-path "~/.emacs.d/vendor/mustache-mode.el")

@defunkt
defunkt / alternately, named arguments in mustache.rb
Created March 6, 2010 06:12
named arguments in mustache.rb
require 'rubygems'
require 'mustache'
class HandleBar < Mustache
def respond_to?(methodname)
methodname = methodname.to_s.split(/\s+/).first
super methodname
end
def method_missing(methodname, *args)
@defunkt
defunkt / how to do arguments in mustache.rb
Created March 6, 2010 06:12
how to do arguments in mustache.rb
require 'rubygems'
require 'mustache'
class HandleBar < Mustache
def respond_to?(methodname)
methodname = methodname.to_s.split(':').first
super methodname
end
def method_missing(methodname, *args)
@defunkt
defunkt / checkout.md
Created March 3, 2010 21:34
Tracking branch shortcut

Old way:

$ git checkout -b preandpost_fork_hooks  scotttam/preandpost_fork_hooks
Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.
Switched to a new branch 'preandpost_fork_hooks'

New way:

$ git checkout preandpost_fork_hooks

Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.

@defunkt
defunkt / vipy.sh
Created March 3, 2010 04:11 — forked from mmalone/vipy.sh
Simple shell script that locates a Python module and opens it in vi.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: vipy <python module>"
exit 1
fi
MODULE_LOCATION=`python -c "import $1; print $1.__file__.rstrip('c')"`
if [ -z $MODULE_LOCATION ]; then