Skip to content

Instantly share code, notes, and snippets.

@tonyg
tonyg / gist:1207521
Created September 9, 2011 22:46
Bram Cohen's geometry question
@bramcohen writes: "What's the maximum ratio between the volume of a
convex shape and the volume of the smallest right angle box it can fit
in?"
Considering the 2D case.
Limit attention without loss of generality to convex polygons.
When discussing rectangles, we use the following terminology:
@tonyg
tonyg / monitor.scm
Created October 18, 2011 15:37
Experimental monitor/link implementation for Racket
#lang racket/base
;; Erlang-style monitors for Racket threads.
(provide monitor-thread!
demonitor-thread!)
(define (monitor-thread! thd [kill-monitoring-thread #f])
(let ((monitoring-thread (current-thread)))
(define monitor-handle
(thread
@tonyg
tonyg / standard-thread.rkt
Created October 22, 2011 15:23
Sketch of exit-status preserving threads
#lang racket/base
;; Standard Thread
(provide exit-status?
exit-status-exception?
exit-status-value
current-thread-exit-status
exit-status-evt
@tonyg
tonyg / minified-os.rkt
Created January 19, 2012 17:46
My, what a small operating system you have
#lang racket
(provide (struct-out subscription)
(struct-out message-handler)
(struct-out kernel-mode-transition)
make-vm
vm?
run-vm
nested-vm)
@tonyg
tonyg / plt.rkt
Created February 9, 2012 18:24
Camcapture-compatible camdisplay in Racket
#lang racket/base
(require racket/pretty)
(require racket/class)
(require racket/gui/base)
(require racket/draw)
(require racket/match)
(require (only-in web-server/private/gzip gunzip/bytes))
(require rnrs/bytevectors-6)
@tonyg
tonyg / struct-map.rkt
Created February 26, 2012 23:20
Generic mapping over Racket structures
#lang racket/base
(provide current-struct-mappers
install-struct-mapper!
struct-map
struct-map/accumulator)
;; Parameter<Hash<StructType,Mapper>>
(define current-struct-mappers (make-parameter (hash)))
@tonyg
tonyg / tuareg-lwt.patch
Created May 5, 2012 20:19
Patch against Tuareg 2.0.4 for Lwt 2.3.2
diff --git a/tuareg.el b/tuareg.el
index 9a25d59..ed83063 100644
--- a/tuareg.el
+++ b/tuareg.el
@@ -1046,7 +1046,7 @@ Regexp match data 0 points to the chars."
'("module" "class" "functor" "object" "type" "val" "inherit"
"include" "virtual" "constraint" "exception" "external" "open"
"method" "and" "initializer" "to" "downto" "do" "done" "else"
- "begin" "end" "let" "in" "then" "with"))
+ "begin" "end" "let" "lwt" "in" "then" "with"))
@tonyg
tonyg / gist:3178967
Created July 25, 2012 22:00
slideshow/pict DSL ftw
#lang racket/base
(require "vm-pictures.rkt")
(render
(vm (vm-label "Ground VM")
(network-label "TCP + Timers")
(process "TCP driver")
(process "Timer driver")
(process "Session factory")
(process-space)
(vm (vm-label "Session VM")
@tonyg
tonyg / mtl.rkt
Created August 8, 2012 13:46
Multitasking with Continuations and Lists
#lang racket/base
(define tasklist (list (list 'root (box 'no-continuation))))
(define currtask tasklist)
(define call/cc call-with-current-continuation)
(define fork
(lambda (name)
(call/cc
@tonyg
tonyg / exqu.hs
Created September 9, 2012 19:25
Existentials and Foralls
{-# LANGUAGE ExistentialQuantification #-}
module Exqu where
type Callback state = (state -> (state, [String]))
data Process = forall state. Process state (Callback state)
proc1 x = (2, ["proc1"])
proc2 x = ("bye", ["proc2"])
drive (Process s d) = let (_, ms) = d s in ms