Skip to content

Instantly share code, notes, and snippets.

@nealtodd
nealtodd / wiimote.py
Last active December 17, 2015 19:19
Base class for detecting Wiimote button presses and triggering actions via methods. Written so that a subclass can be used to control a Raspberry Pi based robot.
import time
import cwiid
import threading
class WiimoteBase(object):
"""
Base class for sending Wiimote button presses to class
methods. Subclass to implement actions in the methods.
@nealtodd
nealtodd / wiible.py
Last active December 17, 2015 09:29
Test of connecting Wiimotes to a Raspberry Pi via Bluetooth. Reports button presses from a Wiimote. Couched in a trivial little game for two kids to 'remote control' each other: The sender can use the crosspad to light the leds on the receiver. The receiver walks in the direction indicated on the leds (led1 = turn left, led2 = forwards, led3=bac…
import time
import cwiid
class Wiible():
buttons = [
"BTN_2",
"BTN_1",
"BTN_B",
@nealtodd
nealtodd / timed_testrunner.py
Created August 25, 2015 15:46
List the longest running tests in a Django test suite
import time
from collections import defaultdict, OrderedDict
from junorunner.testrunner import TestSuiteRunner
from junorunner.extended_runner import TextTestRunner, TextTestResult
class TimedTestSuiteRunner(TestSuiteRunner):
"""
List the longest running tests in a suite
@nealtodd
nealtodd / reorder_ordereddict_snippet.py
Last active August 29, 2015 14:06
Reorder OrderedDict
def reorder_ordereddict(ordered_dict, key_order):
"""
Return a new OrderedDict using a source ordered_dict and key_order iterable.
Any keys in ordered_dict that are not in key_order will be added
in their original order to the end of the returned OrderedDict.
KeyError will be raised for keys in key_order that are not in ordered_dict.
Intended for specifiying the order of Form.fields without having to create
them in the required order.
@nealtodd
nealtodd / uwsgi-init.d
Last active August 29, 2015 13:57 — forked from mariuz/emperor.sh
uwsgi init.d for Wagtail on Debian
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: emperor
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: uwsgi for wagtail
# Description: uwsgi for wagtail