This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun translate(Rect(l1, t1, r1, b1), Rect(l2, t2, r2, b2)) = | |
Rect(abs(l1 - l2), abs(t1 - t2), abs(r1 - r2), abs(b1 - b2)) | |
fun calculateRelativePosition(rt as Rect(l, t, r, b), offset) = | |
let | |
val width = r - l | |
val height = t - b | |
val Rect(x, y, _, _) = translate(rt, offset) | |
val cx1 = Int.toString(width div 2 + x) | |
val cx2 = Int.toString(height + y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* REPRESENTATION CONVENTION: (left, top, right, bottom) | |
REPRESENTATION INVARIANT: left < right andalso bottom < top | |
*) | |
datatype rectangle = Rect of int * int * int * int; | |
(* REPRESENTATION CONVENTION: (extent, horizontal, vertical, | |
topLeft, topRight, bottomLeft, bottomRight) | |
REPRESENTATION INVARIANT: | |
*) | |
datatype quadTree = EmptyQuadTree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun measureTime f = | |
let | |
val t = Timer.startRealTimer () | |
in | |
(f (), Timer.checkRealTimer t) | |
end | |
fun readAll (h, acc) = | |
let | |
val s = TextIO.inputLine h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local | |
fun rmod x y = x - y * Real.realFloor (x / y); | |
val a = 16807.0; | |
val m = 2147483647.0; | |
val random_seed = ref 1.0; | |
in | |
fun random () = | |
let | |
val r = rmod (a * ! random_seed) m | |
in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun orbList l = | |
foldr Word32.orb (Word32.fromInt 0) l | |
fun bin2word x = | |
let | |
fun bin2word' ("", _) = [] | |
| bin2word' (s, i) = | |
let | |
val b = String.sub (s, 0) | |
val v = case b of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local | |
fun rmod x y = x - y * Real.realFloor (x / y); | |
val a = 16807.0; | |
val m = 2147483647.0; | |
val random_seed = ref 1.0; | |
in | |
fun random () = | |
let | |
val r = rmod (a * ! random_seed) m | |
in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun removeElement ([], _) = [] | |
| removeElement (first::rest, x) = | |
if first = x then | |
rest | |
else | |
first::removeElement (rest, x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun superExplode (delimiter, s) = | |
let | |
fun takeUntil (delimiter, []) = [] | |
| takeUntil (delimiter, first::rest) = | |
if first = delimiter then | |
[] | |
else | |
first::(takeUntil (delimiter, rest)) | |
fun superExplode' (delimiter, []) = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
class NoExceptionRaisedError(Exception): | |
pass | |
def exceptional(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import logging | |
from thunderclient import Thunder | |
from evdev import InputDevice, list_devices, ecodes | |
from evdev import categorize | |
logger = logging.getLogger(__name__) | |
def read_codes(device): |
OlderNewer