Skip to content

Instantly share code, notes, and snippets.

@jkominek
jkominek / holepattern.rkt
Created March 30, 2015 17:46
gcode hole patterns in racket
#lang racket
(define (distance a b)
(sqrt (for/sum ([a a] [b b])
(expt (- a b) 2))))
(define (greedy-tsp data #:start [start #f])
(if (null? data)
'()
(if start
@jkominek
jkominek / llvm.rkt
Created February 25, 2015 07:31
turn a block of LLVM IR into a callable procedure
#lang racket
(require ffi/unsafe)
(define llvm (ffi-lib "/usr/lib/x86_64-linux-gnu/libLLVM-3.7.so.1"))
(define get-global-context
(get-ffi-obj 'LLVMGetGlobalContext llvm
(_fun -> _pointer)))
@jkominek
jkominek / $.rkt
Last active August 29, 2015 14:14
simple syntax-parse macros to rearrange evaluation
#lang racket
(require (for-syntax syntax/parse)
syntax/parse)
; why would you want infix syntax, when you can
; change your syntax to suit the task at hand?
(define-syntax ($ stx)
(syntax-parse stx
@jkominek
jkominek / tsp.rkt
Created November 24, 2014 23:55
Greedy and MinSpanTree based traveling salesman approximations
#lang racket
(require graph plot)
(define (distance a b)
(sqrt (for/sum ([a a] [b b])
(expt (- a b) 2))))
(define (every-edge l)
(if (null? l)
@jkominek
jkominek / resistor_color_labels.py
Last active August 29, 2015 14:06
Generate some HTML you can print and cut apart to make labels for drawers of resistors
#!/usr/bin/python
# resistor colors
colors = [ 'black', '#964b00', 'red', '#ffa500', 'yellow',
'#9acd32', '#6495ed', '#ee82ee', 'gray', 'white' ]
# borders around some of the lighter colors
border = [ 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]
out = open("labels.html","wb")
@jkominek
jkominek / ssl-sni-test.rkt
Created May 12, 2014 06:15
test for TLS SNI in racket
#lang racket
(require openssl)
(define (make-sctx pem)
(define sctx (ssl-make-server-context 'tls))
(ssl-load-default-verify-sources! sctx)
(ssl-set-ciphers! sctx "DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2")
(ssl-load-certificate-chain! sctx pem)
(ssl-load-private-key! sctx pem)
#!/usr/bin/python
# inspired by
# http://www.reddit.com/r/mathpics/comments/ookpa/i_decided_to_play_with_the_chaos_game_after_that/
# also, not actually a cube
from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGL.GL.shaders import *
@jkominek
jkominek / nasm.rkt
Created May 3, 2013 19:50
takes a string of assembly, feeds it to nasm, loads it into memory marked executable, and uses the ffi to turn pointers in it into procedures. obviously the assembly has to match your architecture, which has to be 32 or 64 bit x86, as well as your OS calling conventions. example assembly is for 64 bit unix.
(module nasm racket/base
(require racket/system
racket/file
racket/dict
ffi/unsafe
ffi/unsafe/alloc)
(define posix_memalign
; ((allocator free) ; can't auto free these pointers until we ensure that everything using
@jkominek
jkominek / cl-helloworld.rkt
Created April 24, 2013 04:13
A simple OpenCL program for Racket
#lang racket
(require ffi/unsafe)
(require ffi/unsafe/cvector)
(require ffi/vector)
(require (planet jaymccarthy/opencl:3:=4/c))
(define count 1024000)
(define kernel_source
#"
@jkominek
jkominek / 2planet.rkt
Last active December 16, 2015 03:18
This is a kludged up version of stephanh's planet.rkt demo, included with his RacketGL module, intended to demonstrate that my GL context sharing changes to Racket actually work. you should only need them, http://planet.racket-lang.org/package-source/stephanh/RacketGL.plt/1/4/examples/earth.png and my improved racket.
;; Extremely simply OpenGL demo.
;; Draw a "planet" (OK, a textured sphere).
#lang racket/gui
(require ffi/unsafe)
(require (planet "rgl.rkt" ("stephanh" "RacketGL.plt" 1 4)))
(require ffi/vector)
(require "viewer.rkt")