Given a matrix
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
Unroll it as a spiral by printing first the top row, then the last column, then the bottom row backwards, etc.
| 1.9.2-p320 :001 > roses = "red" and "blue" | |
| => "blue" | |
| 1.9.2-p320 :002 > violets = "red" && "blue" | |
| => "blue" | |
| 1.9.2-p320 :003 > roses | |
| => "red" | |
| 1.9.2-p320 :004 > violets | |
| => "blue" |
| function cowsay_everything { | |
| if [[ ! "$BUFFER" =~ "vim|fg|%\d|clear" ]]; then | |
| BUFFER="$BUFFER | cowsay -n" | |
| fi | |
| zle accept-line | |
| } | |
| zle -N cowsay_everything_widget cowsay_everything | |
| function cowsay_on { | |
| bindkey '^J' cowsay_everything_widget |
Given a matrix
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
Unroll it as a spiral by printing first the top row, then the last column, then the bottom row backwards, etc.
| class Foo(object): | |
| __slots__ = ( "foo", "bar" ) | |
| def __init__(self): | |
| pass | |
| f = Foo() | |
| f.foo = "foo" | |
| f.bar = "bar" | |
| f.baz = "baz" |
| import Data.List | |
| sum_zero :: (Integral a) => [a] -> Bool | |
| sum_zero = any (==0) . map sum . filter ((>1) . length) . subsequences |
| " | |
| " While editing a Markdown document in Vim, preview it in the | |
| " default browser. | |
| " | |
| " Author: Nate Silva | |
| " | |
| " To install: Place markdown.vim in ~/.vim/ftplugin or | |
| " %USERPROFILE%\vimfiles\ftplugin. | |
| " | |
| " To use: While editing a Markdown file, press ',p' (comma p) |
| def check_luhn(personal_number) | |
| personal_number.gsub(/\D/,'')[-10,10].split('').map.with_index {|c,i| i % 2 == 0 ? c.to_i * 2 : c.to_i }.join('').split('').reduce(0) {|memo,c| c.to_i + memo } % 10 == 0 | |
| end |
| # find modules that don't .npmignore their test (or tests) directories | |
| # and how much disk space those tests take up | |
| find node_modules -type d -name "test*" | xargs du -csh |
| # So... hash.new takes an optional parameter with a default value, that's neat. | |
| > hash = Hash.new(0) | |
| > hash["foo"] | |
| => 0 | |
| > hash["bar"] += 5 | |
| => 5 | |
| > hash | |
| => {"bar" => 5} |