Skip to content

Instantly share code, notes, and snippets.

@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 / $.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 / 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 / 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
#lang racket/base
(require racket/cmdline)
(define-syntax-rule
(while<> line body ...)
(let ([process-port
(lambda ()
(for ([line (in-port read-line)])
body ...))])
@jkominek
jkominek / locked-boxes.rkt
Created May 28, 2015 18:28
inspectors & parameters to limit the dynamic extent values can be used within
#lang racket
; idea: use inspectors & parameters to protect values so they
; can't be used outside of approved dynamic extents.
; probably not fully baked? (continuations, etc)
; (define-values (b lock) (locked-box important-v key))
; (parameterize ([lock key])
; ; in here b can be used
; (less-trusted-code b))
@jkominek
jkominek / KellysFavorite.java
Created May 28, 2015 23:59
Kelly's Favorite
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class KellysFavorite implements Player {
private ArrayList<Double> cache = new ArrayList<Double>();
@jkominek
jkominek / updatestars.py
Last active March 26, 2022 15:21
Maintain a mirror of all your Github stars.
#!/usr/bin/python
#################
# NOTE
# Now at https://github.com/jkominek/updatestars
#################
import requests
import json
import re
@jkominek
jkominek / ami.rkt
Created June 15, 2015 23:20
Asterisk Manager Interface for Racket
#lang racket/base
(require racket/tcp racket/async-channel racket/match racket/function)
(define-struct ami [input-port
output-port thread
request-channel
response-channel
event-channel
[dead? #:mutable]]
@jkominek
jkominek / NumericNegationFunctionKeyExpression.java
Created August 12, 2019 21:32
numeric negation function key expression
age record.layer.demo;
import com.apple.foundationdb.record.metadata.expressions.FunctionKeyExpression;
import com.apple.foundationdb.record.metadata.expressions.QueryableKeyExpression;
import com.apple.foundationdb.record.metadata.expressions.KeyExpression;
import com.apple.foundationdb.annotation.API;
import com.apple.foundationdb.record.metadata.Key;
import com.apple.foundationdb.record.metadata.MetaDataException;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecord;
import com.google.protobuf.Message;