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) |
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 |
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'} |
View exit_check.go
package main | |
import ( | |
"container/list" | |
"flag" | |
"fmt" | |
"os" | |
"sync" | |
"time" | |
) |
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)' |
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 |
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" |
OlderNewer