Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import logging
from Queue import Empty
from multiprocessing import Queue, Pool, Process
logging.getLogger('').setLevel(logging.DEBUG)
"""
We can send instances thru Queues, and because the Queue is not a list,
import time
import multiprocessing
POOLSIZE = 4
N = 10
mgr = multiprocessing.Manager()
done = mgr.dict() # they don't implement sets. Thread-safe counter???
# this MUST be a globally defined funcion
def f(x):

An example of Python logging over a network, starting with an example from https://docs.python.org/2/howto/logging-cookbook.html.

This is very handy if you have a rack of servers and you want to aggregate logging statements from one or several of them to in some convenient place. This is especially handy if you're using an inversion-of-control framework (my own work these days is with Buildbot, which relies upon Twisted), because a lot of what's happening may be obscured, for instance by Deferreds but also possibly by

Output from this thing currently looks like this, but I'm interested in the possibility of throwing log records in an SQL database for purposes of sorting/filtering/searching, and presenting them with something like http://datatables.net.

@wware
wware / wwcrypt.py
Last active February 19, 2016 15:51
#!/usr/bin/env python
from Crypto.Cipher import AES
from Crypto import Random
from struct import pack
import argparse
import base64
import getpass
import math
import random
@wware
wware / wwlogger.py
Last active December 4, 2015 23:38
Install this in /usr/local/lib/python2.7/site-packages or wherever. It's useful.
import logging
import pprint
import traceback
_sql = False
try:
import sqlalchemy
import sqlparse
_sql = True
except ImportError:
@wware
wware / arduino_print_double.ino
Created July 25, 2015 23:59
An Arduino function to print a double-precision floating point number via Serial. Not exhaustively tested, use at your own risk.
void print_double(double val)
{
char buf[10];
int neg = (val < 0);
int exponent = 0;
if (val == 0.0) {
Serial.print("0.0");
return;
}
if (neg)
@wware
wware / synth.py
Last active August 29, 2015 14:25
import aifc
import math
import sys
filename = sys.argv[1]
F_SAMPLE = 40000
DT = 1. / F_SAMPLE
class Aiff:
@wware
wware / gen_shape.py
Last active August 29, 2015 14:21
Do some linear algebra and generate a 3D shape. Kind of a skewed truncated pyramid.
import doctest
import numpy
import sys
def is_vector(x):
return isinstance(x, numpy.ndarray) and x.shape == (3,)
def normalize(vec):
@wware
wware / Git-Merge-Lore.md
Last active August 29, 2015 14:17
Tricks and tips for "git merge"

Git Merge Lore

I'm working at a place where people prefer merges over rebases. In the past I've been influenced by the pro-rebase school of thought, but if there are relatively few pull requests being merged, you can use --no-ff to maintain pretty good clarity, and merge points become the decision point where a pull request has been included or excluded. With that in mind, I want to look at a few relevant use cases.

@wware
wware / about.py
Last active June 2, 2016 18:30
Yet another attempt to write a useful var_dump for Python
import pprint
import logging
def about(thang):
def shorty(x):
if len(x) > 200:
x = x[:200] + "..."
return x
if isinstance(thang, dict):