Skip to content

Instantly share code, notes, and snippets.


Phil Pennock philpennock

View GitHub Profile
View serve_here
#!/bin/sh -u
python3 -m http.server "$PORT"
[ $ev -ne $CMD_NOT_FOUND ] && exit $ev
python2 -m SimpleHTTPServer "$PORT"

Keybase proof

I hereby claim:

  • I am philpennock on github.
  • I am philpennock ( on keybase.
  • I have a public key whose fingerprint is C865 F6AF 2461 6A74 9836 576B 310D 6001 650E 06D3

To claim this, I am signing this object:

philpennock / fixup-repo
Created Apr 8, 2015
Bourne-shell snippet for fixing up a git repo cloned from github to add the PR fetch set, for CLI diff of a PR.
View fixup-repo
origin_url=$(git config --local --get remote.origin.url)
case $origin_url in
fetches="$(git config --local --get-all remote.origin.fetch)"
case $fetches in
*origin/pr/*) # no action
git config --local --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
philpennock /
Created Jan 12, 2011
Demo of Python one-time eval of function declaration default params, used for caching.
def foo(a, b=None, cache={}):
if b is not None:
cache[a] = b
return b
if a in cache:
return cache[a]
raise KeyError('Bleh, no %s' % a)
philpennock /
Created Mar 20, 2012
Sample WSGI debug application
from __future__ import print_function
import os
import threading
import time
startup_lock = threading.Lock()
philpennock / gist:3505352
Created Aug 28, 2012
Demonstrate python function *args & **kwargs
View gist:3505352
>>> def foo(alpha, *args, **kwargs):
... print 'Foo called, alpha = %s' % repr(alpha)
... for a in args:
... print 'Arg: {%s}' % repr(a)
... for k, v in kwargs.iteritems():
... print 'Arg \"%s\" = \"%s\"' % (k, v)
>>> foo(234234, 'snert', 'wibble', 'bleurgh', fred=42, barney=-1)
Foo called, alpha = 234234
Arg: {'snert'}
philpennock / update-home-ip
Created Dec 18, 2015
7 * * * * /usr/local/sbin/update-home-ip cron
View update-home-ip
#!/bin/bash -eu
progname="$(basename "$0")"
die() { printf >&2 "%s: %s\n" "$progname" "$*" ; exit 1; }
if [[ $# -gt 0 && "$1" == "cron" ]]; then
sleep $((10 + RANDOM % 40 ))
philpennock / foreach-beginend
Last active Dec 25, 2015
Used to iterate over PEM-encoded items in a file
View foreach-beginend
#!/usr/bin/env perl
# For a file containing PEM objects or PGP objects or whatever, emit the file
# filtering the objects through a command-line which takes the object on stdin.
# foreach-beginend bundle.crt openssl x509 -noout -text
use strict;
use warnings;
#!/usr/bin/env python3.2
polygon: polygon puzzle solver business cards might have a polygon puzzler on a promotional card in
the pack. This tool finds the words.
__author__ = ' (Phil Pennock)'
philpennock / git-dessicate
Created Nov 13, 2013
git subcommand to work on serious cleanup and space reclamation
View git-dessicate
[ -d /opt/local/bin ] && PATH="/opt/local/bin:$PATH"
. "$(git --exec-path)/git-sh-setup"
set -e
git fsck --full
git prune -v