Skip to content

Instantly share code, notes, and snippets.

View twpayne's full-sized avatar

Tom Payne twpayne

  • Zürich, Switzerland
  • 10:33 (UTC +02:00)
View GitHub Profile
@twpayne
twpayne / .slate
Last active August 29, 2015 14:01
# Configs
config defaultToCurrentScreen true
config checkDefaultsOnLoad true
# Position Aliases
alias one move screenOriginX;screenOriginY screenSizeX;screenSizeY
@twpayne
twpayne / xlist.c
Created December 8, 2014 12:10
Doubly-linked list with a single word per node
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
/* on Mac OS X sizeof(int) < sizeof(int *) so make sure we use a large enough integer! */
typedef int64_t integer_t;
typedef struct {
int value;
integer_t nextprev;
@twpayne
twpayne / arduino_assemble.py
Created March 21, 2015 15:19
Rough-and-ready approximation to Arduino's multi-file sketch assembly process
#!/usr/bin/python
import glob
import re
import os
import sys
def assemble_paths(paths):
"""Assemble multiple files together into a main sketch. paths is a list
@twpayne
twpayne / xlist.c
Created September 26, 2010 20:52
Doubly-linked list example using a single pointer per node
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int value;
long nextprev;
} node_t;
/* allocate and initialize a new node */
@twpayne
twpayne / columnparser.py
Created September 27, 2010 13:24
A parser for tables in columns
#!/usr/bin/python
import re
class ColumnParser(object):
def __init__(self, header):
self.columns = {}
index = 0
for m in re.finditer(r' (?=\S)', header):
@twpayne
twpayne / polar.py
Created February 8, 2012 20:51
Speed-to-fly analysis for different glider classes
# Units:
# Distance: metres
# Time: seconds
# All vertical velocities are positive upwards, i.e. climb rates are always
# postive and sink rates are always negative
# To convert km/h into m/s multiply by 3.6
# Notation:
# vx: Horizontal velocity along the course line
# vxmin: Minimum velocity (velocity at minimum sink)
@twpayne
twpayne / hotends.py
Created February 26, 2012 11:34
Weight ranges and availability for hot EN D gliders
import matplotlib.pyplot as plt
SHIPPING = 'S'
AVAILABLE_FOR_ORDER = 'A'
PLANNED = 'P'
PARAGLIDERS = [
('EnZo S', 90, 105, SHIPPING),
('EnZo M', 100, 115, SHIPPING),
@twpayne
twpayne / bw.py
Created October 11, 2012 09:28
Burrows-Wheeler forward and reverse transformations
from bisect import bisect_left
from itertools import izip
def bw(s):
"""Forward Burrows-Wheeler transform"""
rotations = (s[i:] + s[:i] for i in xrange(len(s)))
sorted_rotations = sorted(rotations)
last_column = ''.join(sr[-1] for sr in sorted_rotations)
index = bisect_left(sorted_rotations, s)
@twpayne
twpayne / gist:3924761
Created October 20, 2012 20:51
simplerepr
def simplerepr(obj):
keys = sorted(key for key in obj.__dict__.keys() if not key.startswith('_'))
attrs = ''.join(' %s=%r' % (key, obj.__dict__[key]) for key in keys)
return '<%s%s>' % (obj.__class__.__name__, attrs)
@twpayne
twpayne / awb.py
Created October 25, 2012 14:24 — forked from fredj/awb.py
AWB (Airway bill) number validation
import re
def valid(awb):
m = re.match('\d{3}(?P<serial>\d{7})(?P<check>\d)\Z', awb)
return m and int(m.group('serial')) % 7 == int(m.group('check'))