Skip to content

Instantly share code, notes, and snippets.

View foxx's full-sized avatar

Cal Leeming foxx

View GitHub Profile
Dear Zendesk,
On behalf of the internet, and for the greater good of mankind, this is a request to
politely ask you to change the default theme of your support emails.
Currently every support email notification, for the majority of your customers,
includes a complete dump of the entire conversation. And due to the way you
have constructed the HTML in your email, most email clients fail to realise
it is duplicated text and do not remove it.
def get_video_info(path):
"""Uses ffmpeg to determine information about a video. This has not been broadly
tested and your milage may vary"""
from decimal import Decimal
import subprocess
import re
process = subprocess.Popen(['/usr/bin/ffmpeg', '-i', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = process.communicate()
class dict_as_class(dict):
"""Proper replacement for UserDict
Allows a dictionary to be used like a class. Really messy, thrown
together in a few minutes as a quick replacement, will probably
tidy this up later"""
def __setattr__(self, k, v):
if k in self.keys():
# default sub orders before first sub end
with patch_today(2013, 1, 1, 1, 1, 1) as pt:
i = UserSubscription.objects.create_orders()
self.assertEquals(len(i['orders_created']), 0)
# default sub orders after first sub end
with patch_today(2013, 1, 6, 1, 1, 1) as pt:
# create
i = UserSubscription.objects.create_orders()
self.assertEquals(len(i['orders_created']), 2)
def extend_instance(instance, *bases, **kwargs):
"""
Apply subclass (mixin) to a class object or its instance
By default, the mixin is placed at the start of bases
to ensure its called first as per MRO. If you wish to
have it injected last, which is useful for monkeypatching,
then you can specify 'last=True'. See here:
http://stackoverflow.com/a/10018792/1267398
@foxx
foxx / blogsnippets.js
Last active January 15, 2016 13:37
blog
for k in ['host', 'port', 'database', 'user', 'password']:
if k in dbconfig:
if type(dbconfig[k]) in (str, unicode):
match = pat.match(dbconfig[k])
if match and match.groups():
envvar = match.groups()[0]
if envvar in os.environ:
dbconfig[k] = os.environ[envvar]
if k != 'password':
def extend_instance(instance, *bases, **kwargs):
"""
Apply subclass (mixin) to a class object or its instance
By default, the mixin is placed at the start of bases
to ensure its called first as per MRO. If you wish to
have it injected last, which is useful for monkeypatching,
then you can specify 'last=True'. See here:
http://stackoverflow.com/a/10018792/1267398
:attr cls: Target object
#!/usr/bin/env python
"""
Embed files into C arrays
Hacky solution because xxd didn't have enough features
"""
from __future__ import with_statement
from __future__ import print_function
@foxx
foxx / gist:1968fe19f759e608452a
Created November 27, 2014 00:10
Django partial forms mixin (alpha as fuck)
class FormFieldQuerySetMixin(object):
"""
Adds support for changing RelatedField queryset
easily without having to patch __init__.
def get_FIELDNAME_queryset(self):
pass
"""
@foxx
foxx / sanity.py
Created December 4, 2015 21:59
Coderpad pytest support
import os
import sys
import subprocess
def sanitypatch():
"""
Quick hack to install any package we want in coderpad...
Because real coders use pytest, amirite?
"""
print("applying coderpad sanity patch...")