Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
View compile-time.rkt
#lang racket
(require (for-meta 2 racket/base racket/file))
(define-syntax (define-compile-time-bytes stx)
(syntax-case stx ()
[(_ id f)
#`(begin
(begin-for-syntax
(define-syntax (gen _)
@samth
samth / doc.md
Created Apr 19, 2022
annotated Racket disassembly
View doc.md

Annotations by @mflatt.

For the function (define (add m n) (+ m n)), in Aarch64:

 0: ff0a00f1         (subs xzr x23 #x2)          ; are there two arguments?
 4: 01040054         (b.ne (+ pc #x80)) ; => 84  ; jump to slow path if not
 8: 1e0001aa         (orr x30 x0 x1)             ; "or" to combine mask bits
 c: df0b40f2         (ands xzr x30 #x7)          ; zero low bits => both are fixnums
10: a1000054         (b.ne (+ pc #x14)) ; => 24  ; jump to slow path if not
View covid-data.rkt
#lang racket
(require sawzall data-frame json graphite racket/runtime-path)
(require pict)
(require (only-in plot date-ticks) gregor threading)
(define-runtime-path here ".")
(define fips-codes (delay (~> (df-read/csv (build-path here "state_and_county_fips_master.csv"))
(where (state) (equal? state "IN")))))
View serve.rhm
#lang rhombus
// Note: needs comment-out support in DrR
// Note: we should start building up this library now
import:
rhombus/macro: no_prefix
expr.rule '(loop: $body ...):
'(begin:
fun lp():
View bundle.js
'use strict';
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
View bundle.js
'use strict';
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
View Aug-30-21-075230.csv
Position M_D_YYYY TIME[HH:mm:ss] CO2[ppm] Temp[F] RH[%]
1 8/30/2021 07:52:05 702 75.8 62.1
2 8/30/2021 07:52:10 701 75.8 61.9
3 8/30/2021 07:52:15 701 75.9 61.7
4 8/30/2021 07:52:20 701 75.9 61.6
5 8/30/2021 07:52:25 699 75.9 61.7
6 8/30/2021 07:52:30 691 75.9 61.7
7 8/30/2021 07:52:35 619 75.9 61.6
8 8/30/2021 07:52:40 620 76.0 61.4
9 8/30/2021 07:52:45 623 76.0 61.3
View draw-points-typed.rkt
#lang typed/racket
(require typed/racket/draw
plot/private/common/parameters ;; just for plot-width, plot-height
)
(: transform-points : (Listof (List Integer Real)) -> (Listof (Pair Real Real)))
(define (transform-points p)
(define-values (min-x min-y max-x max-y)
(for/fold ([min-x : Integer (first (first points))]
View lex.rkt
#lang racket
(require sugar)
(define (go file h)
(define lines (file->lines file))
(match-define (list header chunks ... summary) (filter-split lines (lambda (l) (equal? l ""))))
(define p
(for/list ([l chunks])
(define size (regexp-match "leak of (.+) .* in (.+) object" (car l)))
(list (and size (map string->number (cdr size)))
(filter values
View mult2.rkt
#lang racket
(require racket/fixnum)
(define (bignum? x) (integer? x))
(define ($bignum-length x) (quotient (integer-length x) 10))
(define (integer* x y) (* x y))
(require racket/trace)
(define-syntax-rule (assert b . args)