Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
@samth
samth / p-and.rkt
Created November 24, 2011 00:02
Some macro trickery
#lang racket
(require (for-syntax syntax/parse))
(define-for-syntax (transform stx)
(syntax-parse stx
#:literals (and or)
[(and rest ...) #'(p-and rest ...)]
[(or rest ...) #'(p-or rest ...)]
[_ stx]))
; lower-bound = alpha
; upper-bound = beta
(define (maximum-value-with-cutoff s depth lower-bound upper-bound)
(let-values
([(maximum-value new-lower-bound within-upper-bound?)
(for*/fold
([maximum-so-far -inf.0]
[new-lower-bound lower-bound])
([successor (successors s)]
[successor-value (in-value (value-with-cutoff successor
#lang racket/base
(require racket/class)
(provide autocompletion-cursor<%> autocompletion-cursor%)
(define autocompletion-cursor<%>
(interface ()
get-completions ; -> (listof string)
get-length ; -> int
empty? ; -> boolean
@samth
samth / kw-typed.rkt
Created December 20, 2011 15:41
require/typed and keyword arguments
#lang racket/load
(module m racket
(define (f #:x x) x)
(provide f))
(module n typed/racket
(require/typed 'm
[f (#:x Any -> Any)])
(f #:x 3))
@samth
samth / num.rkt
Created January 12, 2012 23:22
simple universe program
#lang racket
(require 2htdp/universe 2htdp/image)
(define (draw n)
(overlay (text (number->string n) 20 "green")
(empty-scene 200 200)))
(big-bang 0
[on-key (lambda (n k) 0)]
[on-tick add1]
[to-draw draw])
@samth
samth / gist:1652932
Created January 21, 2012 14:28 — forked from jlongster/gist:1651726
Macros
;; AST style:
((equal? term "cond")
(define (transform i)
(if (or (> i node.children.length)
(eq? i node.children.length))
null
(let ((n (vector-ref node.children i)))
(let ((condition (vector-ref n.children 0))
(res (ast.node ast.LIST
@samth
samth / curl.sh
Created March 1, 2012 00:28
rudimentary github wrangling
[samth@loki:~ plt] curl -u 'samth:PASSWORD' --data '{"title":"the title"}' https://api.github.com/repos/samth/test-bugs/issues
@samth
samth / delay-values.rkt
Created March 5, 2012 20:49
delay/values
#lang racket/base
(require racket/promise)
(provide delay/values)
(define-syntax-rule (delay/values n . e)
(let ([tmp (lazy (call-with-values (λ () . e) vector))])
(apply values (for/list ([i (in-range n)])
(lazy (vector-ref (force tmp) i))))))
#lang typed/racket
(struct: (T) TryS ())
(struct: (T) Failure TryS ([exception : exn]))
(struct: (T) Success TryS ([result : T]))
(define-type (Try T) (U (Failure T) (Success T)))
(: failed (All (T) (Try T) -> Boolean))
#lang racket
(require net/url net/uri-codec)
(define url:string "https://myneu.neu.edu/cp/home/login")
(define the-url (string->url url:string))
(define ip (post-pure-port
the-url
(string->bytes/utf-8
(alist->form-urlencoded '((user . "me") (pass . "my_password"))))
empty))