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
#!r6rs
(import (rnrs (6)))
;; Performs a depth-first search without a get-previous-state function, by enumerating
;; the paths and restarting at the root for each new path.
;; Requires only the memory of the current state and a O(depth-max) memory of other things.
;; num-actions: positive-integer?
;; Number of children per node.
;; get-start-state: none/c -> state?
@Metaxal
Metaxal / latex-math-chars.rkt
Last active July 23, 2025 08:11
List of latex to unicode math characters
#lang racket/base
(provide latex-math-chars)
;;; LaTeX math to Unicode symbols translation dictionaries.
;;; Adapted from
;;; anaconda/lib/python2.7/site-packages/docutils/utils/math/tex2unichar.py
;;; itself generated with ``write_tex2unichar.py`` from the data in
;;; http://milde.users.sourceforge.net/LUCR/Math/
;;; Includes commands from: wasysym, stmaryrd, mathdots, mathabx, esint, bbold, amsxtra, amsmath, amssymb, standard LaTeX
#lang racket/base
(require plot
racket/list
racket/dict)
(module+ test
(require rackunit))
(define (string-ticks string-list)
(let* ([N (length string-list)]
@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 / 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 / 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)))
#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 / 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)
@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 / def-jambda-ex.rkt
Last active December 29, 2015 07:39
def-jambda with signatures next to the body
(defn
#:doc @list{Multiplies @racket[x] by @racket[y].
Use it fruitfully.}
#:ex [10 3 => 30]
#:ex [0 3 => 0]
#:ex [10 => 10]
#:ex [0 => 0]
;; The function signature
(mult [x number?][y number? 1] -> number?)
;; And the function body: