Skip to content

Instantly share code, notes, and snippets.

View joeltg's full-sized avatar

Joel Gustafson joeltg

View GitHub Profile
@joeltg
joeltg / makefile
Last active March 3, 2019 19:47
ZeroMQ MIT Scheme bindings
AUXDIR=/usr/local/lib/mit-scheme-x86-64
all: build
install:
install -m 644 zmq-types.bin $(AUXDIR)
install -m 644 zmq-const.scm $(AUXDIR)
install -m 644 zmq-shim.so $(AUXDIR)
clean:
@joeltg
joeltg / automaton.py
Created February 20, 2017 22:45
automaton
from functools import reduce
from operator import getitem
def bst(n, i):
if n % 2 == 0:
h = 2 ** (n / 2)
remainder, quotient = i % h, i // h
return bst(n / 2, remainder), bst(n / 2, quotient)
else:
return i
@joeltg
joeltg / automata.scm
Created February 21, 2017 06:52
automaton.scm
;;;; automatom.scm
;; rules are binary trees of booleans
;; colors: black = #t and left
;; white = #f and right
;; layers: left = 0
;; top = 1
;; right = 2
@joeltg
joeltg / json-parser.scm
Last active December 28, 2022 06:42
MIT Scheme JSON parser
(load-option '*parser)
(define (json-vector-list v)
(vector (vector->list v)))
(define json-object-pair
(*parser
(transform
(lambda (v)
(vector (cons (string->symbol (vector-ref v 0)) (vector-ref v 1))))
@joeltg
joeltg / attachGist.js
Created June 5, 2017 06:43
Dynamically embed a GitHub Gist with shadow roots and black magic
// GitHub expects us to embed Gists by including a script like this:
// <script src="https://gist.github.com/hash.js"></script>
// But this only works if included at parse timue because the script uses
// document.write() so it can't be dynamically inserted afterwards.
// Google recomments creating an iframe and using contentDocument.writeln()
// with skeleton html that loads the script and writes to the iframe document,
// but then if we ever move the element (or clone it for ghosting) the iframe
// will reload.
// SO instead, we make a shadow root, attach an invisible iframe to the
// shadow root that loads the GitHub embed script for ths gist, and then
@joeltg
joeltg / circular-list.scm
Created September 24, 2017 19:04
Circular list utilities for MIT Scheme
(define (make-initialized-circular-list k procedure)
(let ((circle (make-initialized-list k procedure)))
(set-cdr! (last-pair circle) circle)
circle))
(define (circular-list-length circle)
(if (null? circle)
0
(let iter ((c (cdr circle)) (i 1))
(if (eq? c circle)
@joeltg
joeltg / secrets.c
Created December 18, 2017 06:13
Secrets
#include <avr/io.h>
#include <util/delay.h>
#define output(directions,pin) (directions |= pin)
#define set(port,pin) (port |= pin)
#define clear(port,pin) (port &= (~pin))
#define pin_test(pins,pin) (pins & pin)
#define bit_test(byte,bit) (byte & (1 << bit))
#define led_delay() _delay_ms(500)
@joeltg
joeltg / import.scm
Last active February 25, 2018 19:44
Import/Export macros for MIT Scheme
(define (normalize-pathname pathname)
(directory-pathname-as-file (pathname-simplify pathname)))
(define (initialize-environments ht ie nie nee)
(environment-define nie 'hash-table ht)
(environment-define nie 'import-env nie)
(environment-define nie 'export-env nee)
(environment-define nie 'import-list (make-import-list nie ht))
(environment-define nie 'export-list (make-export-list nie nee))
(link-variables nie 'import ie 'import)
@joeltg
joeltg / cid.d.ts
Last active August 17, 2021 09:15
TypeScript definition files for miscellaneous Protocol Labs projects
export as namespace CID
export = CID
type Buffer = any
interface SerializedCID {
codec: string
version: number
multihash: Buffer
}
@joeltg
joeltg / keybase.md
Created June 26, 2018 16:41
Keybase verification

Keybase proof

I hereby claim:

  • I am joeltg on github.
  • I am joelg (https://keybase.io/joelg) on keybase.
  • I have a public key ASAT5TnVT1VjbgzrxQPWCTHhakVO_WvhLQ2fWl2pFMnUPwo

To claim this, I am signing this object: