Skip to content

Instantly share code, notes, and snippets.

@swaroopch
swaroopch / flask-boilerplate-tmux.bash
Created December 5, 2010 07:00
A command that scripts a tmux session
#!/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
@swaroopch
swaroopch / open_filename_in_tab.vim
Created August 6, 2010 06:18
In Vim, command to open a filename under the cursor in a new Vim tab (or if URL, open in browser)
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
@swaroopch
swaroopch / restructuredtext_helper.vim
Created August 3, 2010 14:15
Making it easy to create headings in ReStructuredText syntax, in Vim
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('=')
@swaroopch
swaroopch / flattener.py
Created July 20, 2010 07:45
Wondering of a clean way to flatten a list (multiple levels)
#!/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)
@swaroopch
swaroopch / treeiterator.py
Created June 23, 2010 05:59
Implement a tree iterator without using a stack
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.