Skip to content

Instantly share code, notes, and snippets.

Avatar
🐧
Staying home

Sam Tobin-Hochstadt samth

🐧
Staying home
View GitHub Profile
View hangul-reading.rkt
#lang racket
(define hangul-data-file "src/racket-unihan/Unihan_Readings.txt")
(define-values (_ r) (call-with-input-file hangul-data-file
(lambda (in)
(for/lists (lines) ([l (in-lines in)]
#:unless (eq? '#\# (string-ref l 0))
#:break (= (length lines) 30))
l))))
View anonymous-gist.rkt
(module+ test
(require rackunit check-sexp-equal)
(define (ts type tok)
(token-struct type tok #f #f #f #f #f))
(define (pt val from to)
(position-token val (position from #f #f) (position to #f #f)))
(define (drain-lexer input)
(define ip (open-input-string input))
View anonymous-gist.rkt
(module+ test
(require rackunit)
(let ([ip (open-input-string "2 + 3")])
(define (ts type tok)
(token-struct type tok #f #f #f #f #f))
(define (pt val from to)
(position-token val (position from #f #f) (position to #f #f)))
(define (check-lex1 type tok a b)
@samth
samth / core.cljs
Last active Dec 23, 2015 — forked from swannodette/core.cljs
breaking parametricity
View core.cljs
(ns typed-play.core
(:require-macros [cljs.core.typed :as t])
(:require [cljs.core.typed :as t]))
(t/ann my-identity (All [x] (Fn [x -> x])))
(defn my-identity [x]
(if (number? x)
(do (prn x) x)
x))
View silly-me.rkt
#lang typed/racket
(: fir-filter ((Listof (List Nonnegative-Fixnum Real)) -> Any))
(define (fir-filter params)
(match params
[`((,#{delays : (List Nonnegative-Fixnum)} ,amplitudes) ...)
(+ 1 (apply max delays))]
[other (error 'ouch)]))
View dave.js
export default f(1, 2, 3); // anonymous export
export let foo = 5; // named declaration export
export foo // named export of existing identifier
export foo, bar; // named export of multiple existing identifiers
export foo as f; // named aliasing export
export foo as f, bar; // you get the idea
import default glob from "glob"; // anonymous import
import sync from "glob"; // named import
import sync as s from "glob"; // named aliasing import
View concat-transform.js
// A.js
import y from "B";
console.log("a");
export var x;
// B.js
import z from "C";
console.log("b");
export var y;
@samth
samth / ideagen.rkt
Last active Dec 14, 2015 — forked from jorendorff/ideagen.py
Talk ideas in Racket
View ideagen.rkt
#lang at-exp racket
;; Generate lovely ideas for talks
;; Ported from Jason Orendorff's python code:
;; https://gist.github.com/jorendorff/4659406
(require math)
(define productions
#hash(["tech" . ("HTML5"
View find-duplicates.rkt
#lang racket
(define (find-duplicates elts)
(define ht (make-hash))
(for/list ([x elts]
#:when (hash-update! ht x add1 0)
#:when (= 2 (hash-ref ht x)))
x))
(find-duplicates '(1 2 2 3 1 4 5 4 4 4))
View test
. Type Checker: untyped identifier apply-contract imported from module <private/base.rkt> in: #%module-begin
. Type Checker: untyped identifier coerce-contract imported from module <private/guts.rkt> in: #%module-begin
. Type Checker: untyped identifier flat-named-contract imported from module <racket/contract> in: #%module-begin
. Type Checker: untyped identifier build-source-location imported from module <syntax/srcloc> in: #%module-begin
. Type Checker: Summary: 4 errors encountered in:
#%module-begin
#%module-begin
#%module-begin
#%module-begin