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 / 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))
#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 / latex-math-chars.rkt
Last active October 5, 2024 13:59
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
#!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 / hanoi.rkt
Created August 19, 2019 16:19
Towers of hanoi, breadth-first search
#lang racket
(require data/heap)
;;; Not the most optimized version.
(define N 12)
(define (hanoi N)
(define visited (make-hash))
(define heap (make-heap (λ(a b) (<= (first a) (first b)))))
@Metaxal
Metaxal / racket-logo-plot.rkt
Created September 2, 2019 12:50
Lambda logo with Racket's plot
#lang racket
(require plot)
(let ([blue '(0 0 164)] [red '(164 0 0)])
(parameterize ([plot-decorations? #f])
(plot3d
(list
(surface3d (λ(x y)(/ x 10)) 0 5 0 1 #:color red #:line-color red)
(surface3d (λ(x y)(- 1 (/ (+ 1 (exp (- 5 x)))))) 0 10 0 1 #:color blue #:line-color blue))
@Metaxal
Metaxal / with-limits-test.rkt
Created December 18, 2019 08:58
The limits of with-limits
#lang racket
(require racket/sandbox)
;; Make sure you have at least 4×max-memory available
;; otherwise your computer might freeze.
(define max-memory 1024)
(define a-tree #f)
;; with-limits should limit the memory use, but it fails in this case.
;; See below for an explanation.
@Metaxal
Metaxal / classify-position-quickscript.rkt
Last active February 1, 2021 09:27
Quickscript script to try out classify-position
#lang racket/base
;;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;;; [MIT license](http://opensource.org/licenses/MIT) at your option.
(require quickscript
racket/format
racket/class)
;; Like classify position, but gives the class of the character at the insert position,
@Metaxal
Metaxal / all-tabs.rkt
Created May 2, 2020 13:58
Display a "All tabs" menu in DrRacket
#lang racket/base
(require racket/gui/base
racket/class
quickscript)
;;; The default 'Tabs' menu in DrRacket lists only the first 10 tabs.
;;; This script displays all tabs, which is particularly convenient when
;;; there are many tabs and not all of them are visible.
(define-script all-tabs
@Metaxal
Metaxal / raco-pkg-migrate.rkt
Last active November 12, 2021 14:35
When installing a new version of racket, run this script instead of just `raco pkg migrate <version-number-you-have-to-remember>`
#!/usr/bin/racket
#lang racket/base
;;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;;; [MIT license](http://opensource.org/licenses/MIT) at your option.
;; When installing a new version of Racket,
;; running this script setups all existing packages that had been installed
;; in the *user* scope.
;;