Skip to content

Instantly share code, notes, and snippets.

View philpennock's full-sized avatar

Phil Pennock philpennock

View GitHub Profile
#!/bin/sh -u
CMD_NOT_FOUND=127
PORT="${1:-8000}"
python3 -m http.server "$PORT"
ev=$?
[ $ev -ne $CMD_NOT_FOUND ] && exit $ev
python2 -m SimpleHTTPServer "$PORT"

Keybase proof

I hereby claim:

  • I am philpennock on github.
  • I am philpennock (https://keybase.io/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
philpennock / fixup-repo
Created April 8, 2015 16:56
Bourne-shell snippet for fixing up a git repo cloned from github to add the PR fetch set, for CLI diff of a PR.
origin_url=$(git config --local --get remote.origin.url)
case $origin_url in
github:*|git@github.*|*//github.*)
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
philpennock / private_cache_in_func.py
Created January 12, 2011 09:36
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
philpennock / pdebug.py
Created March 20, 2012 09:30
Sample WSGI debug application
#!/usr/local/bin/python2.7
from __future__ import print_function
import os
import threading
import time
startup_lock = threading.Lock()
COUNTER = None
@philpennock
philpennock / gist:3505352
Created August 28, 2012 23:38
Demonstrate python function *args & **kwargs
>>> 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
philpennock / update-home-ip
Created December 18, 2015 06:13
7 * * * * /usr/local/sbin/update-home-ip cron
#!/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 ))
fi
dynhost=CENSORED
#!/usr/bin/env python3.2
"""
polygon: moo.com polygon puzzle solver
moo.com business cards might have a polygon puzzler on a promotional card in
the pack. This tool finds the words.
"""
__author__ = 'syscomet@gmail.com (Phil Pennock)'
@philpennock
philpennock / git-pushgroup
Created November 13, 2013 01:59
git: Push a branch to a group of remotes
#!/bin/sh
groupname="${1:?Need a group to push to}"
branch="${2:-master}"
for r in $(git config "remotes.${groupname}"); do
echo >&2 "Pushing '${branch}' to '${r}'"
git push "$r" "$branch"
done
@philpennock
philpennock / uuidbot__main.go
Created January 13, 2016 19:03
A simple Slack responder to the /uuid command
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"strconv"
"strings"