Skip to content

Instantly share code, notes, and snippets.

def get_revision(path=None):
"""
Return the revision identifier of the last commit in a git or svn source pool.
"""
if path is None:
path = "."
import os, re, subprocess
revision = None
os.chdir(path)
context = {
'database': {
'port': 9990,
'users': ['number2', 'dr_evil']
},
'admins': ['number2@virtucon.com', 'dr_evil@virtucon.com'],
'domain.name': 'virtucon.com'
}
# Most comprehensive solution by http://stackoverflow.com/users/95810/alex-martelli
@jkeyes
jkeyes / newtab
Created October 21, 2010 11:54
Opens a new tab in Terminal.app for the current working directory
#!/bin/sh -
if [ $# -ne 1 ]; then
PATHDIR=`pwd`
else
PATHDIR=$1
fi
/usr/bin/osascript > /dev/null <<-EOF
activate application "Terminal"
@jkeyes
jkeyes / gist:1028958
Created June 16, 2011 09:40
Find unbound ports on localhost
import random
import socket
# range of ports where available ports can be found
PORT_RANGE = [33000,60000]
def find_unbound_port():
"""
Returns an unbound port number on 127.0.0.1.
"""
@jkeyes
jkeyes / gist:1030351
Created June 16, 2011 21:38
Get the maximum vserver id and maximum source id from a cherokee configuration file.
import os
import re
def increpl(matchobj):
"""
Replace the include statement with the contnet of the file.
"""
inc = matchobj.group(1)
return parse(inc)
@jkeyes
jkeyes / excel2csv.py
Created June 27, 2011 10:14
Excel to CSV
import csv
from xlrd import open_workbook
def excel_to_csv(excel_file, include=None):
"""
Convert the data in the excel_file to CSV. If
include is specified, only those named columns
will be included in the CSV.
"""
@jkeyes
jkeyes / pathfinder_depth.py
Created September 13, 2011 15:02
pathfinder depth support
import pathfinder
# only search top 2 levels of the directory tree
paths = pathfinder.pathfind(".", depth=2)
@jkeyes
jkeyes / gist:1242040
Created September 26, 2011 11:20
Compile LESS files when a save is detected
#!/bin/bash
watchmedo shell-command --patterns="*.less" --command=\
'LESS=`echo "${watch_src_path}" | sed s/.less/.css/`; \
echo compile: "${watch_src_path}";\
lessc "${watch_src_path}" "${LESS}"; \
if [ "$?" -eq "0" ]; then echo wrote: "${LESS}"; fi' $*
(python2.7)django-exceptional $ pip install --upgrade django-exceptional
Downloading/unpacking django-exceptional
Downloading django-exceptional-0.1.5.tar.gz
Running setup.py egg_info for package django-exceptional
Installing collected packages: django-exceptional
Running setup.py install for django-exceptional
Successfully installed django-exceptional
Cleaning up...
/*** tough-cookie/lib/cookie.js ***/
/* I added the following to the end of the file for testing purposes */
memstore = require('./memstore');
module.exports.memorystore = memstore.MemoryCookieStore;
/*** jsonstore.js ***/
var tough = require('tough-cookie');
// ...