Skip to content

Instantly share code, notes, and snippets.

View trshafer's full-sized avatar

Thomas Shafer trshafer

View GitHub Profile
require File.dirname(__FILE__) + '/../config/database'
register DatabaseSetup
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate(File.dirname(__FILE__)+"/../db/migrate")
# you can make as many tabs as you wish...
# tab names are actually arbitrary at this point too.
---
- tab1: cd ~/foo/bar
- tab2:
- mysql -u root
- use test;
- show tables;
- tab3: echo "hello world"
- tab4: cd ~/baz/ && svn up
@trshafer
trshafer / Infinitely Nested Hashes
Created May 13, 2010 23:49
infinitely nested hashes
default = lambda { |h,k| h[k] = Hash.new(&default) }
top = Hash.new(&default)
@trshafer
trshafer / gist:402088
Created May 15, 2010 07:52
Kings Cup in Ruby
require 'rubygems'
require 'active_support'
while (deck ||= %w(Diamond Heart Spade Club).collect{ |suit| {'Ace' => 'Waterfall', 2 => 'You', 3 => 'Me', 4 => 'Women of Society', 5 => 'Category', 6 => 'Gentlemen', 7 => 'Heaven', 8 => 'Mate', 9 => 'Rhyme', 'Jack' => 'Thumb Master', 'Queen' => 'Questions', 'King' => 'Pour'}.collect{|card, rule| "#{(card)} of #{suit}s: #{rule}"} }.flatten.shuffle).select {|card| card =~ /king/i}.present? do puts deck.pop end
@trshafer
trshafer / git svn create branch
Created August 2, 2010 18:21
git svn branch
git svn branch remote_name
git checkout -b local_name -t remote_name
@trshafer
trshafer / gist:519251
Created August 11, 2010 16:24
git ps1
# GIT PS1
# COLORS
LIGHT_GRAY="\[\033[0;37m\]"; BLUE="\[\033[0;34m\]"; RED="\[\033[0;31m\]"; LIGHT_RED="\[\033[1;31m\]";
GREEN="\[\033[0;32m\]"; WHITE="\[\033[1;37m\]"; LIGHT_GRAY="\[\033[0;37m\]"; YELLOW="\[\033[1;33m\]";
BROWN="\[\033[0;33m\]"; BLACK="\[\033[0;30m\]";PURPLE="\[\033[0;35m\]";CYAN="\[\033[0;36m\]";
# GIT PROMPT (http://gist.github.com/120804)
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/';
}
function parse_git_status {
@trshafer
trshafer / Database Branches
Created September 9, 2010 18:10
Database Branches
## database.yml (after)
<%
# http://mislav.uniqpath.com/rails/branching-the-database-along-with-your-code/
branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : ""
%>
development:
# ... adapter/auth config ...
database: myapp<%= suffix %>
@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'