Skip to content

Instantly share code, notes, and snippets.

View whilo's full-sized avatar

Christian Weilbach whilo

View GitHub Profile
@whilo
whilo / gist:5937694
Created July 5, 2013 22:44
Trying to extend protocol to native javascript DOM type with ClojureScript.
(defprotocol PWindow
(parent [this])
(position [this])
(size [this]))
(extend-protocol PWindow
js/HTMLDivElement
(parent [this] (.-parentNode this))
@whilo
whilo / gist:7321697
Created November 5, 2013 16:27
CRDT braindump
;; Example repository-format for automatic server-side synching (p2p-web)
;; commutative merging must be possible, it is (almost) a converging and commutative distributed data type(?)
#_{:uuid "blib" ;; used to ensure universal identity on repo creation (cannot conflict)
:schema {:type "http://github.com/ghubber/geschichte" ;; might not change, if it does warn and drop merge
:version (max v1 v2)} ;; internal only, allows update to server side synching software
:public (or p1 p2) ;; might only turn to true, always false initially, allows public access to repo meta-data, no strong safety, all values are still distributed!; if false only read access from user itself allowed; must be true for pull-requests
:causal-order {12344 #{3774 23} ;; use uuids as commit ids, unionize, no conflicts, removal impossible
3774 #{12}
23 #{12}
@whilo
whilo / gist:7363179
Last active December 27, 2015 17:39
RC4 in Clojure
(ns rc4.core)
(defn init-sbox [enc-key]
(let [k (mapv int enc-key)
L (count enc-key)]
(loop [s (into [] (range 0 256)) i 0 j 0]
(if (= i 256) s
(let [j (mod (+ j (s i) (k (mod i L))) 256)]
(recur (assoc s i (s j) j (s i)) (inc i) j))))))
@whilo
whilo / clj-like-func-data-fns
Created November 22, 2013 01:30
Clojure like functional data functions for hy sketch.
(import [pysistence [make_list make_dict]])
(defn atom [init-val])
(defn swap! [atom fn])
(defn massoc [as k v]
(kwapply (as.using) {k v}))
@whilo
whilo / gist:8504314
Created January 19, 2014 12:36
Windowing/layout experiments.
(ns slide.window
(:use [dommy.core :only [set-style!]]
[dommy.template :only [PElement]]))
(defprotocol PWindow
(parent [this])
(position [this])
(size [this])
#_(set-parent! [this par])
#_(set-position! [this pos])
@whilo
whilo / d3-line-plot-test
Created February 1, 2014 15:49
Straight port from line plotting example to cljs.
(ns d3-line-plot-test)
(def margins {:top 20
:right 20
:bottom 30
:left 50})
(def totalwidth 960)
(def totalheight 500)
@whilo
whilo / hynn_example.hy
Created March 4, 2014 15:26
Simple Example of PyNN in Hy.
(import [toolz.itertoolz.core [concat cons count drop mapcat partition partial take-nth]])
(import [toolz.functoolz.core [compose complement]])
; (import [pyrsistent [pvec pmap pset]]) ; persistent data structures for python
(import [matplotlib [pyplot :as plt]])
(import [pylab :as p])
(import [numpy :as np])
;(import [scipy [optimize :as opt]])
(import [pyNN.nest [setup
create
connect
@whilo
whilo / debug-chan.clj
Last active August 29, 2015 13:57
Debugging core.async channels.
(def chan-log (atom []))
(defn debug-chan [pre]
(let [c (chan)
lc (chan)]
(async/tap (async/mult c) lc)
(go-loop [m (<! lc)]
(swap! chan-log conj [pre m])
(recur (<! lc)))
c))
(ns cljc.play)
(defn fib [x]
(if (or (= x 1) (= x 0)) 1
(+ (fib (- x 1)) (fib (- x 2)))))
(fib 30)
(defn msec []
@whilo
whilo / minimal.svg
Created May 26, 2014 15:29
Minimal test case to trigger NPE in data.xml.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.