Skip to content

Instantly share code, notes, and snippets.

@micktwomey
micktwomey / keybase.md
Created September 30, 2014 08:13
keybase.md

Keybase proof

I hereby claim:

  • I am micktwomey on github.
  • I am micktwomey (https://keybase.io/micktwomey) on keybase.
  • I have a public key whose fingerprint is 1D6D 1310 409E 5801 A5EA DA4B 1714 CC85 82E2 B3E3

To claim this, I am signing this object:

@micktwomey
micktwomey / redis.conf.diff
Created October 25, 2012 15:46
Difference between default redis 2.4 and 2.6 configs
--- /dev/fd/63 2012-10-25 16:46:38.000000000 +0100
+++ /dev/fd/62 2012-10-25 16:46:38.000000000 +0100
@@ -1,6 +1,6 @@
# Redis configuration file example
-# Note on units: when memory size is needed, it is possible to specifiy
+# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
@micktwomey
micktwomey / utf8bmp.py
Created October 16, 2012 11:01
WSGI middleware to replace non-BMP characters in JSON with unknown character. Works around poor UTF-8 support in certain dbs.
"""WSGI middleware and test code to munge utf-8
To work around narrow builds you need to do this:
re.sub(r'\\U[0-9a-f]{8}', '\\ufffd', s.encode("unicode_escape")).decode("unicode_escape")
(Use the representation)
"""
@micktwomey
micktwomey / forgive.py
Created August 9, 2012 11:22
Better to ask for forgiveness...
import contextlib
import functools
@contextlib.contextmanager
def forgiveness(exceptions):
"""Seek forgiveness
"""
try:
yield
@micktwomey
micktwomey / mttpstats.py
Created October 2, 2010 14:32
redis profiling
"""Class for printing reports on profiled python code."""
# Modified by mtt to support loading of stats without creating file objects
# Class for printing reports on profiled python code. rev 1.0 4/1/94
#
# Based on prior profile module by Sjoerd Mullender...
# which was hacked somewhat by: Guido van Rossum
#
# see profile.doc and profile.py for more info.
@micktwomey
micktwomey / data.csv
Created October 2, 2010 14:10
python basics
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
scheme number
scheme1 5.23456
scheme2 563.7655
scheme3 34534.734534
scheme4 34534.76546756
@micktwomey
micktwomey / client.py
Created October 1, 2010 13:03
python multiprocessing socket server example
import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
@micktwomey
micktwomey / uriparse.py
Created September 1, 2010 10:08
Generic URI parsing for python with a ZODB example
"""Generic URI parsing
Intended to be more generally applicable than urlparse.
"""
import cgi
import re
import urllib
@micktwomey
micktwomey / import_tumblr.py
Created March 19, 2010 21:43
Simple script I used to import entries from my old blog to tumblr
"""My old blog -> tumblr importer
"""
import csv
from getpass import getpass
import json
import logging
import sys
import urllib
from pkg_resources import resource_filename
(r"^media/(?P<path>.*)$", 'django.views.static.serve', {'document_root': resource_filename('django.contrib.admin', 'media')}),