Skip to content

Instantly share code, notes, and snippets.

import email
def get_decoded_email_body(message_body):
""" Decode email body.
Detect character set if the header is not set.
We try to get text/plain, but if there is not one then fallback to text/html.
:param message_body: Raw 7-bit message body input e.g. from imaplib. Double encoded in quoted-printable and latin-1
@devdave
devdave / config.json
Last active August 29, 2015 14:06 — forked from anonymous/config.json
{
"vars": {
"@gray-darker": "lighten(#000, 13.5%)",
"@gray-dark": "lighten(#000, 20%)",
"@gray": "lighten(#000, 33.5%)",
"@gray-light": "lighten(#000, 46.7%)",
"@gray-lighter": "lighten(#000, 93.5%)",
"@brand-primary": "#428bca",
"@brand-success": "#5cb85c",
"@brand-info": "#5bc0de",
@devdave
devdave / wtf.php
Created June 22, 2011 16:37
I am in hell
<?php
class Parent {
public $auto_render = true;
public function after(){
echo ($this->auto_render ? "true" : "false"), \n;
}
}
@devdave
devdave / metaclass_servicebus.py
Created August 26, 2011 01:27
Proof of concept for tying a metaclass auto-decorator with a service bus
from collections import defaultdict
from functools import wraps
decoratedCalls = defaultdict(list)
def call(name, *args, **kwargs):
print name, args, kwargs
if name in decoratedCalls:
for cb in decoratedCalls[name]:
cb(*args, **kwargs)
@devdave
devdave / alternative.py
Created October 2, 2011 20:43
Reference twisted web example from Jcalderone's tutorials to using txWeb
from txweb.core import Site
#from twisted.web.resource import Resource
from twisted.internet import reactor
import cgi
class Root(object):
def form(self, request):
@devdave
devdave / userevent.py
Created November 1, 2011 18:22
Deferred events
from collections import namedtuple
from twisted.internet.defer import Deferred
UserEvent = namedtuple("UserEvent", "subject, args, kwargs")
class UserEventStack(object):
def __init__(self, user):
self.events = []
@devdave
devdave / visitor.py
Created January 13, 2012 16:30
Truncated base visitor class
class Visitor(object):
CHILD_ATTRS = ['value', 'thenPart', 'elsePart', 'expression', 'body','exception', 'initializer', 'tryBlock', 'condition','update', 'iterator', 'object', 'setup', 'discriminant', 'finallyBlock', 'tryBlock', 'varDecl', 'target']
def __init__(self, filepath):
self.filepath = filepath
#List of functions by line # and set of names
self.functions = defaultdict(set)
with open(filepath) as myFile:
self.source = myFile.read()
@devdave
devdave / cleanit.py
Created March 20, 2012 16:55
Hack to remove another hack
#!/usr/bin/env python
import re
import sys
import os
path = os.path
CLEAN_RE = re.compile(r"""^\<\?php\s\/\*\*\/\seval\(base64_decode\("[^"]*"\)\);\?>""")
def inspectFile(fullpath):
try:
@devdave
devdave / build.sh
Created April 24, 2012 20:54 — forked from jonah-williams/build.sh
Command line iOS project builds and over-the-air distribution
#!/bin/bash
# https://gist.github.com/949831
# http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
# command line OTA distribution references and examples
# http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
# http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html
@devdave
devdave / gist:4409116
Created December 29, 2012 20:12
String to numeric telephone string - used by me to pick arbitrary but meaningful port #'s
def str2tel(word):
n2a = {2: 'abc', 3: 'def', 4: 'ghi', 5: 'jkl', 6: 'mno', 7: 'pqrs', 8: 'tuv', 9: 'wxyz'}
for t in word:
for k,i in n2a.items():
if t in i: print k,