This file contains 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
# Emulating `sed` with inplace editing **without** backups for OS X | |
# Tested with zsh. | |
sedi () { | |
local ext='.sedi-bak' | |
sed -i $ext $@ | |
rm "${@: -1}$ext" | |
} |
This file contains 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
class Hash | |
alias_method :[], :fetch # !> method redefined; discarding old [] | |
end | |
h = {a: 1} | |
h[:a] # => 1 | |
h[:b] rescue $! # => #<KeyError: key not found: :b> | |
h[:b, 2] # => 2 |
This file contains 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
# # Adventures in `flat_map` land | |
# | |
# Investigating the conceptual difference between Ruby's `flat_map` and Scala's `flatMap`. | |
# | |
# Ruby's `flat_map` | |
a = [[1], [2], [[3]], [[4], 5], [[[6]]]] | |
a.flat_map { |e| e.first } # => [1, 2, 3, 4, [6]] | |
# ... which is the same as ... | |
a.map { |e| e.first }.flatten(1) # => [1, 2, 3, 4, [6]] |
This file contains 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
# Composition | |
class Eat | |
def do_it | |
puts 'Nom, nom ...' | |
end | |
end | |
class Say | |
def do_it |
This file contains 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
# git lye | |
# An attempt to make rebasing easy, by draining unnessarcy commit noise. | |
# No warranty, use at own risk. | |
# Author Hannes Tydén <hannes@tyden.name> | |
# Contributor Tobias Schmidt <ts@soundcloud.com> | |
# TODO | |
# - Don't sign off all commits are by current user. |
This file contains 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
scala> def whatIsMyName[A,B](map: Map[A, Seq[B]]): List[(A, B)] = | |
| map.map { case (k, v) => v.map(k -> _) }.flatten.toList | |
whatIsMyName: [A, B](map: Map[A,Seq[B]])List[(A, B)] | |
scala> whatIsMyName(Map('a -> Seq(1,2), 'b -> Seq(3,4))) | |
res0: List[(Symbol, Int)] = List(('a,1), ('a,2), ('b,3), ('b,4)) |
This file contains 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
class E < StandardError; end | |
def m(raise_exception) | |
y do | |
r(raise_exception) | |
:nothing_raised | |
end | |
rescue E | |
:rescued | |
end |
This file contains 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 | |
function _andr_push { | |
echo "Pushing $1" | |
adb $target_flag push $1 $books_dir | |
} | |
function _andr_delete { | |
echo "Removing $1" | |
adb $target_flag shell "rm $books_dir/$1" |
This file contains 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
source 'https://rubygems.org' do | |
gem 'mechanize' | |
end |
This file contains 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/sh | |
# .git/hooks/post-checkout | |
# chmod +x .git/hooks/post-checkout | |
if [ $(git symbolic-ref HEAD | cut -d '/' -f 3) == 'master' ]; then | |
lines[0]="Master, Master, where's the dreams that I've been after?" | |
lines[1]="Master, Master, you promised only lies" | |
lines[2]="Laughter, laughter, all I hear or see is laughter" | |
lines[3]="Laughter, laughter, laughing at my cries" | |
echo " ${lines[$((RANDOM%${#lines[*]}))]}"; |