Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am thepaul on github.
  • I am thepaul (https://keybase.io/thepaul) on keybase.
  • I have a public key ASDVjs42Wo8PNSFWHDKiZmIsGEemdqZ4En1SFeO0uzkhswo

To claim this, I am signing this object:

git for-each-ref --format '%(refname) %(authoremail) %(committerdate:raw)' refs/remotes/origin/ \
| sort -k2,3 \
| awk '$3 < (systime()-(86400*30)) {
gsub(/refs\/remotes\//, "", $1);
printf "%-30s %-26s %s\n", $1, $2, strftime("%Y-%m-%d %H:%M", $3)
}'
@thepaul
thepaul / yieldscanner.py
Created January 12, 2016 00:57
Similar to re.Scanner but works as a coroutine, yielding tokens as found
import re
class NotAToken(Exception):
pass
class YieldScanner(re.Scanner):
def scan(self, inputstr):
match = self.scanner.scanner(inputstr).match
pos = 0
while True:
diff --git a/tools/dockerz/Dockerfile b/tools/dockerz/Dockerfile
new file mode 100644
index 0000000..0eafb35
--- /dev/null
+++ b/tools/dockerz/Dockerfile
@@ -0,0 +1,17 @@
+FROM ubuntu:trusty
+MAINTAINER <pcannon@epochlabs.com>
+
+RUN apt-get -y update \
@thepaul
thepaul / gist:0e611da8b4fadec94568
Created July 9, 2015 21:29
wait for all subprocesses in a list to exit
import signal
def wait_for_subprocs(procs, cb=lambda proc: 0):
# do-nothing handler for SIGCHLD, just so it's something other than SIG_DFL.
# otherwise, Python won't interrupt syscalls.
oldhandler = signal.signal(signal.SIGCHLD, lambda *_: None)
try:
while procs:
signal.pause()
aliveprocs = []
@thepaul
thepaul / gist:aec592cb62294e587ef8
Created June 17, 2015 22:33
things in the Python standard library which use super()
argparse (all classes)
abc.ABCMeta
collections.Counter
fractions.Fraction
plistlib.Dict and plistlib.Plist
random.Random
unittest.TextTestResult and unittest.FunctionTestCase
weakref.KeyedRef
zipfile.ZipExtFile
ctypes.py_object
@thepaul
thepaul / ssh_tunnel_control.py
Created May 14, 2014 20:32
ssh tunnel up/down
import contextlib
import os
import subprocess
import tempfile
class SshTunnelDefinition:
def __init__(self, host, user=None, executable='ssh', localforwards=(),
remoteforwards=(), port=None, options=None):
self.executable = executable
@thepaul
thepaul / SanerConfigParser.py
Created May 13, 2014 22:42
# the ConfigParser.*ConfigParser family is just comically terrible
import ConfigParser
class SanerConfigParser(ConfigParser.SafeConfigParser):
def __init__(self, defaults=None, dict_type=dict, allow_no_value=False):
ConfigParser.SafeConfigParser.__init__(self, dict_type=dict_type,
allow_no_value=allow_no_value)
self.mydefaults = defaults or {}
no_default = object()
@thepaul
thepaul / gist:8588668
Last active January 9, 2016 18:30
send python stdlib logging output through the Twisted logging system
import logging
from twisted.python import log, failure
class TwistedLogHandler(logging.Handler):
"""
Sends Python stdlib logging output through the Twisted logging system.
"""
def __init__(self, twistedlogpublisher=None):
@thepaul
thepaul / unused_port.py
Created December 28, 2013 02:55
choose a port number unused for TCP on all local inet interfaces (or on a particular interface). use sock_type=socket.SOCK_DGRAM for an unused UDP port instead of TCP.
import socket
import contextlib
def choose_unused_port(interface='0.0.0.0', sock_type=socket.SOCK_STREAM):
with contextlib.closing(socket.socket(socket.AF_INET, sock_type)) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((interface, 0))
return s.getsockname()[1]