Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
@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.

(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.
@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)
@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)))
// 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;
(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]))
(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,
@terjesb
terjesb / logicrels-lucene.clj
Created July 26, 2012 08:39 — forked from jsmorph/logicrels-lucene.clj
Lucenalog: Datalog interface to Lucene in 10 lines
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
@martintrojer
martintrojer / sud4-ckanren.clj
Created July 27, 2012 18:36
Sudoku core.logic
(defne all-distinctfd [l]
([()])
([[h . t]]
(distinctfd h)
(all-distinctfd t)))
(run 1 [q]
(fresh [a1 a2 a3 a4
b1 b2 b3 b4
c1 c2 c3 c4
@swannodette
swannodette / fbound.clj
Created August 10, 2012 13:55 — forked from frenchy64/fbound.clj
F-bounded Polymorphism in Typed Clojure
; y has upper bound x, z has upper bound (Seqable y)
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]]
[x y z -> Any]))
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))]
typed.core=> (declare foo)
#'typed.core/foo
;cf = check-form
typed.core=> (cf (foo 2 2 [2]))
Any