Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
#lang racket
(struct time-result [elapsed gc cpu] #:prefab)
(define (time-function func N)
(let loop ((n N) (results '()))
(cond
[(zero? n) (reverse results)] ; Return the results in reverse order
[else
(let-values ([(result elapsed gc-time cpu-time) (time-apply func '())])
#lang rosette/safe
(require rosette/lib/synthax) ; Require the sketching library.
(define-grammar (bsl-nums x) ; Grammar of int32 expressions over two inputs:
[expr
(choose x (?? integer?) #;(/ (?? integer?) (?? integer?)) ; <expr> := x | y | <32-bit integer constant> |
((bop) (expr) (expr)) ; (<bop> <expr> <expr>) |
((uop) (expr)))] ; (<uop> <expr>)
#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 April 19, 2022 18:08
annotated Racket disassembly

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
#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")))))
#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():
'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."); }
'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."); }
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
#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))]