Skip to content

Instantly share code, notes, and snippets.

@bmander
bmander / code.py
Last active November 21, 2023 18:34
CircuitPython code for volume knob
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
import time
import usb_hid
class Button:
"""Debounced button handler. The user can assign a callback function
to be called when the button is pressed and/or released."""
@bmander
bmander / rainbow.py
Created March 13, 2019 22:53
A handy command-line utility for converting transaction POS files into machine-readable JSON files
import re
import json
def pos_float(s):
if s[-1]=="-":
return -float(s[:-1])
else:
return float(s)
def parse_entry(entry):
@bmander
bmander / knn.ipynb
Created November 21, 2018 02:03
using KNN to find calibratred curves
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
date energy
2014-01-01 0.9374433333333336
2014-01-02 0.2131616666666668
2014-01-03 1.3784516666666657
2014-01-04 1.5620366666666663
2014-01-05 1.6286066666666656
2014-01-06 0.730888333333333
2014-01-07 0.33522999999999975
2014-01-08 0.27334499999999995
2014-01-09 0.3330000000000002
@bmander
bmander / graph.py
Created June 21, 2018 21:46
minimal graph and shortest path tree implementation
import heapq
import itertools
from sys import maxsize
INFINITY = maxsize
class PriorityQueue(object):
def __init__(self):
self.pq = [] # list of entries arranged in a heap
state_fips other_roads rural_arterial urban_arterial year month
9 2267 138 1656 2004 1
23 1115 461 233 2004 1
25 4239 465 2844 2004 1
33 964 360 340 2004 1
34 5011 634 3160 2004 1
36 9706 1279 5413 2004 1
42 7073 1930 3223 2004 1
44 417 32 332 2004 1
50 582 231 96 2004 1
@bmander
bmander / no.chords
Last active November 24, 2016 04:24
The Magnetic Fields, "No"
intro
Am G F C
C F C
Is there a man in heaven looking out for you
C G
Is there a place dead loved ones go?
C F C
Is there a source of wisdom that will see you through?
@bmander
bmander / pendulumcart.ipynb
Created November 7, 2016 22:22
Deriving inverted pendulum equations of motion two different ways
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmander
bmander / invpendulum.ipynb
Last active March 26, 2016 17:55
A minimal inverted pendulum simulation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.