Skip to content

Instantly share code, notes, and snippets.

View jdunck's full-sized avatar

Jeremy Dunck jdunck

View GitHub Profile
@jdunck
jdunck / force_html_middleware.py
Last active August 29, 2015 14:02 — forked from leetrout/force_html_middleware.py
A hack to wrap API responses in HTML so that django debug toolbar can be used on API requests.
def uncompress_string(c):
from io import BytesIO
from gzip import GzipFile
zbuf = BytesIO(c)
with GzipFile(mode='rb', compresslevel=6, fileobj=zbuf) as zfile:
return zfile.read()
class ForceDebugJSONMiddleware(object):
def process_response(self, request, response):
"""Add html, head, and body tags so debug toolbar will activate."""
@jdunck
jdunck / gist:6100645
Last active December 20, 2015 08:29 — forked from gulnara/gist:6100119
import pprint
def nested_tree(edges):
nested = {}
for from_, to in edges:
value = {}
@jdunck
jdunck / s3_multipart.py
Last active May 15, 2019 13:55 — forked from BradWhittington/s3_multipart.py
upload to s3 with streaming, multi-part, threaded upload, with key rollover as you pass the 4gb limit, with adjustable buffering and pooling. Don't forget to call uploader.close() when you're done.
from multiprocessing.pool import ThreadPool
import logging, os, threading
from StringIO import StringIO
import boto.s3
logger = logging.getLogger('s3upload')
class MultiPartUploader:
upload_part = 0
@jdunck
jdunck / test_cache.py
Created August 24, 2012 07:05 — forked from onyxfish/test_cache.py
Python unittest-based cache testing rig for Varnish + Wordperss
#!/usr/bin/env python
import cookielib
import json
import re
import random
import unittest
import requests
from wordpress_xmlrpc import Client, WordPressComment, WordPressPost
@jdunck
jdunck / prefixed.py
Created June 4, 2010 13:26 — forked from bkonkle/prefixed.py
A namespacing cache backend for django
import types
from django.conf import settings
from urllib import urlencode
from django.core.cache.backends.base import BaseCache
from django.utils.encoding import smart_str
#future-proofing against any Django upstream additions of new cache methods.
# If we didn't do this, we'd silently use the base class's methods, which wouldn't
# use the prefix as required.
_expected_methods = set(['__contains__', '__init__', 'add', 'close',
@jdunck
jdunck / uuid.py
Created May 26, 2009 01:21 — forked from mmalone/uuid.py
import socket
def sockrecv(sock):
d = ''
while not d or d[-1] != '\n':
d += sock.recv(8192)
return d