Skip to content

Instantly share code, notes, and snippets.

View jneen's full-sized avatar

Jeanine Adkisson jneen

View GitHub Profile
@jneen
jneen / variant-multimethods.clj
Created November 22, 2014 20:55
Multimethods with variants
; it's a bit cumbersome to set up and there's the unfortunate need to ignore the tag
; in the individual methods, but this allows you to leave the interpretation of open
; variants, well, *open* for extension by multimethod.
; dispatch off the first argument, which will be the tag
(defmethod command-multi (fn [tag & data] tag))
; the first argument to the *method* is still the tag
(defmulti command-multi :print [_ val] (println val))
(defmulti command-multi :read [_ fname] (slurp fname))
@jneen
jneen / Dockerfile
Created September 5, 2014 18:17
Fig setup
FROM base/devel
RUN pacman --noconfirm -Sy jdk7-openjdk
RUN pacman --noconfirm -Sy socat
ENV LEIN_ROOT 1
RUN curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > /usr/local/bin/lein \
&& chmod +x /usr/local/bin/lein \
&& lein
@jneen
jneen / gist:d697fbb42399806f46cf
Created May 30, 2014 00:14
/usr/local/bin/wifi
#!/bin/bash
. /usr/lib/network/globals
. "$SUBR_DIR"/wpa
BIN_DIR="$(dirname "$0")"
PREFIX="${WIFI_PREFIX:-$BIN_DIR/..}"
LIB_DIR="$PREFIX/lib/wifi"
NOW="$(date +%s)"
@jneen
jneen / lambda.hs
Last active August 29, 2015 13:59
what i'm trying to do
data Expr = Var Char
| Lam Char Expr
| App Expr Expr
hasFree :: Char -> Expr -> Bool
hasFree c (Var v) = c == v
hasFree c (Lam arg body) = c /= arg && hasFree c body
hasFree c (App func arg) = hasFree c func && hasFree c arg
@jneen
jneen / lambda.clj
Last active August 29, 2015 13:59
core.typed and core.match failing to get along, with multimethods this time
(ns type-test.lambda
(require [clojure.core.typed :refer :all]
[clojure.core.match :refer [match]]))
(def-alias Expr "An expression"
(Rec [e]
(U '[(Value :var) Symbol]
'[(Value :lam) Symbol e]
'[(Value :app) e e])))
@jneen
jneen / lambda.clj
Created April 17, 2014 03:53
core.typed and core.match failing to get along
(ns type-test.lambda
(require [clojure.core.typed :refer :all]
[clojure.core.match :refer [match]]))
(def-alias Expr "An expression"
(Rec [e]
(U '[(Value :var) Symbol]
'[(Value :lam) Symbol e]
'[(Value :app) e e])))
(defn rec [expr]
(match expr
[:global] 'GLOBAL
[:constant x] x
[:variable x] x
[:lazy-variable x] `(deref ~x)
[:if test if-true if-false] `(if ~(rec test)
~(rec if-true)
~(rec if-false))
[:delist list index] `(get ~(rec list) ~(rec index))
> time node ~/tmp/perf-test.js
dynamic
real 0m0.697s
user 0m0.690s
sys 0m0.013s
> time node ~/tmp/perf-test.js static
static
@jneen
jneen / monad.py
Last active December 23, 2015 09:49
class Monad:
@staticmethod
def unit(val):
raise NotImplemented
def bind(self, fn):
raise NotImplemented
def map(self, map_fn):
"""
@jneen
jneen / monad.java
Last active December 20, 2015 11:39
// what i assume the callbacks look like
abstract class Callback<T> {
abstract void run(T data);
}
// the binding function a -> m b
abstract class Step<T, U> {
abstract Action<U> into(final T data);
}