Skip to content

Instantly share code, notes, and snippets.

View Metaxal's full-sized avatar

Laurent Orseau Metaxal

  • Google DeepMind
  • London, UK
View GitHub Profile
Metaxal / big-bang-slowness.rkt
Last active August 29, 2015 14:00
Simple test showing big-bang being slow at rendering on screen in new version
#lang racket
;;; Run this file with `racket test-big-bang.rkt`
;;; then type quickly "asdf" to trigger several successive to-draw events.
;;; Drawing the scene is fast, but rendering it on-screen is very slow?
(require 2htdp/image
Metaxal /
Last active August 29, 2015 14:03
regex-golf slowdown?
# From:
import re
def verify(regex, winners, losers):
"Return true iff the regex matches all winners but no losers."
missed_winners = {W for W in winners if not, W)}
matched_losers = {L for L in losers if, L)}
if missed_winners:
print "Error: should match but did not:", ', '.join(missed_winners)
#lang racket
;; proc : procedure? ; procedure to apply
;; dict : dict? ; dictionary of keywords and values
;; A key can be either a keyword or a symbol that is turned into a keyword.
;; largs : list? ; positional arguments
;; Returns the result of the application of proc to the positional arguments and the keyword values.
(define (keyword-apply/dict proc dict largs)
(define alist
Metaxal / message-no-event.rkt
Last active August 29, 2015 14:24
Sample code showing that on-subwindow-event does not have correct receiver for message%
#lang racket/gui
(define my-frame%
(class frame%
(define/override (on-subwindow-event receiver event)
(when (send event button-down?)
(displayln (send receiver get-label)))
Metaxal / canvas-speed.rkt
Last active August 29, 2015 14:25
Simple stress test for canvas speed
#lang racket/base
(require racket/gui/base
(define NUM-CELL-X 100)
(define NUM-CELL-Y 100)
(define CELL-SIZE 2)
Metaxal / test-closure.rkt
Last active August 29, 2015 14:26
Stress test for JIT optimizations of closures and conditionals
#lang racket
(define ((foo #:a? [a? #t] #:b? [b? #t]) x)
(when b?
(displayln "b!"))
(if a?
(+ x 1)
(+ x 2)))
(define fooanb (foo #:b? #f))
Metaxal / client.rkt
Last active December 16, 2015 11:19
Unix domain socket communication test
#lang racket
(require (planet shawnpresser/racket-unix-sockets)
(define-values (i o)
(unix-socket-connect socket-path))
(communicate i o)
Metaxal / dabbrev.rkt
Last active December 16, 2015 20:59
dabbrev for DrRacket. Similar to dabbrev for emacs, a bit simplified.
#lang racket/base
(require racket/class
;racket/gui ;for message-box
(define non-word-str "\"'`,;\r\n\t (){}[]")
(define non-word-chars (string->list non-word-str))
(define non-word-re (regexp-quote non-word-str))
Metaxal / copy-paste.rkt
Last active December 18, 2015 03:39
Copy/paste example for keymap and text editors
#lang racket/gui
(require framework) ; for keymap:get-editor
(define keymap (keymap:get-editor))
#| ; Or define them yourself:
(define keymap (new keymap%))
(add-text-keymap-functions keymap)
Metaxal / prisoner-dilemma-read-code.rkt
Last active December 18, 2015 04:09
Iterated prisoner's dilemma where the code can be read by the opponent.
#lang racket
(require racket/sandbox)
Original idea by Eliezer Yudkowski and Alex Mennen: