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 Benerator | |
def initialize(&block) | |
@block = block | |
end | |
def next | |
as_array.shift | |
end | |
def as_array |
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 Parent | |
def foo | |
"Parent#foo" | |
end | |
alias :bar :foo | |
end | |
class Child < Parent | |
def foo | |
"Child#foo" |
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
def foo(a=[]): | |
a.append(1) | |
return a | |
foo() # => [1] | |
foo() # => [1, 1] | |
foo() # => [1, 1, 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
{ | |
"java": { | |
"jdk_version": "7", | |
"oracle": {"accept_oracle_download_terms": "true"}, | |
"accept_license_agreement": "true", | |
"install_flavor": "oracle" | |
}, | |
"elasticsearch": { | |
"nginx": { | |
"users": [{"username": "salesloft", "password": "<haha you wish>"}], |
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
sqrtSums :: Double -> Int | |
sqrtSums x = length (takeWhile (<x) (scanl1 (+) (map sqrt [1..]))) + 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
$ time ls -lh > ~/files.txt | |
real 186m14.030s | |
user 0m9.361s | |
sys 43m37.939s |
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
ve() { | |
local curdir ve | |
curdir="$PWD" | |
[ -z "$1" ] && ve="ve" || ve="$1" | |
while ! ls -d "$ve" >/dev/null 2>&1; do | |
if [ "$PWD" == "/" ]; then | |
echo "Cannot find a '$ve' directory on the current path" >&2 | |
cd $curdir | |
return -1 | |
fi |
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
[alias] | |
pep8 = !git status -s | awk '{print $2}' | grep '.py' | xargs pep8 | |
pyflakes = !git status -s | awk '{print $2}' | grep '.py' | xargs pyflakes |
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 Regexen | |
def initialize(a={}) | |
a.default_proc = proc { |h,k| [] } | |
@good = a[:good] | |
@bad = a[:bad] | |
end | |
def good=(r) | |
@good << r | |
end | |
def bad=(r) |
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
SINGLE_RATES = {8700 => 0.10, 35350 => 0.15, 85650 => 0.25, 178650 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35} | |
MARRIED_RATES = {17400 => 0.10, 70700 => 0.15, 142700 => 0.25, 217450 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35} | |
def taxes(amt, rates=SINGLE_RATES) | |
last_cap = 0 | |
taxes = 0 | |
rates.each do |cap, rate| | |
taxable = amt - last_cap | |
if taxable > 0 | |
taxes += [cap, taxable].min * rate |