This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Requires pyshp: https://pypi.python.org/pypi/pyshp | |
# | |
import os | |
import shapefile | |
import shutil | |
import tempfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import itertools | |
import re | |
import sys | |
from datetime import datetime as dt | |
pattern = re.compile(r'.* \[([^]]*) \+[0-9]+\] .*') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fake_request(method=None, fake_user=False): | |
'''Returns a fake `WSGIRequest` object that can be passed to viewss. | |
If `fake_user` is `True`, we attach a random staff member to the request. | |
Even if not set, you can still do this manually by setting the `user` | |
attribute on the returned object. | |
The `GET` and `POST` `QueryDict` objects are mutable:: | |
req = fake_request(mutable=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import sys | |
import urllib2 | |
import xml.etree.ElementTree as ET | |
url = "https://nextbike.net/maps/nextbike-live.xml" | |
stations = sys.argv[1:] | |
xml = urllib2.urlopen(url).read() | |
root = ET.fromstring(xml) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_point(point): | |
# junk | |
point = point.strip() | |
junk = [u'\ufeff', ' ', u'\xa0', u'\u2013'] # [, , , –] | |
for symbol in junk: | |
point = point.replace(symbol, '') | |
point = point.lstrip('+') | |
point = point.lstrip("'") # leading quote chars to fool excel | |
point = point.lstrip(',') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
pattern = re.compile( | |
r'(mailto:)?(?P<email>[^(\s|<|\[))]*@[^\s]*\.[^(\s|>|;|,|\])]*)' | |
) | |
test_data = ''' | |
This is [email protected] string with some Email Addresses | |
<[email protected]> in it. There are also | |
some mailto:[email protected] addresses in here too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import flickr | |
flickr.API_KEY = '<your API key>' | |
flickr.API_SECRET = '<your API secret>' | |
# get some photos | |
photos = flickr.photos_search(tags='manhattan', page='1', per_page='10') |
OlderNewer