Skip to content

Instantly share code, notes, and snippets.

View tmhedberg's full-sized avatar

Taylor M. Hedberg tmhedberg

View GitHub Profile
#my_table td {
font-weight: bold;
}
@tmhedberg
tmhedberg / mkbean.awk
Created February 2, 2011 21:51
Generate a JavaBean class body from a list of properties
#!/bin/awk -f
{
printf "private %s %s;\n", $1, $2;
cap = sprintf("%s%s", toupper(substr($2, 1, 1)), substr($2, 2));
get[NR] = sprintf("public %s get%s() {\n\treturn %s;\n}", $1, cap, $2);
set[NR] = sprintf("public void set%s(final %s %s) {\n\tthis.%s = %s;\n}", cap, $1, $2, $2, $2);
}
@tmhedberg
tmhedberg / serialgen
Created May 13, 2011 16:07
Generate a pseudorandom signed integer
#!/bin/bash
[[ $# -lt 1 ]] &&
B=8 ||
B=$1
dd if=/dev/urandom bs=1 count="$B" 2>/dev/null |
od -A n -t d"$B" |
sed 's/^[[:space:]]*//'
@tmhedberg
tmhedberg / touchtoggle
Created May 17, 2011 03:28
Toggle Synaptics touchpad on/off
#!/bin/bash
cmd='synclient TouchpadOff='
[[ $(
synclient |
grep '^\s*TouchpadOff' |
awk '{print $3}'
) == 0 ]] &&
${cmd}1 ||
@tmhedberg
tmhedberg / fp-compile
Created May 31, 2011 17:41
Compile an Intermec Fingerprint source file to its directly executable format
#!/usr/bin/python
import re
import sys
argc = len(sys.argv)
ifd = sys.stdin if argc <= 1 else open(sys.argv[1])
ofd = sys.stdout if argc <= 2 else open(sys.argv[2], mode="w")
lnum = 10
@tmhedberg
tmhedberg / fpipe.sh
Created June 15, 2011 15:13
Shell function to pipe text to a program which does not read from stdin
fpipe () {
local tmpfile=`mktemp`
cat >$tmpfile
$@ $tmpfile
rm $tmpfile
}
@tmhedberg
tmhedberg / largepkg
Created June 16, 2011 16:34
List installed Arch Linux packages in descending order of size
#!/bin/bash
for pkg in `pacman -Qq`; do
size=`
pacman -Qi $pkg |
grep '^Installed Size' |
awk -F '[[:space:]]+:[[:space:]]+' '{print $2}'
`
echo "$size - $pkg"
done |
@tmhedberg
tmhedberg / git-treebase
Created July 18, 2011 18:55
Rebase a "tree" (connected DAG) of Git branches onto a common new base
#!/bin/bash
branches=$(
git branch --contains `
git rev-list $1..$2 |
tail -n 1
` |
sed 's/^..//'
)
@tmhedberg
tmhedberg / auto_error_class.py
Created July 23, 2011 21:25
Monkey-patch a Django Field instance in order to automatically add a CSS class to its widget when validation fails
import types
from django.core import exceptions
def auto_error_class(field, error_class="error"):
inner_clean = field.clean
def wrap_clean(self, *args, **kwargs):
try:
@tmhedberg
tmhedberg / pacweek
Created July 24, 2011 18:37
List Arch Linux packages recently added to the system
#!/bin/bash
# List Arch Linux packages recently added to the system
#
# Usage:
#
# pacweek [<since>]
#
# Default interval is 1 week ago.
#