Skip to content

Instantly share code, notes, and snippets.

View TRManderson's full-sized avatar

Taylor Manderson TRManderson

View GitHub Profile
@TRManderson
TRManderson / Makefile
Created February 20, 2016 09:52
My AVR makefile for a uni course last year
# 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)
@TRManderson
TRManderson / caching.py
Last active August 22, 2017 01:56
Cache decorator and cached property decorator
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)
@TRManderson
TRManderson / keybase.md
Created July 1, 2017 02:21
Verifying myself on Keybase

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:

@TRManderson
TRManderson / log_exc.py
Created May 26, 2017 13:33
Handy decorator for exception logging using `logging`
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
@TRManderson
TRManderson / .gitignore
Last active February 8, 2017 00:37
Testing the new metaclass support for mypy in Py2
__pycache__/
*.py[cod]
*$py.class
pip-log.txt
pip-delete-this-directory.txt
.venv
@TRManderson
TRManderson / index.html
Last active October 5, 2016 02:27
Example jquery.load
<!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>
@TRManderson
TRManderson / rec_dl.py
Created May 19, 2016 01:36
Recursively download everything from a start page, so long as it starts with a given root url
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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@TRManderson
TRManderson / check_gh.py
Last active January 28, 2016 02:50
Repeatedly hit the Github status API to see if it's down or not (py2/3 compatible and cross-platform)
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: