Skip to content

Instantly share code, notes, and snippets.

View puredanger's full-sized avatar
😀
Clojure is life

Alex Miller puredanger

😀
Clojure is life
View GitHub Profile
{:paths ["."]
:deps {org.clojure/data.json {:mvn/version "2.4.0"}}}
@puredanger
puredanger / # clojure - 2020-01-30_14-27-00.txt
Created February 21, 2020 14:56
clojure on macOS 10.15.2 - Homebrew build logs
Homebrew build logs for clojure on macOS 10.15.2
Build date: 2020-01-30 14:27:00
@puredanger
puredanger / # clojure - 2020-01-30_14-27-00.txt
Created February 21, 2020 14:52
clojure on macOS 10.15.2 - Homebrew build logs
Homebrew build logs for clojure on macOS 10.15.2
Build date: 2020-01-30 14:27:00
@puredanger
puredanger / dump.clj
Last active November 20, 2017 07:36
Dumping a var meta table
;; Prints a table of vars in an ns with name/line/added/macro flag/deprecated flag
(defn pr-vars [ns-sym]
(->> (ns-publics ns-sym) vals (map meta) (sort-by :name)
(map #(select-keys % [:name :line :added :macro :deprecated]))
(map #(merge {:added nil :macro false :deprecated false} %))
clojure.pprint/print-table))
(pr-vars 'clojure.string)
;; | :added | :macro | :deprecated | :name | :line |
@puredanger
puredanger / ex.clj
Last active June 22, 2017 15:57
fspec missing gen
(require '[clojure.spec.alpha :as s] '[clojure.spec.test.alpha :as stest])
(s/def ::cb (s/fspec :args (s/cat :e #(instance? Throwable %))))
(s/fdef foo :args (s/cat :e ::cb))
(defn foo [e])
(stest/instrument `foo)
(foo (fn [e] e))
ExceptionInfo Unable to construct gen at: [:e] for: (instance? java.lang.Throwable %) clojure.core/ex-info (core.clj:4727)
;; for the use case where same key is transformed through stage
(s/def :st1/a int?)
(s/def :st2/a string?)
(defn validate-map [stage m]
(every? (fn [[k v]] (s/valid? (keyword stage (name k)) v)) m))
(validate-map "st1" {:a 100}) ;; true
(validate-map "st2" {:a "abc"}) ;; true
(def v0 [])
(def v10 (vec (range 10)))
(def v100 (vec (range 100)))
(def v1000 (vec (range 1000)))
(quick-bench (reduce + v0)) ;; 2 ns
(quick-bench (apply + v0)) ;; 29 ns
(quick-bench (reduce + v10)) ;; 216 ns
(quick-bench (apply + v10)) ;; 392 ns
(quick-bench (reduce + v100)) ;; 2.13 µs
@puredanger
puredanger / discussion.md
Created August 20, 2016 04:50
Twitter responses

Hi Brian,

Twitter is terrible for this conversation due to non-threaded replies, the use of embedded images (instead of actual code), and the inability to reply to anything in more than 140 char chunks, so I am putting this in a gist for my own sanity. The ideal place to have this conversation is on the Clojure mailing list, where many people can both contribute to and benefit from a threaded discussion, with a searchable archive. I'd prefer any follow-ups go there.

  1. https://twitter.com/marick/status/766766153712697345 If I reported that the attached worked fine for many versions, but fails in alpha111 what would happen?
@puredanger
puredanger / ByteInputStream.clj
Created September 10, 2015 22:03
Example of using gen-class to subclass a class with multi-arity method
(ns example.ByteInputStream
(:gen-class
:extends java.io.InputStream
:state byteseq
:init init
:constructors {[clojure.lang.Seqable] []}
:exposes-methods {read readSuper}
:main false))
(defn -init [byte-seq]