This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process(chicken) | |
case chicken | |
when Hen | |
chicken.collect(&:eggs) | |
when Rooster | |
chicken.chop | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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\)/[34mPending migration: [31;1m\1[0m/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Precedence = Int | |
data Associativity = AssocL | AssocR | |
data Token = Operand Int | Operator String (Int -> Int -> Int) Associativity Precedence | ParenL | ParenR | |
instance Show Token where | |
show (Operator s _ _ _) = s | |
show (Operand x) = show x | |
show ParenL = "(" | |
show ParenR = ")" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var eventColors = { | |
mouseover: 'red', | |
mouseout: 'blue', | |
click: 'yellow' | |
} | |
var highlight = function(event) { | |
Event.stop(event); | |
element = Event.element(event); | |
Element.setStyle(element, {backgroundColor: eventColors[event.type]}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Text.Html | |
dateSelect year = dateSelect "born_on_month" [1..12] monthName | |
+++ dateSelect "born_on_day" [1..31] show | |
+++ dateSelect "born_on_year" [year-80..year] show | |
where monthName x = words "January February March April May June July August September October November December" !! (x - 1) | |
dateSelect n xs f = (select << map (dateOption f) xs) ! [name n] | |
dateOption f x = (option << f x) ! [value $ show x] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
products = concatMap (\x -> map (*x) [1..10]) [1..10] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad (filterM) | |
powerset :: [a] -> [[a]] | |
powerset = filterM (\x -> [True, False]) |
OlderNewer