Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
(def timing
(for [seq-len [100 10000 1000000]
:let [v (vec (range seq-len))]
[name [f combine]] {:map [map reduce]
:r/map [r/map r/reduce]
:fold [r/map r/fold]}
num-layers [0 2 5 10 25]]
{:f name,
:len seq-len,
:layers num-layers,
(def users [{:name "Brian" :age 22} {:name "Ben" :age 19}])
;; Takes a "path", returns a function that takes an "object" and
;; returns a "costate"
(defn lens [p]
(fn [o]
{:get (get-in o p)
:set #(assoc-in o p %1)}))
(def myAgeLens (lens [0 :age]))
// based off of http://labs.unwieldy.net/moocirclepack/
org.polymaps.packer = function() {
var packer = {},
nodes = [],
elements = [],
timesToPack = 50;
packer.elements = function(e) {
if (!arguments.length) {
return elements;
@swannodette
swannodette / gist:2400319
Created April 16, 2012 17:53 — forked from jamii/gist:2400297
Very crude (monotonic) datalog interpreter
(ns mist.logic.datalog
(:use clojure.core.logic
[clojure.set :only [union, difference]])
(:require clojure.walk))
(defne allo [goal args]
([_ ()])
([_ [arg . rest]]
(goal arg)
(allo goal rest)))
@jhickner
jhickner / gist:2374900
Created April 13, 2012 07:36
konami code rxjs example in clojurescript
(ns rxjs.client.core
(:use [jayq.core :only [$ on off document-ready]]
[jayq.util :only [log]]))
(defn on-as-observable [$elem events & [sel data]]
(js/Rx.Observable.create
(fn [observer]
(let [handler (fn [evt-object]
(.onNext observer evt-object))]
(on $elem events sel data handler)
(comment
Given some rules like:
{(if ?x ?y nil) (when ?x ?y)
(when true . ?x) (do . ?x)}
And the `unify` and `check-form` functions below,
I would like to apply `unify` until I `unify` returns nil.
@jamii
jamii / Mist.md
Created February 25, 2012 21:15
Mist: an open-source clojure library for p2p NAT traversal, dynamic addressing and pubsub

About

Building decentralised services is an exercise in accidental complexity. Connectivity is the first hurdle. Users move around, go on- and off-line and lurk behind NAT. For centralised systems we have ICE. For decentralised systems there is no standard solution.

Mist will take an abstract address representing a user, locate their machine, punch a hole and return a local UDP proxy to talk to that user. It will be cross-platform, provide a simple api and be easy to use with existing UDP programs.

As a bonus, the implementation also provides a p2p pubsub system.

The design is based heavily on Jeremy Miller's telehash protocol (although simplified and streamlined) and draws ideas from libswift. It is also based on lessons learned from my telehash implementation.

@swannodette
swannodette / gist:1893724
Created February 23, 2012 16:52 — forked from fogus/gist:1893062
pretty-lambdas for elisp
(defun pretty-lambdas ()
"Show glyph for lower-case Greek lambda (λ) wherever 'lambda' appears."
(font-lock-add-keywords
nil
`(("(\\(lambda\\>\\)"
(0
(progn
(compose-region
(match-beginning 1)
(match-end 1)
@fogus
fogus / delegating-proxy.clj
Created February 1, 2012 16:53 — forked from michalmarczyk/delegating-proxy.clj
A ridiculous proxy macro which delegates calls to methods which have not been explicitly implemented to a specified object.
;;; Written when pondering
;;; http://stackoverflow.com/questions/9086926/create-a-proxy-for-an-specific-instance-of-an-object-in-clojure
(defmacro delegating-proxy [o class-and-ifaces ctor-args & impls]
(let [oname (gensym)]
(letfn [(delegating-impls [^java.lang.reflect.Method ms]
(let [mname (symbol (.getName ^java.lang.reflect.Method (first ms)))
arity-groups (partition-by #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)
max-arity (max-key #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)]
`(~mname
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog