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
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
2htdp/planetcute
2htdp/universe)
@Metaxal
Metaxal / regex-golf-norvig.py
Last active August 29, 2015 14:03
regex-golf slowdown?
#!/usr/bin/python
# From: http://nbviewer.ipython.org/url/norvig.com/ipython/xkcd1313.ipynb
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 re.search(regex, W)}
matched_losers = {L for L in losers if re.search(regex, 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
(sort
@Metaxal
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)))
#f)
(super-new)))
@Metaxal
Metaxal / canvas-speed.rkt
Last active August 29, 2015 14:25
Simple stress test for canvas speed
#lang racket/base
(require racket/gui/base
racket/class
racket/format)
(define NUM-CELL-X 100)
(define NUM-CELL-Y 100)
(define CELL-SIZE 2)
(define XMAX (* NUM-CELL-X CELL-SIZE))
@Metaxal
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
Metaxal / client.rkt
Last active December 16, 2015 11:19
Unix domain socket communication test
#lang racket
(require (planet shawnpresser/racket-unix-sockets)
"communicate.rkt")
(define-values (i o)
(unix-socket-connect socket-path))
(communicate i o)
@Metaxal
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/list
racket/format
;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
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
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)
#|
Self-link: http://gist.github.com/Metaxal/5723825
Original idea by Eliezer Yudkowski and Alex Mennen:
http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/4ru9
http://lesswrong.com/lw/hmx/prisoners_dilemma_with_visible_source_code/