kwantam.github.io

Snippets

or, my irregularly updated code blog

2011 June 17
A quine in Scheme derived via the applicative-order Y-combinator:
    ((eval '(lambda (x) (pp `((eval '(lambda (x) (pp ,x))) ',x))))
           '`((eval '(lambda (x) (pp ,x))) ',x))
2013 March 10
A meditation on efficiently detecting illegal states in twisted-ring FSM state vectors. Literate Haskell is a beautiful thing.
2013 April 21
Uncurrying functions for mad(wo)men, or, an entertaining line of thought about something almost entirely pointless.
2013 May 2
BeagleBoard Black Notes, Part 1 — some notes I wrote while playing with my new BeagleBoard Black for the first time. Debian Wheezy installation ; setting up the USB gadgets ; installing a few useful packages.
2013 May 4
BeagleBoard Black Notes, Part 2 — USB network bridging; working with the PRUSS; updating the eMMC's Ångstrom image from Debian.
2014 June 23
Cross Bootstrapping Rust — The Rust build system doesn't presently support bootstrapping a compiler to a different architecture, but with a few modifications we can get it there. This is useful if you're building for a slow device, or for one that doesn't yet have an official stage0 image.

Projects

eccons

eccons is a toolkit for constructing elliptic curves. Its focus is on constructing Weierstrass and Edwards curves having specified order (or, for Edwards curves, specified subgroup order) via complex multiplication.

addchain

addchain implements several methods from the literature for computing short addition chains. You should also see Mike McLoughlin's addchain library, which often gives better results.

conec

conec (COordinated NEtwork Channels) is a Rust library that provides a high-level networking abstraction: it lets clients communicate with one another using arbitrary names rather than network addresses, handles NAT traversal, and provides a number of other nice features.

fffft

fffft is a parallel FFT implementation for Rust.

lviv

lviv is a hybrid functional/stack programming language. Here's some example code:

; qsort.lviv
; quicksort implemented in lviv

; filter2
; given a predicate in slot 0 and a list in slot 1
; filter the list into two lists, one for which the
; predicate is true and one for which it is false
( (*tList *fList) ; if the list is null, return the true and false lists
  (*lList uncons (*tList cons *fList) ; otherwise, take the first element, cons it to tlist
                 (*fList cons *tList swap) ; or flist as appropriate
                 3 pick *pred apply if ; (test whether to cons to tList or fList)
   3 roll ***pred eval *filt2Hlp) ; then get the stack back in order and call again
  *lList null? if ) ; (test whether list is null)
(*tList *fList *lList *pred) lambda *filt2Hlp define

( () () *lList **pred eval *filt2Hlp ) ; call the helper function with empty tList and fList
(*lList *pred) lambda *filt2 define

; qsort: use the first element of the list as the pivot
; filter the list and qsort the resulting lists
( (*lList) ; if it's 0 or 1 elm long, just return it
  (*lList uncons dup 3 unroll ; otherwise, get the next pivot, save off the pivot
   (***n <) cons (***n) lambda filt2    ; filter the list into greater and lesser lists
   *qsort swap                          ; sort the first part
   *qsort 3 roll :cons                  ; sort the second part, then replace the pivot
   append                               ; append them, and we are sorted
  )
  (#t) (*lList cdr null?) *lList null? if if )
(*lList) lambda *qsort define

TriHs

A Tetris clone in Haskell using Cairo and Gtk2Hs. In 2-player mode, you can screw with your opponent by switching their next piece for a random one.

TriHs

BC

A ballistic calculator for Maemo5 using the GNU Ballistics Library.

synthres

Generate a series-parallel network of unit-sized resistors that synthesize an arbitrary resistance value.

8.7k resistor

Now there are two versions of this code: the original one in Perl, and a new implementation in Haskell that can search for a more optimal implementation and render the result as an SVG, like so:

8.7k resistor, optimized

See README.md for more info.

resgrad

Generate optimal 2d resistor pack layout for N:1/N ratioed resistors in the presence of linear gradients in X and Y.

resistor pack optimized for gradient minimization

multiexp-a5gx

An FPGA-based PCIe accelerator for batched modular multiexponentiation.

sousvide628

Simple code to use a PIC16F628a to control a heater and pump for Sous-vide.

hset

The game of Set. Includes a rudimentary CGI interface.

batsM3u

A minimal audio player for Android. Primarily for playing m3u files that include http URLs.

batsPass

A simple password manager application for Android.

batsHIIT

A simple, usable HIIT workout timer.

Weston Voltmeter Clock

What else would you do with a 120 V meter?

NIXIE-1

A simple, single-digit NIXIE clock.

2nix

If one NIXIE is good, two must be better!

vclk

An electrostatic CRT vector display clock. High voltages within!

inGrid

An IV-18 vacuum fluorescent display clock. This design inspired LadyAda's Ice Tube kit.

Pocket Ignignokt

Come for the humor, stay for the delightful 555-based power converter.

Heaviside headphone amplifier

Quick writeup of a vacuum tube–based headphone amplfier with op-amp sensibilities.

Gilberd headphone amplifier

A solid-state headphone amplifier with a fun "unfolded diff pair" input and a DC servo.

Questions? Comments?
@kwantam | <kwantam@gmail.com> | github