Skip to content

Instantly share code, notes, and snippets.

Phil Pennock philpennock

Block or report user

Report or block philpennock

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@philpennock
philpennock / private_cache_in_func.py
Created Jan 12, 2011
Demo of Python one-time eval of function declaration default params, used for caching.
View private_cache_in_func.py
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 Mar 20, 2012
Sample WSGI debug application
View pdebug.py
#!/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 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
philpennock / exit_check.go
Created Oct 24, 2012
Showing interactions of defer, os.Exit and panic in Golang.
View exit_check.go
package main
import (
"container/list"
"flag"
"fmt"
"os"
"sync"
"time"
)
@philpennock
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;
View guarded_memory_alloc_test.c
// this is C99
// compile: gcc -std=c99 -ggdb -O3 -Wall guarded_memory_alloc_test.c
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
View polygon.py
#!/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-dessicate
Created Nov 13, 2013
git subcommand to work on serious cleanup and space reclamation
View git-dessicate
#!/bin/sh
SUBDIRECTORY_OK=true
[ -d /opt/local/bin ] && PATH="/opt/local/bin:$PATH"
. "$(git --exec-path)/git-sh-setup"
set -e
git fsck --full
git prune -v
@philpennock
philpennock / git-pushgroup
Created Nov 13, 2013
git: Push a branch to a group of remotes
View git-pushgroup
#!/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
View serve_here
#!/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"
You can’t perform that action at this time.