View eugene_and_jeroen.clj
(ns clojure-dojo.core)
(import '[javax.imageio ImageIO]
'[java.awt.image BufferedImage])
(def img (let [f "resources/image.png"]
(ImageIO/read (clojure.java.io/file f))))
View strict_keys_spec.clj
;; If you want to fail before your old https://github.com/plumatic/schema
;; function fails the strict-keys macros below will help you find it.
(require '[clojure.spec.alpha :as s]
'[clojure.set])
(defn allowed-keys? [ks]
(fn [m]
(empty? (clojure.set/difference (set (keys m)) ks))))
View set_and_identity.md

Empty sets are always identical (apparently)

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

But when we add values this changes

(identical? #{1} #{1}) ;=> false
View alternative_dependencies.md

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
View example.clj
(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
View search.clj
(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
View sample_log_normal.clj
(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))))
View manifold_test.clj
(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)
View latency.txt
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
View conform_unform_error.clj
(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]}]}]}}