Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
@samth
samth / ray.rkt
Created February 21, 2013 21:07
Ray tracer by Dmitry Cherkassov
#lang racket/gui
(require racket/flonum)
(require racket/future)
;; basic structs -------------------------------------------
(struct pixel (r g b))
(struct vec (x y z))
(struct ray (from dir))
(struct int-res (int? t p))
(struct sphere3D (center radius col))
@samth
samth / static-checking.rkt
Last active December 14, 2015 01:49
Restricting the keywords
#lang typed/racket
(: f (case->
(Integer [#:application Integer] [#:context Nothing] -> (List Integer Integer))
(Integer [#:context Integer] [#:application Nothing] -> (List Integer Integer))))
(define (f x #:application [a 0] #:context [c 0])
(list a c))
(f 1)
(f 1 #:application 5)
@samth
samth / ideagen.rkt
Last active December 14, 2015 02:49 — forked from jorendorff/ideagen.py
Talk ideas in Racket
#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"
// 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 / out.txt
Last active December 16, 2015 08:09
q vs lines
2htdp 772
afm 0
algol60 58
at-exp 2
browser 111
combinator-parser 0
compatibility 46
compiler 937
config 1
data 193
<jorendorff> good morning!
I do have a new raft of questions
<samth> ok
fire away
earlier you asked about the fetch callbacks
<jorendorff> yes?
* jorendorff tries to remember what he asked
<samth> first, `skip()` means "someone else is going to fulfill this particular module request"
<jorendorff> samth: 1. Regarding eval(code, {module, url}), what's the module for?
samth: wait but then
@samth
samth / dave.js
Last active December 16, 2015 17:59 — forked from dherman/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
@samth
samth / gist:5534844
Last active December 17, 2015 02:19
palindrome
#lang racket
(define (palindrome str)
(define lst (string->list (string-downcase str)))
(define slst (remove* '(#\space) lst))
(equal? (reverse slst) slst))
(module+ test (require rackunit)
(check-true (palindrome "able was i ere i saw elba")))
@samth
samth / gist:5618014
Created May 21, 2013 07:09
splitting
[samth@hermes:~/tmp plt] git clone ~/sw/plt/
[samth@hermes:~/tmp/plt (master) plt] git filter-branch -f --prune-empty --tag-name-filter cat --subdirectory-filter collects/realm/ -- --all
[samth@hermes:~/tmp/plt (master) plt] git filter-branch -f --index-filter 'git ls-files -s | sed "s-\t\"*-&realm/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
#lang racket/base
(require racket/class json net/url racket/port net/base64 racket/match racket/trait)
(provide client%)
(define ua-header "User-Agent: Racket github package; github.com/samth/github.rkt")
(define (do-post token title body url)
(define auth-header (format "Authorization: bearer ~a" token))