Skip to content

Instantly share code, notes, and snippets.

View austintaylor's full-sized avatar

Austin Taylor austintaylor

View GitHub Profile
@austintaylor
austintaylor / gist:465756
Created July 6, 2010 18:39
One-liner to rollback schema changes in a branch
for VERSION in `git diff --summary master..HEAD -- db/migrate/ | sed -e "s/.*migrate\///" -e "s/_.*//" | sort -r` ; do export VERSION && rake db:migrate:down; done
@austintaylor
austintaylor / 1_to_english.rb
Last active September 5, 2015 01:44
Ruby vs. Haskell – to_english
# This is the version I wrote in Ruby. I considered it to be pretty tight code at the time.
# It only handles integers from 0 to 999. When I wrote this, I understood that it ought to
# be more generalized, but I couldn't figure out how to do it in Ruby.
class Integer
ONES = %w(zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen)
TENS = %w(twenty thirty fourty fifty sixty seventy eighty ninety)
def to_english
if self < 20
@austintaylor
austintaylor / gist:405513
Created May 18, 2010 20:46
Text object for indented code
" Text object for indented code
onoremap <silent>ai :<C-u>cal IndTxtObj(0)<CR>
onoremap <silent>ii :<C-u>cal IndTxtObj(1)<CR>
vnoremap <silent>ai :<C-u>cal IndTxtObj(0)<CR><Esc>gv
vnoremap <silent>ii :<C-u>cal IndTxtObj(1)<CR><Esc>gv
function! IndTxtObj(inner)
if &filetype == 'haml' || &filetype == 'sass' || &filetype == 'python'
let meaningful_indentation = 1
else
#!/bin/bash
# Print out what changed in a nice format.
git log @{1}.. --pretty=format:"%Cblue%an%Creset %ar: %Cred\"%s%b\"%Creset (%h)" --reverse --no-merges
# Print out any new migrations
diff <(ls -l db/migrate/ | grep "[0-9]\{14\}" | sed -e 's/.*\([0-9]\{14\}\).*/\1/g' | sort) <((test -f db/development.sqlite3 && sqlite3 db/development.sqlite3 "select version from schema_migrations" || mysql -uroot `pwd | xargs basename`_development -e "select version from schema_migrations") | grep [0-9] | sort) | grep "< [0-9]\{14\}" | cut -d' ' -f2 | tr '\n' '|' | sed -e 's/\(.*\)|$/"\\\(\1\\\)"/' -e 's/|/\\\|/g' | xargs -J % grep % <(ls -l db/migrate | tail -100) | sed -e 's/.*\([0-9]\{14\}_.*\.rb\)/Pending migration: \1/g'
# Yes, I know about rake db:about_if_pending_migrations, but it's way too slow.
# On the other hand, this makes all kinds of assumptions about your database configuration.
def process(chicken)
case chicken
when Hen
chicken.collect(&:eggs)
when Rooster
chicken.chop
end
end