Instantly share code, notes, and snippets.

View caching.py
from functools import wraps
def cache(fn):
cache_dict = {}
@wraps(fn)
def result(*args, **kwargs):
# can't cache kwargs
assert not kwargs
if args not in cache_dict:
cache_dict[args] = fn(*args)
View keybase.md

Keybase proof

I hereby claim:

  • I am trmanderson on github.
  • I am trm (https://keybase.io/trm) on keybase.
  • I have a public key whose fingerprint is 2EF6 0F25 F529 D0CE FD37 1095 E056 0B6E A3AB FDFD

To claim this, I am signing this object:

View log_exc.py
import logger
from functools import wraps
def log_exc(fn=None, reraise=None, msg=None, exc=None, logger=None):
"""
Decorator to log exceptions in a function.
Usage:
@log_exc
View .gitignore
__pycache__/
*.py[cod]
*$py.class
pip-log.txt
pip-delete-this-directory.txt
.venv
View index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#viewer").load("/viewer.html");
console.log("Done");
});
</script>
View rec_dl.py
import mechanize, os, errno
from urlparse import urldefrag
from time import sleep
def recursive_download(root, page, browser=mechanize.Browser(), visited=set()):
if page in visited or not page.startswith(root):
return
else:
visited.add(page)
View oil_blending.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Farmer Jones (integer).ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Makefile
# Name: Makefile
# Author: Tom Manderson
# Based on https://github.com/obdev/CrossPack-AVR/
DEVICE = atmega324a
CLOCK = 8000000
PROGRAMMER = -c avrispmkii
OBJECTS = project.o buttons.o game.o ledmatrix.o score.o scrolling_char_display.o serialio.o spi.o terminalio.o timer0.o
AVRDUDE = avrdude $(PROGRAMMER) -p m324pa -F
COMPILE = avr-gcc -Wall -Os -std=c99 -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
View check_gh.py
from __future__ import print_function
import requests
import os
import time
if os.name == "posix":
def sound():
os.system("play --no-show-progress --null --channels 1 synth 5 sin 440")
else: