Skip to content

Instantly share code, notes, and snippets.

@nealtodd
nealtodd / wiibot.py
Last active December 17, 2015 23:49
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
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 / deletable_objects_snippet.py
Last active August 10, 2020 06:49
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
nealtodd / decorator.py
Created April 25, 2012 13:15
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