Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
@jeroenvandijk
jeroenvandijk / set_and_identity.md
Created February 12, 2018 11:12
Sets and identity

Empty sets are always identical (apparently)

(identical? #{} #{}) ;=> true

But when we add values this changes

(identical? #{1} #{1}) ;=> false
@jeroenvandijk
jeroenvandijk / alternative_dependencies.md
Created March 30, 2017 14:23
Alternative dependencies

External dependencies: a different approach?

Libraries like https://github.com/danielsz/system offer a way to share reusable components/namespaces. The downside is that it is impossible to customize (without weird hacks or code). Often it is easier to copy-paste the code in your repo.

What if we could automate the copy-pasting in these cases? I would like to propose an idea for a (leiningen) plugin to share code without the pains of normal dependencies. No (Leftpad)[http://www.haneycodes.net/npm-left-pad-have-we-forgotten-how-to-program/] issues.

Requirements

  • No external dependencies (no risk of losing a remote dependency e.g. read about left-pad issues [1])
  • Less work than copy-pasting
  • No conflicts between dependencies
@jeroenvandijk
jeroenvandijk / example.clj
Last active February 10, 2017 09:44
Rum reconciling like
(ns adgoji.rum.reconciler.example
(:require [rum.core :as rum]
[adgoji.rum.subscriptive :as sub]))
(enable-console-print!)
(println "This text is printed from src/adgoji.rum.reconciler/core.cljs. Go ahead and edit it and see reloading in action.")
;; define your app data so that it doesn't get over-written on reload
@jeroenvandijk
jeroenvandijk / search.clj
Created February 8, 2017 17:35
AI search
(ns adgoji.planning.search
(:require [clojure.data.priority-map :as priority-map]))
(defprotocol IStack
(next-node [_])
(rest-nodes [_])
(add-nodes [_ nodes]))
(defrecord Queue [queue]
IStack
@jeroenvandijk
jeroenvandijk / sample_log_normal.clj
Created January 20, 2017 14:20
Sample log normal
(require '[incanter.core :as incanter])
;; From http://stats.stackexchange.com/questions/95498/how-to-calculate-log-normal-parameters-using-the-mean-and-std-of-the-given-distr#95506
(defn sample-log-normal [n & {:keys [mean sd]}]
(let [sd-log-part (incanter/log (+ 1.0 (/ (* sd sd) (* mean mean))))
mu (- (incanter/log mean) (* 0.5 sd-log-part))
sigma (incanter/sqrt sd-log-part)]
(incanter/exp (incanter.stats/sample-normal n :mean mu :sd sigma))))
@jeroenvandijk
jeroenvandijk / manifold_test.clj
Last active October 5, 2016 10:39
Manifold buffer stream issue
(ns manifold-test
(:require [midje.sweet :refer :all]
[manifold.stream :as s]))
;; Observed with [manifold "0.1.6-alpha1"] and [org.clojure/clojure "1.8.0"] and Java 8
;; Used [midje "1.8.3"] for testing
(facts "about manifold.stream/buffered-stream"
(fact "Issue 1: goes over capacity when manifold.stream/put doesn't respect back pressure"
(let [s (s/buffered-stream 10)
@jeroenvandijk
jeroenvandijk / latency.txt
Created September 22, 2016 21:04 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@jeroenvandijk
jeroenvandijk / conform_unform_error.clj
Last active September 12, 2016 09:04
Case where clojure.spec/unform returns invalid result according to spec
(require '[clojure.core.specs])
(require '[clojure.spec :as s])
(s/def ::defn-macro (s/cat :type #{'defn} :definition :clojure.core.specs/defn-args))
(let [form '(defn foo "bar" ([a & b] a a c) ([a b] a))]
(-> form
(->> (s/conform ::defn-macro))) ;;=> {:type defn, :definition {:name foo, :docstring "bar", :bs [:arity-n {:bodies [{:args {:args [[:sym a]], :varargs {:amp &, :form [:sym b]}}, :body [a a c]} {:args {:args [[:sym a] [:sym b]]}, :body [a]}]}]}}
@jeroenvandijk
jeroenvandijk / multispec_vector.clj
Last active September 8, 2016 15:17
multi-spec on vectors
(require '[clojure.spec :as s])
;; WARNING: be careful with testing in the repl as reloading doesn't work AFAIK (e.g. changing the dispatch fn). You have to change the multimethod name
(do
(s/def ::action-type #{:CREATE :DELETE})
(s/def ::entity-id any?)
(s/def ::label-action (s/cat :type ::action-type
:entity-type #{:label}
:entity-id ::entity-id))
@jeroenvandijk
jeroenvandijk / user.clj
Created June 15, 2016 08:56
Repl commands for Onyx development
(ns user
(:require [clojure.tools.namespace.repl :refer [refresh]]
[com.stuartsierra.component :as component]
[onyx api
[test-helper :refer [load-config validate-enough-peers!]]]
;; Implicit requires for env
[onyx.plugin.seq]
))