Skip to content

Instantly share code, notes, and snippets.

View eraserhd's full-sized avatar

Jason Felice eraserhd

View GitHub Profile
@eraserhd
eraserhd / infix.lisp
Created July 12, 2013 03:57
Infix expressions in Common Lisp. (Work in progress.)
(require 'cl-test-more)
(defpackage infix
(:use :cl :cl-test-more))
(in-package :infix)
(defun simple-binary (sym)
#'(lambda (left right)
(list sym left right)))
@eraserhd
eraserhd / vimrc
Created July 25, 2013 13:14
Scheme/lisp setup
augroup scmprog
au!
autocmd BufNewFile,BufRead *.scm,*.sch let b:is_chicken=1
autocmd BufNewFile,BufRead *.scm,*.sch set ft=scheme sts=2 sw=2 autoindent lisp showmatch
augroup END
augroup lisp
autocmd FileType lisp set sts=2 sw=2
augroup END
@eraserhd
eraserhd / 9.clj
Created November 23, 2013 20:47
Divide large decimal numbers by 9
(defn decimal-divide-by-9 [n]
(letfn [(digit-value [digit]
(- (.charCodeAt digit 0)
(.charCodeAt "0" 0)))
(place-values-+ [place-values addend]
(cond
(= 0 addend) place-values
(seq place-values) (conj (rest place-values)
(+ addend (first place-values)))
@eraserhd
eraserhd / splay-rope.clj
Created January 22, 2014 15:28
A rope implementation using splay trees.
(ns splay-rope.core)
(declare traverse)
(deftype Node [^int offset
^String data
left
right]
Object
(toString [node]
@eraserhd
eraserhd / simple-check.clj
Created January 24, 2014 00:25
An attempt at testing multiple splices via simple-check.
;; 1. What I'm testing: A rope implementation where the binary tree is
;; balanced by splaying.
;; 2. To simplify things, it supports one update operation:
;; (splice rope start-offset end-offset new-data)
;; 3. I'd like to verify that the nodes are in the right order and other
;; properties after multiple splicings
;; Here's a spec I wrote for testing that the rope has the right
;; string representation after a single insertion-type splice:
@eraserhd
eraserhd / normal.clj
Created March 8, 2014 19:42
Guess what's wrong?
(defmacro defhandler
[& args]
(let [tags (take-while keyword? args)
[keystroke handler-args & handler-body] (drop-while keyword? args)]
`(def ^{:handles ~keystroke} handler#
(make-handler ~@tags (fn ~handler-args ~@handler-body)))))
@eraserhd
eraserhd / macros.clj
Created April 19, 2014 23:17
in-> and ->' macros
(ns avi.compose)
(declare ^:private splice-form)
(defn- splice-normal-form
[value form]
(apply list (first form) value (rest form)))
(defn- splice-if-form
[value form]
@eraserhd
eraserhd / prepare-commit-msg
Created April 24, 2014 16:28
When using midje, this script tries hard to guess the commit message based on added facts.
#!/usr/bin/env ruby
def levenshtein_edit_distance(a,b)
dp = Array.new(a.length + 1) {Array.new(b.length + 1, 99999999)}
dp[0][0] = 0
1.upto(a.length) {|i| dp[i][0] = i}
1.upto(b.length) {|j| dp[0][j] = j}
1.upto(a.length) do |i|
1.upto(b.length) do |j|
dp[i][j] = [
@eraserhd
eraserhd / grabvars
Created June 5, 2014 13:36
grabssh
#!/bin/sh
(
printf 'unset SSH_CLIENT\n'
printf 'unset SSH_AUTH_SOCK\n'
printf 'unset SSH_CONNNECTION\n'
printf 'unset SSH_TTY\n'
set |grep ^SSH |sed 's/^/export /'
) > ~/.ssh/vars
@eraserhd
eraserhd / interpreter.c
Created August 24, 2014 17:52
A really simple language interpreter
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char op;
int a, b;
scanf("%c %d %d", &op, &a, &b);
switch (op) {
case '+': printf("%d\n", a + b); break;