Skip to content

Instantly share code, notes, and snippets.

View trshafer's full-sized avatar

Thomas Shafer trshafer

View GitHub Profile
@trshafer
trshafer / .gitignore
Created September 20, 2010 18:28
.gitignore
.DS_Store
*.swp
.sass-cache
.irb-save-history
.capfile
.bundle
.bundle/*
config/deploy.rb
config/database.yml
@trshafer
trshafer / ensure_insanity.rb
Created October 7, 2010 17:46
Differences with ensure and return
# Returns the expected method return
def return_out_of_ensure
return 'actual return'
ensure
'not returned'
end
# Returns from ensure despite a method return
def return_within_ensure
return 'not returned'
@trshafer
trshafer / .irbrc
Created October 12, 2010 17:23
a good looking irbrc
# load libraries
require 'rubygems'
require 'wirble'
# so I can use awesome print (syntax: ap object) for sane object printing:
require 'ap'
require 'irb/completion'
require 'map_by_method'
require 'what_methods'
@trshafer
trshafer / nginx
Created October 21, 2010 18:29
/etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
alias gi="echo is \'gitx\' really that hard to type?; gitx; osascript -e 'tell application \"System Events\" to keystroke \"2\" using command down'"
@trshafer
trshafer / pre-commit
Created January 11, 2011 23:00
precommit hook for checking reminders.txt content
#!/usr/bin/env ruby
reminder_location = 'ignored/reminders.txt'
file_location = File.join( File.dirname(__FILE__), '..', '..', reminder_location)
more_work_needed = IO.readlines(file_location).join('').strip != ''
exit 1 if more_work_needed
@trshafer
trshafer / params-to-url.js
Created January 28, 2011 07:41
Appends parameters to url
function appendParamsToUrl(url, params){
if(url.match(/\?/)){
//it just has a question mark at the end
if(url.indexOf('?') == url.length-1){
return url + jQuery.param(params);
}else{
//it already has query params
return url + '&' + jQuery.param(params);
}
}else{
http://paulbarry.com/articles/2009/08/30/active-record-random
class ActiveRecord::Base
def self.random
if (c = count) > 0
first(:offset => rand(c))
end
end
end
@trshafer
trshafer / unmerged.sh
Created January 29, 2011 22:11
Open all conflicted files in textmate
# http://optimisdev.com/posts/open-all-conflicted-files-in-textmate
git ls-files --unmerged | awk '{print $4}' | sort -u | xargs mate
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon