Skip to content

Instantly share code, notes, and snippets.

View trshafer's full-sized avatar

Thomas Shafer trshafer

View GitHub Profile
@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
@trshafer
trshafer / mapsHelpers.html
Created February 12, 2011 02:53
gets a codified location from any search or current locationand calls a callback with that result
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
<script type="text/javascript" src="http://cdn.simplegeo.com/js/1.2/simplegeo.all.jq.min.js"></script>
<script type="text/javascript" charset="utf-8">
;var Maps = function(){
@trshafer
trshafer / facebook-stub.html
Created February 15, 2011 04:50
A js stub for the facebook javascript sdk
<html>
<head>
<script type="text/javascript" charset="utf-8">
var FB = function(){
//defaults and accessors
var initialized = false,
loggedIn = null,
shouldSucceed = true,
uid = '12345';
@trshafer
trshafer / rkill.sh
Created February 18, 2011 05:02
kills any process matching the first argument
#!
ps -e -f | grep `ruby -e 'puts "[#{ARGV[0][0,1]}]#{ARGV[0][1..-1]}"' $*` | awk '{print $2}' | xargs kill -9