Skip to content

Instantly share code, notes, and snippets.

View gilesbrown's full-sized avatar

Giles Brown gilesbrown

  • San Francisco
View GitHub Profile
@gilesbrown
gilesbrown / ttyorjsonstreamhandler.py
Created May 10, 2019 19:25
Switch between formatted or structured logging based on isattry()
import logging
import json
import types
from traceback import format_tb
from simplegeneric import generic
@generic
def encode_log_record(obj):
return repr(obj)
@gilesbrown
gilesbrown / Console
Created February 12, 2017 18:09
Mismatch in ids
$ python compare.py customers.csv orders.csv
1711 out of 7067 order customer ids are missing
import requests
import logging
logging.basicConfig()
def gen():
yield "this"
yield "that"
requests.put('http://httpbin.org/put', data=gen())
@gilesbrown
gilesbrown / gist:760a341a857438c96115
Created November 6, 2014 05:26
Tarfile streaming with gevent
(reconf)LM-sjn-00874409:reconf gsbrown$ vi setup.py │
(reconf)LM-sjn-00874409:reconf gsbrown$ │
import os
import tarfile
import time
from io import BytesIO
def copyfileobj(fsrc, fdst, length=16*1024):
size = 0L