Skip to content

Instantly share code, notes, and snippets.

Avatar
👾

Thom Chiovoloni thomcc

👾
View GitHub Profile
@thomcc
thomcc / asmcc
Created Mar 15, 2014
A small script I use to quickly see the assembly or LLVM IR output by clang for a given piece of C++ code. (public domain, no warantee, etc.)
View asmcc
#!/usr/bin/env ruby
require 'optparse'
require 'tempfile'
TEMPLATE = <<-CODE_EOF
#include <cinttypes>
#include <cmath>
#include <cstddef>
#include <cstring>
#include <climits>
@thomcc
thomcc / resumable_random.dart
Last active Aug 29, 2015
Serializable RNG
View resumable_random.dart
// This is free and unencumbered software released into the public domain.
// For more information, please refer to <http://unlicense.org/>
import 'dart:math' as math;
/// A class used to store the state of a [ResumableRandom].
class RngState {
final int originalSeed, a, b, c, d;
RngState(this.originalSeed, this.a, this.b, this.c, this.d);
}
View a_scheme.scm
; 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))
View thom.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 Nov 30, 2011
icarus-verilog build failure
View gist:1411486
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 Dec 5, 2011
brainfuck interpreter in scheme
View bf.rkt
(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 Dec 6, 2011
just another scheme hacker
View jash.rkt
(((λ(_)((λ(.#)((λ(!)((λ(~)((λ(--)((λ(%)((λ(*)((λ($)((λ(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! *(- * %))))(#\+.,(λ(
View snake.rkt
#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)))
View donut.rkt
(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 Dec 21, 2011
show an image snip on a canvas in a new frame
View gist:1507796
#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]))