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 /
Created Apr 25, 2012
Python profiling decorator
from cProfile import Profile
import pstats
def profile(sort_args=['cumulative'], print_args=[10]):
profiler = Profile()
def decorator(fn):
def inner(*args, **kwargs):
result = None
nealtodd /
Last active Nov 20, 2018
Django helper for showing related objects that would be cascade deleted on deletion of an object.
from django.conf import settings
from django.db.models.deletion import Collector
from django.db.utils import ConnectionRouter
def deletable_objects(obj):
Return a generator that yields (model, instance) tuples
of instances related to obj (including obj itself).
Essentially, programmatic access to the data Django Admin
nealtodd /
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…
import time
import cwiid
class Wiible():
buttons = [
nealtodd /
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.
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 /
Last active Dec 17, 2015
Subclass of WiimoteConnect for controlling a real Pi-driven Lego-based forklift truck.
import piface.pfio as pfio
from wiimote import WiimoteConnect
class WiiBot(WiimoteConnect):
Use Wiimote to control robot
Basic usage:
from wiibot import WiiBot
nealtodd /
Created Jul 2, 2013
Django formset for validating a minimum number of filled out forms.
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 /
Last active Dec 23, 2015
Django management command: Take a fully qualified URL and show the resolved view (accounting for decorators on the view).
from textwrap import dedent
from urlparse import urlparse
from 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.


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 / uwsgi-init.d
Last active Aug 29, 2015 — forked from mariuz/
uwsgi init.d for Wagtail on Debian
View uwsgi-init.d
#!/usr/bin/env bash
# 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
nealtodd /
Last active Oct 26, 2016
Skip migrations for a Django 1.7 test run
# If your test settings file doesn't import any other settings file
# then you can use the function directly:
def prevent_tests_migrate(db):
import django
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
ma = MigrationExecutor(connections[db]).loader.migrated_apps
return dict(zip(ma, ['{a}.notmigrations'.format(a=a) for a in ma]))
You can’t perform that action at this time.