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 / gist:5182719
Last active July 5, 2022 04:36
Example of using `yield', and related usages of Racket's GUI
View gist:5182719
#lang racket/gui
(define xmax 200)
(define ymax 200)
(define seconds-in-loop 3)
(define fr (new frame% [label ""]))
(define cv (new canvas% [parent fr] [min-width xmax] [min-height ymax]))
(define dc (send cv get-dc))
(send fr show #t)
Metaxal / client.rkt
Last active December 16, 2015 11:19
Unix domain socket communication test
View client.rkt
#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.
View dabbrev.rkt
#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
View copy-paste.rkt
#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.
View prisoner-dilemma-read-code.rkt
#lang racket
(require racket/sandbox)
Original idea by Eliezer Yudkowski and Alex Mennen:
Metaxal / and-def.rkt
Last active December 18, 2015 08:59
Allowing for internal definitions in `and'
View and-def.rkt
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (and/def stx)
(syntax-parse stx
#:literals (define define-values)
[(_) #'#t]
[(_ [define-values (var:id ...) val:expr] rest ...)
#'(let-values ([(var ...) val])
Metaxal / struct-default-super.rkt
Last active December 18, 2015 20:28
Giving default/optional values for struct. Define the struct with opt-struct instead of struct, and use make-<struct-name> as the default constructor. struct-default.rkt is the simple version, but does not handle super structs as struct-default-super.rkt does (though not entirely correctly).
View struct-default-super.rkt
#lang racket
(require (for-syntax syntax/parse
;;; Recognizes super-id and keyword arguments of struct.
;;; Caveats:
;;; - does not recognize per-field options (like per-field mutability).
;;; - the hash table uses the symbol of the super-id, but should use the binding instead.
;;; - may not work if the default expr depends on bindings not available in the context of the
Metaxal / name-and-pos.rkt
Last active May 7, 2020 10:00
Both by-name and by-position per argument procedure calls.
View name-and-pos.rkt
#lang racket
(require (for-syntax syntax/parse))
;;; Allow every argument to be passed by-name or by-position in a procedure call.
;;; Keywords do not need to apper in procedure headers in definitions.
;;; Accepts rest and keyword-rest arguments.
;;; A new definition of instantiate is also given to resemble this procedure call style.
;;; Resources:
;;; -
;;; -
Metaxal /
Last active December 21, 2015 15:29
Compile racket on the QNAP TS 121 (ARMv5)
# This is not really a script and should be run line by line instead.
# With the admin user, do the following.
# Install Optware (ipkg)
# and configure the admin's path.
# Install correct versions of basic tools,
# otherwise the following will not work.
ipkg install coreutils make find grep sed gawk
Metaxal / logging.rkt
Last active September 10, 2023 09:52
Simple usage of Racket's logging facility
View logging.rkt
#lang racket/base
; One way to define a logger
(define lg (make-logger 'my-logger))
; Define a receiver for this logger, along with a log level
(define rc (make-log-receiver lg 'error)) ; also try with 'debug
; Another way to define a logger, with additional forms
(define-logger lg2)
(define rc2 (make-log-receiver lg2-logger 'debug))