Skip to content

Instantly share code, notes, and snippets.

View trshafer's full-sized avatar

Thomas Shafer trshafer

View GitHub Profile
@trshafer
trshafer / gist:1081064
Created July 13, 2011 19:08
Module extension within module, post class inclusion
module FourToedFrontFeet
def number_of_toes
4
end
end
module Quadruped
include FourToedFrontFeet
def number_of_legs
4
@trshafer
trshafer / gist:1045464
Created June 24, 2011 19:17
Textmate defaults untitled files to ruby
defaults write com.macromates.textmate OakDefaultLanguage E00B62AC-6B1C-11D9-9B1F-000D93589AF6
@trshafer
trshafer / ternary_precedence.rb
Created June 3, 2011 18:57
Ternary Operation Precedence Gotcha
a = []
a << false ? "bad" : "awesome"
puts a.inspect # => [false]
a = []
a << (false ? "bad" : "awesome")
puts a.inspect # => ["awesome"]
@trshafer
trshafer / dude.rb
Created June 3, 2011 02:24
class_accesssor
class Dude < Person
awesomeness "SUPER AWESOME"
intellect 80
end
# Dude.awesomeness #=> "SUPER AWESOME"
# Dude.new.intellect #=> 80
@trshafer
trshafer / gist:943312
Created April 26, 2011 22:12
Spermy Gem::Version definition
Specification From ... To (exclusive)
">= 3.0" 3.0 ... &infin;
"~> 3.0" 3.0 ... 4.0
"~> 3.0.0" 3.0.0 ... 3.1
"~> 3.5" 3.5 ... 4.0
"~> 3.5.0" 3.5.0 ... 3.6
taken from: http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html
@trshafer
trshafer / kill_teleport.rb
Created April 13, 2011 23:54
kills teleport and runs the same command again. essentially it kicks people from you
Put this in an automator service as described by
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
@trshafer
trshafer / formtastic validations
Created March 3, 2011 21:51
initializers/formtastic.rb
require 'formtastic/validations'
module Formtastic
class SemanticFormBuilder < ActionView::Helpers::FormBuilder
@@validate_by_default = false
cattr_accessor :validate_by_default
end
end
Formtastic::SemanticFormBuilder.validate_by_default = true
@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
@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 / 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(){