Skip to content

Instantly share code, notes, and snippets.

View litchfield's full-sized avatar

Simon Litchfield litchfield

View GitHub Profile
@litchfield
litchfield / doubledecode.py
Created October 12, 2011 21:53
Double decode utf8 and cp1252
#!/usr/bin/env python
"""
Ever had a mysqldump of utf8 data stored in latin1 tables, dumped in utf8 and
munged with windows cp1252?
If so this is your friend. Just pipe it through this little baby and spare
yourself hours of unicode hell- it'll take your dirt and spit out clean utf8.
You can also import it and use it in your python code.
@litchfield
litchfield / duration.py
Created April 24, 2012 04:53
Django DurationField
from django import forms
from django.db import models
def split_duration(value):
if value:
return ( '%02d' % (value // 3600),
'%02d' % ((value % 3600) // 60),
'%02d' % (value % 60),
)
return ('00', '00', '00')
@litchfield
litchfield / add_error.py
Created May 5, 2014 06:29
Django Forms add_error() backport for <1.7
from django import forms
from django.forms.forms import NON_FIELD_ERRORS
class AddErrorMixin(object):
"Backport add_error() for django <1.7"
def add_error(self, field, msg):
field = field or NON_FIELD_ERRORS
if field in self._errors:
self._errors[field].append(msg)
else:
@litchfield
litchfield / grouper.html
Created April 16, 2015 04:41
Javascript grouping example
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
// FUNCTION
function group(data, groupby) {
var grouped = {}
export EDITOR='nano'
export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/python:$PATH"
export HISTSIZE=10000
export HISTFILESIZE=10000
#export PROMPT_COMMAND='echo -ne "\033]0;`hostname -s`\007"'
export LSCOLORS=gxfxcxdxbxegedabagacad
export PIP_DOWNLOAD_CACHE=$HOME/Library/Caches/pip-downloads
alias ls='ls -aGp'
alias ll='ls -la'
@litchfield
litchfield / gist:bd66ad8cf4586674abe5
Created May 18, 2015 00:29
Sample sublime project conf
{
"folders":
[
{
"path": "site",
"folder_exclude_patterns": [
"node_modules",
".sass-cache",
".tmp",
"dist"