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 eachnode(tree, n=0): | |
if n == len(tree): | |
raise StopIteration | |
yield tree[n] ## The method of access is specific to the data structure | |
for subnode in eachnode(tree, n+1): | |
yield subnode | |
if __name__ == '__main__': | |
tree = [10,20,30] ## Assuming array for test purposes, can be a real tree. |
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
#!/usr/bin/env python | |
def flatten(array): | |
out = [] | |
def real_flatten(array): | |
for item in array: | |
if isinstance(item, (list, tuple, set)): | |
real_flatten(item) | |
else: | |
out.append(item) |
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
if has('ruby') | |
function! Heading(char) | |
ruby <<EOF | |
buffer = VIM::Buffer.current | |
new_line = VIM::evaluate("a:char") * buffer.line.length | |
buffer.append(buffer.line_number, new_line) | |
EOF | |
endfunction | |
command H1 call Heading('=') |
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
if has('python') " Assumes Python >= 2.6 | |
" Quick way to open a filename under the cursor in a new tab | |
" (or URL in a browser) | |
function! Open() | |
python <<EOF | |
import re | |
import platform | |
import vim |
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 flask-boilerplate-tmux | |
{ | |
# https://github.com/swaroopch/flask-boilerplate | |
BASE="$HOME/code/flask-boilerplate" | |
cd $BASE | |
tmux start-server | |
tmux new-session -d -s flaskboilerplate -n model |
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
#!/usr/bin/env python | |
import oauth2 as oauth # pip install oauth2 | |
parameters = { | |
'oauth_version' : '1.0', | |
'oauth_nonce' : oauth.generate_nonce(), | |
'oauth_timestamp' : oauth.generate_timestamp(), | |
} |
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
→ python server.py | |
Run after this server starts : curl http://127.0.0.1:5000/?test=1 | |
[2012-02-15 12:24:34,716] [werkzeug] [INFO] * Running on http://127.0.0.1:5000/ | |
[2012-02-15 12:24:34,717] [werkzeug] [INFO] * Restarting with reloader | |
Run after this server starts : curl http://127.0.0.1:5000/?test=1 | |
[2012-02-15 12:24:36,459] [root] [INFO] Received data ImmutableMultiDict([('test', u'1')]) | |
[2012-02-15 12:24:36,460] [root] [INFO] Closing connection! | |
[2012-02-15 12:24:36,460] [werkzeug] [INFO] 127.0.0.1 - - [15/Feb/2012 12:24:36] "GET /?test=1 HTTP/1.1" 200 - | |
[2012-02-15 12:24:36,460] [root] [INFO] In separate process, doing something with data {'test': [u'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
// https://github.com/xetorthio/jedis | |
import redis.clients.jedis.Jedis; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; |
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
(ns scratchpad.core | |
(:require [monger.core :as mg] | |
[monger.collection :as mc] | |
[monger.query :as mq])) | |
(def local-mongodb | |
(.getDB (mg/connect-via-uri! "mongodb://127.0.0.1:27017/local") "local")) | |
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
# Before: I have a local Java or Django server running on port 8000 | |
function expose_port { | |
local_port=$1 | |
shift | |
ssh -vvv -i "$HOME/.ssh/aws.pem" -N -R "9000:localhost:8000" "[email protected]" | |
} |
OlderNewer