Skip to content

Instantly share code, notes, and snippets.

View treyhunner's full-sized avatar
🐍
💖

Trey Hunner treyhunner

🐍
💖
View GitHub Profile
@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'
#!/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 / 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
@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 / 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 / findpi
Created December 30, 2012 19:28
Script for finding Raspberry Pi computers on the network. The scripts searches for MAC addresses starting with `b8:27:eb:` (the Ethernet port on the Pi) and `80:1f:02` (Edimax wifi USB dongle).
#!/bin/sh
if which nmap > /dev/null ; then
echo "Running nmap as root\n"
IP_RANGE=$(ip addr | grep "inet " | awk '{ print $2}' | grep -v 127.0.0)
sudo nmap -sP $IP_RANGE | grep -B2 -i 'b8:27:eb\|80:1f:02'
else
if which arp-scan > /dev/null ; then
echo "Running arp-scan as root\n"
sudo arp-scan --interface=eth0 --localnet | grep 'b8:27:eb\|80:1f:02'
else
@treyhunner
treyhunner / nbc
Created October 9, 2012 20:20
Instructions for installing pynxc on Ubuntu for use with Lego Mindstorm robots
This file has been truncated, but you can view the full file.
@treyhunner
treyhunner / Makefile
Created June 25, 2012 07:04
Generic Makefile for Django project
run:
python manage.py runserver_plus || python manage.py runserver
shell:
python manage.py shell_plus || python manage.py shell
@treyhunner
treyhunner / test_path.py
Created April 26, 2012 07:37
Test file for OS path representation
"""File for testing OS path separators in Python
Execute this file like this:
python test_path.py c:/path/to/a/file.txt
"""
import sys
import os
@treyhunner
treyhunner / approach 1: hal with _embedded.json
Created February 18, 2012 02:19
Embedding links in HAL+JSON
{
"queue_status": "running",
"_embedded": {
"jobs": [
{
"_links": {
"self": { "href": "/queue/job1" },
}
"status": "queued"
},