Skip to content

Instantly share code, notes, and snippets.

View lharding's full-sized avatar

Leander Harding lharding

View GitHub Profile
@lharding
lharding / hexagon.py
Created April 7, 2013 15:42
My wife is crocheting a big hexagonal blanket made of hexagons and needed to know how many tiles she'd need to get a hexagon of a certain size, so I wrote her this little script. It takes one argument, the number of hexagons to a side for the big hex. I let her play with it and she insisted I share the code, so here it is.
import sys
height = int(sys.argv[1])
total = 0
row = 0
for i in range(height):
row = i + height
print " "*(height-i) + "<>"*row
total = total+row
@lharding
lharding / debounceKeys.java
Last active December 15, 2015 00:49
Example Processing code for getting around AWT's terrible key repeat handling on Linux. Takes advantage of the fact that autorepeat keypresses come inhumanly soon after the virtual key release to filter out keyup->keydown pairs that happen too fast. This example is from a project of mine that uses ultimately sends out key events as strings, but …
private static class NonsimultaneousTimeSeries<T> extends TreeMap<Long, T> {
@Override
public T put(Long when, T what) {
//If something already happened on this millisecond, try the next one:
while(containsKey(when)) when++;
return super.put(when, what);
}