This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# export2csv.py | |
# | |
# export random database stuff to csv | |
from __future__ import with_statement | |
import csv | |
def export2csv(cursor, outf): | |
""" | |
cursor should have an executed query already |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import contextmanager | |
@contextlib.contextmanager | |
def have_pidfile(fname): | |
f = open(fname, 'w') | |
f.write('%d\n' % os.getpid()) | |
f.flush() | |
s = os.fstat(f.fileno()) | |
dev, ino = s.st_dev, s.st_ino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from subprocess import check_output | |
from sys import stdout | |
from os import getpid | |
def info_about_socket(s, out=stdout): | |
""" | |
Write some information about the status and state of a socket object | |
to the file-like object 'out' (stdout, by default). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
awk '{x[$1]=x[$1]?(x[$1] VSEP OFS $2):$2}END{for(e in x){print e,x[e]}}' VSEP=, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ParallelBatcher.py | |
# | |
# Job pipeline for Twisted Matrix | |
# the paul 2011 | |
# | |
# Sort of goes between defer.DeferredList and plain Deferred chaining. | |
# When you have lots of jobs to do which take time (most likely because | |
# they have to wait on some network action) but you don't want to do | |
# them all at the same time (maybe the remote network action is CPU- or | |
# bandwidth-intensive and you want to avoid overloading the remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2001-2010 Twisted Matrix Laboratories. | |
# See LICENSE for details. | |
import traceback | |
import warnings | |
from sys import exc_info | |
# Twisted imports | |
from twisted.python import failure, lockfile | |
from twisted.python.util import mergeFunctionMetadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
xlog = log --graph --pretty=format:\"%C(yellow)%h%Creset %ad %s%C(cyan)%d%Creset %C(green)[%an]%Creset\" --date=short |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
backslash_shell_quote_re = re.compile(r'([^A-Za-z0-9_.,:/])') | |
def shell_escape(s, flavor='sh'): | |
""" | |
Escape a random string (s) so that it reads as a single word when | |
undergoing shell command-line parsing. | |
The default flavor should be safe for all mainstream shells I know | |
about, but there are some other escaping modes which may result in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
changelog_from_deb () { | |
# won't work when packages symlink their docs from another package from the same source; | |
# you'll get "No changelog found." | |
t="$(mktemp -d)" | |
p="$(dpkg-deb -f "$1" Package)" | |
fail=1 | |
dpkg-deb --fsys-tarfile "$1" | \ | |
tar -x --wildcards -C $t ./usr/share/doc/"$p"/changelog\* 2>/dev/null | |
for f in changelog.Debian.gz changelog.gz; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def center(text, width): | |
if len(text) < width: | |
diff = width - len(text) | |
pad = ' ' * (diff / 2) | |
text = pad + text + pad | |
if diff % 2: | |
text += ' ' | |
return text | |
def print_table(fieldnames, table, outstream=None): |
OlderNewer