Skip to content

Instantly share code, notes, and snippets.

View philchristensen's full-sized avatar

Phil Christensen philchristensen

View GitHub Profile
@philchristensen
philchristensen / svn-color.py
Created August 10, 2010 20:20
Color-Coded `svn status`

First there was: http://snipplr.com/view/15246/color-coded-svn-status

Then there was: http://snipplr.com/view/16540/color-coded-svn-status-v2

A few days ago, I found a handy script online that colorized the output of SVN status. It worked pretty well, but needed a little polish and a couple of tweaks to make it use more common Python idioms. As I continued to use it and fix bugs and inefficiencies, I ended up replacing nearly every line in the original, but it was still a great starting point.

Additional changes include ANSI word-wrapping, a configurable tab expansion feature (for better code alignment), the 'colorizedSubcommands' sequence so that only applicable commands get colorized, use of proper subprocess module calls so that piping through less will work (for example, try svn-color diff | less -r to see colorized diff output).

To use, stick it somewhere, make executable (`chmod 7

@philchristensen
philchristensen / wikifetch.pl
Created October 29, 2010 17:11
a script to download wikipedia image galleries
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;
my $mech = new WWW::Mechanize(
autocheck => 1
);
@philchristensen
philchristensen / ichat-fortune.pl
Created October 29, 2010 17:12
a script to set your iChat message to the output from fortune
#!/usr/bin/perl
use strict;
use warnings;
my $fortune = `/sw/bin/fortune -s`;
$fortune =~ s/"/\\"/g;
open(OSASCRIPT, "| /usr/bin/osascript");
@philchristensen
philchristensen / README.txt
Created October 29, 2010 17:16
Script to automate converting batches of audio files
SoundGlue
by Phil Christensen
9-18-2005
This is a script that will handle the ins and outs of converting popular lossless
sound formats to mp3. To the purists, I say, "go to hell!", and to everyone else
I recommend not distributing the lossy files back to the world.
This has some tie-ins with etree.org, or more specifically, with FurtherNet,
although since the advent of BitTorrent, I guess FN doesn't get used quite as
@philchristensen
philchristensen / wabi.py
Created October 29, 2010 17:17
My first python project, a wiki; this is from back when WikiWikiWeb was all there was.
#!/usr/bin/python
import cgi, sys, os, traceback, string, re, binascii, urlparse
import cgitb; cgitb.enable()
try:
import cPickle as pickle
except:
import pickle
@philchristensen
philchristensen / cutup.pl
Created October 29, 2010 17:18
Takes text input files and generates William Borroughs-style cutup poetry
#!/usr/bin/perl
use strict;
use Options;
my $options = new Options(params => [
['file', 'f', undef, 'The data file of return-separated lines to cutup.'],
['lines', 'l', 10, 'Resulting cutup will contain this many lines.'],
#['density', 'd', 3, 'Each line will contain, at most, this many pieces.'],
@philchristensen
philchristensen / dbcopy.pl
Created October 29, 2010 17:33
A tool for syncing local databases with a remote master
#!/usr/bin/env perl
##################################################################
# dbcopy.pl 1.0
#
# Copyright (C) 2008 Phil Christensen
##################################################################
use strict;
use warnings;
@philchristensen
philchristensen / svndist.pl
Created October 29, 2010 17:35
A tool for updating checked out SVN repos on remote servers
#!/usr/bin/env perl
##################################################################
# svndist.pl 1.0
#
# Copyright (C) 2008 Phil Christensen
##################################################################
use strict;
use warnings;
@philchristensen
philchristensen / japh.pl
Created November 8, 2010 16:36
just another perl hacker...
$Z=sub{for($Z=0;$Z<@_;$Z++){$z=oct("$_[$Z++]")."$_[$Z++]".$_[$Z];for($W=0;
$W<length($z);$W++){($n,$N)=split(m--,substr($z,$W,2));$W++;$X=int($n);
push(@V,split(m++,${N}x${X}));}}for($W=0;$W<@V/3;$W++){$_=chr(int($V[$W].
$V[$W+055].$V[$W+0x5A]));$_=~tr,a-zA-Z,n-za-mN-ZA-M,;print $_;}};$Z->(10016,0x460,
4120,6046,0x1810,3110,15706,0x83e,1130,2437,0xb5e,2110,2447,0x456,1213,6050,0x456,
3411,2613,0x840,1321,1763,0x7db,1910,2151,0x584,1312,1771,0x715,1714,2130,0x77a,
2112,3256,0x4ba,1411,7032,0x5ef,1718,2142,0x6af,1812,2442,0x6b0,1417);
@philchristensen
philchristensen / init_deferred_example.py
Created November 8, 2010 16:46
a method decorator to enable asynchronous object construction in Twisted
from twisted.internet import defer, reactor
from twisted.enterprise import adbapi
def deferredInit(deferredName):
"""
Mark a method as waiting on deferred initialization.
"""
def _deferredInit(func):
def __deferredInit(self, *args, **kwargs):
initDeferred = None