Skip to content

Instantly share code, notes, and snippets.

View philchristensen's full-sized avatar

Phil Christensen philchristensen

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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
@philchristensen
philchristensen / switch_idea.py
Created November 8, 2010 16:48
sketch idea for implementing case/switch with Python decorators
case_dict = {}
def case(key=None):
def case_builder(func):
case_dict[key] = func
return func
return case_builder
def switch(value):
return case_dict[value]
@philchristensen
philchristensen / git-prompt.bash
Created December 19, 2010 20:20
add current git branch to shell prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "#"${ref#refs/heads/}
}
export PS1="\u@\h:\w\[\e[31;40m\]\$(parse_git_branch)\[\e[0m\] \$ "