Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
@thomcc
thomcc / a_scheme.scm
Created October 25, 2011 04:59
toy scheme
; racket
(#%require srfi/69 srfi/23)
; chicken
;(require-extension (srfi 69))
(define raise-user-error error)
(define apply-scm apply)
(define (new-eval exp env)
((analyze exp) env))
@thomcc
thomcc / thom.zsh-theme
Created November 6, 2011 19:07
zsh theme
autoload -U add-zsh-hook
autoload colors
colors
function zsh_prompt_command() {
local pwdmaxlen=25
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
@thomcc
thomcc / gist:1411486
Created November 30, 2011 22:37
icarus-verilog build failure
thom /usr/local $ brew install -v icarus-verilog
==> Downloading ftp://ftp.icarus.com/pub/eda/verilog/v0.9/verilog-0.9.3.tar.gz
File already downloaded in /Users/thom/Library/Caches/Homebrew
/usr/bin/tar xf /Users/thom/Library/Caches/Homebrew/icarus-verilog-0.9.3.tar.gz
==> ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/icarus-verilog/0.9.3
./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/icarus-verilog/0.9.3
checking build system type... i386-apple-darwin11.2.0
checking host system type... i386-apple-darwin11.2.0
checking for gcc... /usr/bin/llvm-gcc
checking for C compiler default output file name... a.out
@thomcc
thomcc / bf.rkt
Created December 5, 2011 23:31
brainfuck interpreter in scheme
(define (new-bf)
(let ((tape (make-vector 30000 0))(ptr 0))
(define (reset [sz 30000]) (set! tape (make-vector sz 0)) (set! ptr 0))
(define (b>) (set! ptr (add1 ptr)))
(define (b<) (set! ptr (sub1 ptr)))
(define (b+) (vector-set! tape ptr (add1 (vector-ref tape ptr))))
(define (b-) (vector-set! tape ptr (sub1 (vector-ref tape ptr))))
(define (p) (write-byte (vector-ref tape ptr)))
(define (g) (vector-set! tape ptr (read-byte)))
(define ops `((#\..,p)(#\,.,g)(#\>.,b>)(#\<.,b<)(#\+.,b+)(#\-.,b-)))
@thomcc
thomcc / jash.rkt
Created December 6, 2011 01:39
just another scheme hacker
(((λ(_)((λ(.#)((λ(!)((λ(~)((λ(--)((λ(%)((λ(*)((λ($)((λ(d)
((λ(f)((λ(>)(f(λ(^)((> >)^))))(λ(>)(f(λ(^)((> >)^))))))(λ
(f)(λ(^)(let ~((< 0))(cond((>= <(_ ^))(void))((eq?(.# ^ <
)#\[)((λ(>)((λ(^)(let ~()(unless(= --(! $ *))(f ^)(~)))(~
(+ > %)))(substring ^(+ % <)>)))((λ(o)((λ(f)(let ~((++ --
)(f(+ f %)))((λ(<)(if(= <(- %))f(~ < (+ f %))))(case(.# o
f)((#\[)(+ % ++))((#\])(- ++ %))(else ++)))))<))^)))(#t(d
(.# ^ <))(~(+ % <)))))))))(λ(>)(cond((assoc >`((#\..,(λ @
(write-byte(! $ *))))(#\,.,(λ()(~ $ *(read-byte))))(#\>.,
(λ .(set! *(+ % *))))(#\<.,(λ()(set! *(- * %))))(#\+.,(λ(
@thomcc
thomcc / snake.rkt
Created December 12, 2011 20:18
snake game
#lang racket/gui
(require data/queue)
(define snake%
(class object%
(super-new)
(init w h)
(define x (inexact->exact (floor (/ w 2))))
(define y (inexact->exact (floor (/ h 2))))
(define dir 'E)
(define body (let ((q (make-queue)))
@thomcc
thomcc / donut.rkt
Created December 12, 2011 20:22
donut
(define *theta-spacing* 0.07)
(define *phi-spacing* 0.02)
(define *screen-width* 300)
(define *screen-height* 240)
(define R1 1)
(define R2 2)
(define K2 5)
(define K1 (/ (* 3 K2 *screen-width*) (* 8 (+ R1 R2))))
(define (clip n min max) (if (< n min) min (if (> n max) max n)))
(define donutcvs
@thomcc
thomcc / gist:1507796
Created December 21, 2011 21:30
show an image snip on a canvas in a new frame
#lang racket/gui
(define (show-image-snip-in-new-frame snip)
(define bmp (send snip get-bitmap))
(define f (new frame% [label "image snip"]
[width (send bmp get-width)]
[height (send bmp get-height)]))
(define c
(new canvas%
[paint-callback (λ (c dc) (send dc draw-bitmap bmp 0 0))]
[parent f]))
@thomcc
thomcc / snake.clj
Created January 2, 2012 00:00
Snake game in clojure
(ns snake
(:import (java.awt Color Graphics Dimension Font)
(javax.swing JFrame JPanel)
(java.awt.event KeyEvent KeyAdapter)))
(def field [80 48]) ; [width height]
(def scale 10)
(def screen (Dimension. (* scale (field 0)) (* scale (field 1))))
(def on? true)
(def tick-speed 100)
@thomcc
thomcc / gist:1603487
Created January 12, 2012 22:18
sets problem
(def sets
{:vowel #{:a :e :i :o :u}
:consonant #{:b :c :d :f :g :h :j} ; ... etc.
:other #{:y}})
(defn categorize [thing]
(condp #(% %2) thing
(sets :vowel) :vowel
(sets :consonant) :consonant
(sets :other) :other