Skip to content

Instantly share code, notes, and snippets.

@jkominek
jkominek / seidel-lp.rkt
Created September 27, 2011 06:42
Seidel's Linear Programming Algorithm
#lang racket
; A non-random Racket implementation of the algorithm given in:
; Small-Dimension Linear Programming and Convex Hulls Made Easy by R. Seidel
; There are a number of other documents floating around describing it,
; including another Seidel paper. I think all of them have at least typos,
; if not conceptual errors. The pseudo code at the end of the above paper
; is, I think, the least buggy. All the λ stuff is a bit odd; they seem
; to be mixing some numerical tolerance stuff with the variable bounds?
@jkominek
jkominek / gesture-canvas.rkt
Created October 4, 2011 22:34
An implementation of the Dollar Recognizer as a canvas% mixin for Racket
#lang scheme/gui
; $1 gesture recognizer
; Based on
; WOBBROCK J. O., WILSON A. D., LI Y.: Gestures without libraries, toolkits or training: a $1 recognizer for user interface prototypes. In UIST ’07: Proceedings of the 20th annual ACM symposium on User interface software and technology (New York, NY, USA, 2007), ACM, pp. 159–168.
; There's another paper that improves on recognition time:
; Reaver, Stahovich, Herold: How to make a Quick$: Using Hierarchical Clustering to Improve the Efficiency of the Dollar Recognizer. Eurographics Symposium on Sketch-Based Interfaces and Modeling (2011), pp. 103-108.
; Currently when it's run, it pops open a little window that will do the recognition. The mixin could certainly use more features.
@jkominek
jkominek / pegasos.rkt
Created October 10, 2011 17:36
Implementation of Pegasos SVM for Racket
#lang racket
; Racket implementation of "Pegasos: Primal Estimated sub-GrAdient SOlver for SVM"
; http://www.cs.huji.ac.il/~shais/papers/ShalevSiSrCo10.pdf
; This is placed in the public domain, all rights are relinquished. Have at it.
; - Jay Kominek, 2011-10-10
(require racket/flonum)
(require (planet neil/levenshtein:1:3/levenshtein))
@jkominek
jkominek / metaheuristic-web.rkt
Created March 20, 2012 22:48
Metaheuristic search procedures, a toy servlet for using the user as a comparison function, and some functions for rendering triangles into SVG
#lang web-server
; Three things happened in somewhat rapid succession:
; 1. I was playing with stateless servlets
; 2. I came across a copy of Essentials of Metaheuristics on my drive
; 3. I remembered seeing some web pages which generated abstract art
; for the user by having them choose which of a population they found
; most asthetically pleasing.
;
; At that point, this seemed like a great idea.
@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")
@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 / 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
#!/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 / 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)
@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")