Skip to content

Instantly share code, notes, and snippets.

Neal Todd nealtodd

Block or report user

Report or block nealtodd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nealtodd
nealtodd / uwsgi-init.d
Last active Aug 29, 2015 — forked from mariuz/emperor.sh
uwsgi init.d for Wagtail on Debian
View uwsgi-init.d
#!/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
View reorder_ordereddict_snippet.py
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 / timed_testrunner.py
Created Aug 25, 2015
List the longest running tests in a Django test suite
View timed_testrunner.py
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 / wiible.py
Last active Dec 17, 2015
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…
View wiible.py
import time
import cwiid
class Wiible():
buttons = [
"BTN_2",
"BTN_1",
"BTN_B",
@nealtodd
nealtodd / wiimote.py
Last active Dec 17, 2015
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.
View wiimote.py
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 / wiibot.py
Last active Dec 17, 2015
Subclass of WiimoteConnect for controlling a real Pi-driven Lego-based forklift truck.
View wiibot.py
import piface.pfio as pfio
from wiimote import WiimoteConnect
class WiiBot(WiimoteConnect):
"""
Use Wiimote to control robot
Basic usage:
from wiibot import WiiBot
@nealtodd
nealtodd / minimumrequiredformset.py
Created Jul 2, 2013
Django formset for validating a minimum number of filled out forms.
View minimumrequiredformset.py
from django import forms
class MinimumRequiredFormSet(forms.models.BaseInlineFormSet):
"""
Inline formset that enforces a minimum number of non-deleted forms
that are not empty
"""
default_minimum_forms_message = "At least %s set%s of data is required"
@nealtodd
nealtodd / u2v.py
Last active Dec 23, 2015
Django management command: Take a fully qualified URL and show the resolved view (accounting for decorators on the view).
View u2v.py
from textwrap import dedent
from urlparse import urlparse
from django.core.management.base import BaseCommand
from django.core.urlresolvers import resolve, Resolver404
class Command(BaseCommand):
"""
Take a fully qualified URL and show the resolved view
View gist:6883345

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@nealtodd
nealtodd / package_dev.sh
Last active Jul 6, 2016
Debugging / testing a third party package without hacking the pip installed version
View package_dev.sh
cd somewhere
git clone https://github.com/[OWNER]/[REPO].git --branch [SPECIFIC BRANCH] --single-branch
cd [REPO]
python setup.py develop
# Usually, restart dev server to prevent it using already loaded site-packages modules.
# Hack away on code in [REPO], python will use this one rather than the one in site-packages.
# When done, to switch back:
python setup.py develop --uninstall
cd ..
rm -rf [REPO]
You can’t perform that action at this time.