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
(use-modules (rnrs)) | |
(define* (string->binary str #:key (base 16) (endiannes 'little)) | |
(let ((n (string->number str base)) | |
(f (case endiannes | |
((big) identity) | |
((little) reverse) | |
(else (error "wrong endiannes" endiannes))))) | |
(let lp ((n n) (result '())) | |
(if (zero? n) |
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
(use-modules (rnrs)) | |
(define* (binary->string bin #:key (base 16) (endiannes 'little)) | |
(let ((bl (bytevector->uint-list bin endiannes 1)) | |
(n (car (assoc-ref '((2 "~b") (8 "~o") (16 "~x")) base)))) | |
(call-with-output-string | |
(lambda (port) | |
(for-each (lambda (i) (format port n i)) bl))))) |
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
#!/usr/bin/python | |
from PIL import Image, ImageDraw | |
import time, os, sys | |
ori, des = sys.argv[1:] | |
im = Image.open(ori) | |
draw = ImageDraw.Draw(im) | |
textPadding = 5 |
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
(use-modules (ice-9 match)) | |
(define (cl str) | |
(define (parser s) | |
(let lp((i 0) (ret '())) | |
(cond | |
((= i (string-length s)) | |
(map (lambda (x) | |
(if (char? x) (string->symbol (string x)) x)) | |
(reverse ret))) |
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
#! /usr/bin/env guile | |
!# | |
(use-modules (ice-9 getopt-long)) | |
(setlocale LC_ALL "") | |
(define cur-out (current-output-port)) | |
(define cur-in (current-input-port)) | |
(define option-spec |
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
#! /usr/bin/env python | |
# Be sure you have installed: | |
# easy_install PIL | |
# easy_install PySerial | |
# easy_install gameduino | |
import Image | |
import gameduino.prep as gdprep | |
from sys import argv |
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
(use-modules (srfi srfi-1) (ice-9 receiver)) | |
(define (gen-xfix-list str generator) | |
(let lp((ret '()) (n (1- (string-length str)))) | |
(if (zero? n) ret (lp (cons (generator str n) ret) (1- n))))) | |
(define (gen-prefix-list str) | |
(gen-xfix-list str (lambda (str n) (substring str 0 n)))) | |
(define (gen-suffix-list str) |
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 sets import Set | |
def gen_xfix_set(string, generator): | |
ret,n = Set([]),len(string)-1 | |
while True: | |
if n==0: return ret | |
else: | |
ret.add(generator(string, n)) | |
n -= 1 |
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
(use-modules (system foreign) (rnrs bytevector)) | |
;; TODO: | |
;; 1. (> hi (bytevector-length bv)) | |
;; 2. (< lo 0) wrap reference | |
(define (%bytevector-slice bv lo hi) | |
(and (< hi lo) (error %bytevector-slice "wrong range" lo hi)) | |
(let* ((ptr (bytevector->pointer bv)) | |
(addr (pointer-address ptr)) | |
(la (+ addr lo)) |
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
(define sm '((0 ("A" 1)) (1 ("A" 3) ("B" 2)) (2 (end 2) ("C" 7)) (3 ("B" 4)) | |
(4 ("B" 6) (end 4)) (6 (end 6)) (7 ("C" 8)) (8 ("D" 9)) (9 (end 9)))) | |
(define ll '((2 . "AB") (4 . "AAB") (6 . "AABBB") (9 . "ABCCD"))) | |
(define (my-lexer str) | |
(call-with-input-string | |
str | |
(lambda (port) | |
(let lp((stat 0) (c (read-char port)) (ret '())) | |
(if (eof-object? c) | |
(let* ((now (assoc-ref sm stat)) (w (assoc-ref now 'end))) |