Empty sets are always identical (apparently)
(identical? #{} #{}) ;=> true
But when we add values this changes
(identical? #{1} #{1}) ;=> false
;; 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)))) |
Empty sets are always identical (apparently)
(identical? #{} #{}) ;=> true
But when we add values this changes
(identical? #{1} #{1}) ;=> false
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.
(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 |
(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 |
(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)))) |
(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) |
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 |
(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]}]}]}} |
(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)) |