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 / new-line-keep-comments.rkt
Last active October 13, 2023 13:22
quickscript: Like pressing Enter, but keeps the comments at the end of the line
#lang racket/base
(require quickscript
racket/list
racket/class
racket/gui/event)
(script-help-string "Like pressing Enter, but keeps the comments at the end of the line")
;;; Author: Laurent Orseau <laurent.orseau@gmail.com>
@Metaxal
Metaxal / logging.rkt
Last active September 10, 2023 09:52
Simple usage of Racket's logging facility
#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))
@Metaxal
Metaxal / remove-trailing-spaces.rkt
Last active September 10, 2023 09:41
remove trailing spaces on save
#lang racket/base
;;; Author: Laurent Orseau https://github.com/Metaxal
;;; 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/string
racket/class)
@Metaxal
Metaxal / latex-math-chars.rkt
Last active August 7, 2023 12:12
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
@Metaxal
Metaxal / tab-panel-example.rkt
Last active July 23, 2023 20:04
Usage example of tab-panel%
#lang racket/gui
(define fr (new frame% [label "Tab example"]))
(define (tab-panel-set-tab tp idx)
(send tp change-children
(λ (previous-children)
(list (list-ref tab-contents idx)))))
(define tp (new tab-panel%
@Metaxal
Metaxal / readme.md
Last active July 1, 2023 12:50
Making a pull request for a main distribution package for Racket
@Metaxal
Metaxal / run-main-file.rkt
Last active June 26, 2023 09:00
A proof-of-concept quickscript to run the main file in the same directory
#lang racket/base
;;; Author: Laurent Orseau
;;; 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
quickscript/utils
racket/file
racket/path
@Metaxal
Metaxal / plot-ticks.rkt
Created November 5, 2021 10:48
Customizing plot ticks
#lang racket
(require plot)
(define (tlayout low high)
(list
; major ticks: tick is shown with label
(pre-tick pi #t)
(pre-tick (sqrt 2) #t)
(pre-tick 0.5 #t)
; minor ticks: tick is shown, but without label
@Metaxal
Metaxal / command-palette.rkt
Last active March 19, 2023 22:14
`Navigate' the menus with a search-list-box (quickscript)
#lang racket/base
(require quickscript
racket/gui/base
racket/class
racket/list
search-list-box)
(provide (except-out (all-defined-out)
search-list-box-filter))
@Metaxal
Metaxal / hasheq-ref-vs-bin-search.rkt
Created October 16, 2022 17:16
Comparison between hash-ref on hasheq (for fixnums) and a custom binary search
#lang racket
(require racket/fixnum
math/base)
;;; Conclusion: hasheq-ref is (slightly) faster than a custom binary search
;;; (It's actually probably implemented as a binary search, with some more optimization,
;;; as the bin search is within a factor 2)
(#%declare #:unsafe)