Skip to content

Instantly share code, notes, and snippets.

View treyhunner's full-sized avatar

Trey Hunner treyhunner

View GitHub Profile
@treyhunner
treyhunner / ecosystem.rst
Last active July 10, 2020 16:23
Compilation of useful Django-related packages and other resources

Django Ecosystem

Where do I go to get help?

I want to know how to make static files show up when developing locally.

  1. Think of some search terms that might describe what you're looking for. Let's go with django static files runserver
@treyhunner
treyhunner / problem.py
Created February 20, 2013 22:24
Programming interview practice of the week (Feb. 20, 2013)
"""
Programming interview practice of the week (2013-02-20)
Problem of the week - Singletons considered okay
1. Write a simple singleton class in your favorite programming language with an example usage.
2. Solve the Sorted array binary search problem:
Given a sorted array of integers array and an integer key, return the index of the first instance of key in the array. If key is not present in array, you should return -1.
@treyhunner
treyhunner / world_ends.txt
Created March 21, 2013 19:09
January 18, 2038
>>> from time import mktime
>>> from datetime import datetime
>>> mktime(datetime(2038, 1, 18, 19, 14, 30).timetuple())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
#!/usr/bin/env python
from unittest import TestCase, main
from turn_picker import score
class TurnPickerTest(TestCase):
def test_score_low_vs_high_attendance(self):
self.assertGreater(score(2, 10, 0), score(50, 200, 12))
@treyhunner
treyhunner / django-simple-history failed tests.out
Created April 21, 2013 21:08
Tests using django-webtest pass on Django 1.3, Django 1.4, and Django 1.5 but fail on Django trunk.
$ python setup.py test
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'mantainer'
warnings.warn(msg)
running test
running egg_info
writing django_simple_history.egg-info/PKG-INFO
writing top-level names to django_simple_history.egg-info/top_level.txt
writing dependency_links to django_simple_history.egg-info/dependency_links.txt
reading manifest file 'django_simple_history.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
@treyhunner
treyhunner / datetime_modulo.py
Last active May 20, 2020 01:47
Python modulo support for datetime
import datetime as dt
class datetime(dt.datetime):
def __divmod__(self, delta):
seconds = int((self - dt.datetime.min).total_seconds())
remainder = dt.timedelta(
seconds=seconds % delta.total_seconds(),
microseconds=self.microsecond,
)
@treyhunner
treyhunner / example.py
Last active December 24, 2015 02:59
Using single-dispatch generic functions (PEP 443) to implement an extensible JSON encoder To use with Python 2.6 to 3.3, install singledispatch from PyPI.
from decimal import Decimal
from json_singledispatch import encode
@encode.register(set)
def encode_set(obj):
return encode(list(obj))
@treyhunner
treyhunner / findccmusic.py
Created May 13, 2014 17:38
Find Creative Commons Music
#!/usr/bin/env python
"""
Find Creative Commons Music
Provide names of musical artists and the script returns any relevant URLs for
FreeMusicArchive.org, Jamendo.com, and Magnatune.com.
Usage::
$ ./findccmusic.py <artist name>...
@treyhunner
treyhunner / find_audiobooks.py
Last active August 29, 2015 14:01
Search for DRM-free audiobooks
#!/usr/bin/env python
"""
Search downpour.com and emusic.com for DRM-free audiobooks
Usage::
./find_audiobooks.py <title>...
File released to the public domain under CC0 license:
http://creativecommons.org/publicdomain/zero/1.0/deed
@treyhunner
treyhunner / some_file.js
Created May 24, 2014 17:58
Example of indentation correction problems
var some_variable = some_function(an_argument,
another_argument);
var soome_variable = some_function(
an_argument,
another_argument
);