Skip to content

Instantly share code, notes, and snippets.

@samdphillips
samdphillips / spotify.rkt
Created July 13, 2018 20:57
Remote control of Spotify from Racket for Mac OSX
#lang racket/base
#|
A Hack to remote control Spotify from Racket.
It pretty reliably will crash DrRacket if run.
Works better if require'd from another module, or run from command line.
|#
#lang racket/base
(require racket/class
racket/draw
racket/match
threading
(only-in math pi))
(struct draw (perform x0 y0 x1 y1)
@samdphillips
samdphillips / example-snip.rkt
Created August 24, 2018 00:25
A minimal example of a value with a snip for Racket
#lang racket/base
(require racket/class
racket/gui
racket/struct)
(struct message
(text size)
#:methods gen:custom-write
[(define (write-proc v outp mode)
@samdphillips
samdphillips / interaction.txt
Created October 2, 2018 00:47
Teeing Racket Output Ports
> (define out (tee "test"))
> (fprintf out "test~%")
test
> (fprintf out "test~%")
test
> (fprintf out "test~%")
test
> (for ([x 10]) (fprintf out "test ~a~%" x))
test 0
test 1
@samdphillips
samdphillips / tee1.rkt
Created October 2, 2018 01:14
Evolution of functions
#lang racket/base
(require racket/port)
(define (tee filename)
(let ([file-out (open-output-file filename)]
[stdout (current-output-port)])
(let-values ([(inp outp) (make-pipe)])
(thread
(lambda ()
@samdphillips
samdphillips / gui-tabs.rkt
Created October 3, 2018 18:35
Tabs Example in Racket GUI
#lang racket/base
(require racket/class
racket/gui)
(define frame
(new frame% [label "Tabs!"]))
(define (change-tab tp event)
(when (eq? (send event get-event-type) 'tab-panel)
@samdphillips
samdphillips / for-hash-map.md
Last active January 7, 2019 18:18
Racket map over a hash with for/hash
Welcome to Racket v7.0.
> (for/hash ([x 10]) (values x x))
'#hash((0 . 0)
       (1 . 1)
       (2 . 2)
       (3 . 3)
       (4 . 4)
       (5 . 5)
 (6 . 6)
@samdphillips
samdphillips / class_field_ex.rkt
Last active January 19, 2019 19:21
access fields in Racket
#lang racket
(define foo%
(class object%
(init-field f)
(define/public (get-f) f)
(super-new)))
(define foo (make-object foo% 42))
@samdphillips
samdphillips / copier.rkt
Created January 23, 2019 02:30
Crude copy and paste tool
#lang racket/base
#|
Crude hack when I have to repeatedly copy a bunch of things and then want
to paste them in one go.
Very imperative!
Such power!
#lang racket/base
(require racket/match
racket/struct
(rename-in data/heap
[heap-remove-min! -heap-remove-min!]))
(define (heap-empty? h)
(zero? (heap-count h)))