Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / bashrc
Created June 9, 2013 16:47
View branch name in command prompt for git and hg repositories, as well as current applied patch queue for mercurial
###################################################
# Command line prompt settings
###################################################
__git_hg_ps1 () {
local b="$(git symbolic-ref HEAD 2>/dev/null)";
if [ -n "$b" ]; then
printf " [%s]" "${b##refs/heads/}";
elif [ "$(hg root 2> /dev/null)" ]; then
printf " [%s]" "$(hg branch)"
fi
@stantonk
stantonk / django_orm_query_stacktrace.py
Created May 4, 2013 00:49
Django logging config to dump a stack trace for every ORM query, so you can find the code that is producing queries that are icky.
DEBUG=True
LOG_FILE_SIZE=1024*1000
LOGGING = {
'version' : 1,
'disable_existing_loggers':True,
'formatters' : {
'simple' : {
'format' : '%(levelname)s %(name)s %(message)s'
},
@stantonk
stantonk / multitail.sh
Created February 27, 2013 21:43
Unified tail -f of a log file across multiple hosts via ssh.
#!/bin/bash
HOSTS=(PUT, YOUR, HOSTS, HERE)
CMD="tail -f logs/api.log"
echo "Hit CTRL-C to stop"
sleep 0.5
PIDS=""
for host in ${HOSTS[*]}
do
@stantonk
stantonk / unicode_examples.py
Created February 6, 2013 20:20
Shows how unicode & str types, utf-8 and ascii encodings interoperate with each other in Python 2.x
import sys
def _helper(s, method, encoding):
try:
print 'print s.%s(\'%s\'): %s' % (method, encoding, getattr(s, method)(encoding))
except UnicodeError as e:
print 'print s.%s(\'%s\'): %s' % (method, encoding, e)
def test_encodings(s):
@stantonk
stantonk / flake8.xml
Created January 26, 2013 01:17
PyCharm Flake8 Configuration XML File
<!-- Drop this in ~/Library/Preferences/PyCharm20/tools -->
<!-- make sure you set the path to flake8 executable for your machine in the COMMAND option -->
<?xml version="1.0" encoding="UTF-8"?>
<toolSet name="Flake8">
<tool name="Flake8 File" showInMainMenu="true" showInEditor="true" showInProject="true" showInSearchPopup="false" disabled="false" useConsole="true" synchronizeAfterRun="true">
<exec>
<option name="COMMAND" value="/usr/local/share/python/flake8" />
<option name="PARAMETERS" value="--max-line-length=120 --ignore=E301,E302,E261,E262,W404 $FileDir$/$FileName$" />
<option name="WORKING_DIRECTORY" value="$FileDir$" />
@stantonk
stantonk / doit
Created November 15, 2012 22:46
Install python 2.7.3 on CentOS 5.8
#!/bin/bash
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
yum groupinstall "Development tools"
yum install zlib-devel
yum install bzip2-devel openssl-devel ncurses-devel
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
@stantonk
stantonk / csv
Last active October 5, 2015 22:07
Read a list of values separated by newlines from stdin and output the values on a single line separated by commas to stdout
#!/usr/bin/env bash
######
# Why is this useful?
#
# Say you have a list of ids in a database tool like SequelPro in
# the result of a query. It is possible to copy an entire column
# to the clipboard. But then you may want to pass that list of
# ids as a comma-separated list into an HTTP(S) API endpoint for
# testing. This solves that problem!
@stantonk
stantonk / date2epoch.py
Last active October 5, 2015 15:47
date2epoch
#!/usr/bin/env python
# Notes
# One can easily get the current epoch using the date command, like so:
#
# in your timezone:
#
# $ date -j +"%s"
# 1363104249
#
@stantonk
stantonk / .gvimrc.after
Created March 27, 2012 22:25
My current .gvimrc.after
"colo dawn
"colo ir_black
"colo maroloccio
colo darkbone
"set guifont=Monaco:h14
set guifont=DejaVu\ Sans\ Mono\ Bold:h14
"set guifont=Inconsolata\ Bold:h16
set hls is ic scs
set gcr=n:blinkon0
@stantonk
stantonk / hgbatch.sh
Created March 8, 2012 17:06
Batch execute any single mercurial command on all repositories within a directory.
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg $@" to batch execute a mercurial command in all the repositories.
#
# Make sure you know what you're doing before running this ;-)
#
# Examples:
#
# Perform pull -u on all repositories to get the latest changes and update: