Skip to content

Instantly share code, notes, and snippets.

View tmhedberg's full-sized avatar

Taylor M. Hedberg tmhedberg

View GitHub Profile
@tmhedberg
tmhedberg / sdl_test.c
Created February 12, 2012 21:45
Simple SDL graphics test
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
int main(void)
{
SDL_Surface *main_surf;
SDL_Event *const ev = malloc(sizeof (SDL_Event));
@tmhedberg
tmhedberg / ChurchBool.hs
Created December 29, 2011 18:17
Church Booleans in Haskell
{-# LANGUAGE FlexibleInstances, Rank2Types, TypeFamilies #-}
module ChurchBool where
type CB = forall a. a -> a -> a
instance a ~ Bool => Show (a -> a -> a) where
show cb = if cb True False then "cTrue" else "cFalse"
cTrue, cFalse :: CB
@tmhedberg
tmhedberg / jumpbuf.vim
Created November 18, 2011 15:46
Jump through Vim's jump list one buffer at a time
" Jump backwards or forwards through the jump list one buffer at a time,
" rather than one jump at a time.
"
" Use <Leader>o to jump backwards and <Leader>i to jump forwards
let s:JUMPLIMIT = 100
if exists('g:loaded_jump_buf') && loaded_jump_buf
finish
endif
@tmhedberg
tmhedberg / gist:1345463
Created November 7, 2011 16:40
bash function to provide improved Git status indicator in primary prompt
parse_git_branch () {
local stat
if ! stat=`git status -sb 2>/dev/null` || [[ -n $NO_GIT_PROMPT ]]; then
return
fi
local ref=`sed -nr '/^##/{s/^## (Initial commit on )?//;p}' <<<"$stat"`
local dirty=`
@tmhedberg
tmhedberg / crawlscores
Created November 1, 2011 04:45
Print Dungeon Crawl Stone Soup high score list
#!/bin/bash
# Print Dungeon Crawl Stone Soup high score list
{
echo ' |Score|Name|Level|Type|Religion|Runes Ascended'
for f in `ls -tr ~/.crawl/morgue/morgue-*.txt`; do
sed -nr '
3{
s/([0-9]+)./\1|/
@tmhedberg
tmhedberg / fxg.sh
Created October 20, 2011 20:40
Shell function to search specific files for a pattern (augmented grep)
# Common pattern for searching file contents
fxg () {
local OPTIND=1 findbase=. grepflags verbose=false usage=false
while getopts b:g:vh opt; do
case $opt in
b) findbase=$OPTARG ;;
g) grepflags=$OPTARG ;;
v) verbose=true ;;
@tmhedberg
tmhedberg / pacmanifest
Created August 6, 2011 14:05
Display the number of cached versions for each package in the pacman cache
#!/bin/bash
ls /var/cache/pacman/pkg |
awk -F - '
{
k = ""
for (i = 1; i < NF - 2; ++i)
k = k $i "-"
sub(/-$/, "", k)
@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.
#
@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 / 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/^..//'
)