Skip to content

Instantly share code, notes, and snippets.

@jimr
jimr / ical_print.py
Created May 13, 2013 09:27
Pretty formatting of meeting invites (for use in mutt etc).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# To parse ics attachments in mutt, put this in your ~/.mailcap:
#
# text/calendar; /path/to/ical_print.py; copiousoutput
#
# Otherwise, you can either pass a an .ics file as a parameter, or pipe
# something to it on stdin.
#
@jimr
jimr / gist:5370940
Created April 12, 2013 09:54
Django test suite discovery that works with `python manage.py test` and `django-jenkins`. If you want to put your tests in a folder instead of `tests.py`, you need to define a `suite` in your `models.py` as below.
# put this in your_app/models.py
def suite():
"""Django test discovery."""
import nose
import unittest
path = os.path.join(os.path.dirname(__file__), 'tests')
suite = unittest.TestSuite()
suite.addTests(nose.loader.TestLoader().loadTestsFromDir(path))
return suite
@jimr
jimr / line_diff.py
Last active December 15, 2015 18:19
Python script for finding the first difference between two lines. Useful for (e.g.) diffing minified JS. Usage: git diff -p some/minified/file.js | grep "^[+-]" | tail -n 2 | python diff.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import fileinput
lines = list(fileinput.input())
if len(lines) != 2:
raise Exception("Input must be a pair of lines to diff")