Skip to content

Instantly share code, notes, and snippets.

try:
from collections import OrderedDict
except ImportError:
OrderedDict = None
from UserDict import UserDict
if OrderedDict is not None:
class Cache(OrderedDict):
def flush(self):
@andialbrecht
andialbrecht / python-flake8.el
Created September 26, 2011 08:09
Thin wrapper around python-pylint to run flake8
;;; python-flake8.el --- Thin wrapper around python-pylint to run flake8
;; Copyright (C) 2011 Andi Albrecht
;; Author: Andi Albrecht <albrecht.andi@gmail.com>
;; Keywords: languages
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
@andialbrecht
andialbrecht / git-branch-io
Created May 31, 2011 08:06
git command to summarize incoming and outgoing changes on local branches
#!/usr/bin/env python2
# git-branch-io -- show incoming and outgoing commits
#
# Place this file somewhere in your PATH.
#
# Usage: git branch-io [branch]
#
# If branch is not given the current branch will be used. The script
# prints out how many commits should go in either direction to bring
@andialbrecht
andialbrecht / closure-gjslint.el
Created May 16, 2011 09:58
Emacs mode for running gjslint from Closure library
;;; closure-gjslint.el --- Closure Lint mode
;; Copyright (C) 2011 Andi Albrecht
;; Author: Andi Albrecht <albrecht.andi@gmail.com>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
@andialbrecht
andialbrecht / gist:917126
Created April 13, 2011 07:26
Regex to parse pylint output
# Regex to extract error messages from "pylint -f parseable" output
import re
P_PYLINT_ERROR = re.compile(r"""
^(?P<file>.+?):(?P<line>[0-9]+):\ # file name and line number
\[(?P<type>[a-z])(?P<errno>\d+) # message type and error number, e.g. E0101
(,\ (?P<hint>.+))?\]\ # optional class or function name
(?P<msg>.*) # finally, the error message
""", re.IGNORECASE|re.VERBOSE)
@andialbrecht
andialbrecht / models.py
Created March 11, 2011 12:03
Adds Meta option db_column_prefix that prepends a per-model prefix to db column names
# -*- coding: utf-8 -*-
# This hack adds a new Meta option "db_column_prefix". If not None all
# database columns in a model will be prepended with this prefix (the
# database columns, not the attributes). See Person model for an
# example.
#
# Issues:
# - How to set a prefix for a m2m table? - If "through" argument is
# not specified on a M2MField, Django automatically adds a model