Skip to content

Instantly share code, notes, and snippets.

Avatar
😀
Eating nachos

Alex Miller puredanger

😀
Eating nachos
View GitHub Profile
@puredanger
puredanger / # clojure - 2020-01-30_14-27-00.txt
Created Feb 21, 2020
clojure on macOS 10.15.2 - Homebrew build logs
View # clojure - 2020-01-30_14-27-00.txt
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 Feb 21, 2020
clojure on macOS 10.15.2 - Homebrew build logs
View # clojure - 2020-01-30_14-27-00.txt
Homebrew build logs for clojure on macOS 10.15.2
Build date: 2020-01-30 14:27:00
@puredanger
puredanger / dump.clj
Last active Nov 20, 2017
Dumping a var meta table
View dump.clj
;; 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 Jun 22, 2017
fspec missing gen
View ex.clj
(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)
View gist:4ca8fd95bcdee0601f09410b4b2f85c2
;; 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
View gist:88d0491cbb4dbf8fe98b3747963d0068
(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 Aug 20, 2016
Twitter responses
View discussion.md

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 Sep 10, 2015
Example of using gen-class to subclass a class with multi-arity method
View ByteInputStream.clj
(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]
View gist:83f66f157f56bc9db845
compare perf of reduce and mapv on small vectors - testing worst case of size 6
## 1.7.0
vecperf.bench=> (def v [0 1 2 3 4 5])
#'vecperf.bench/v
vecperf.bench=> (quick-bench (reduce + 0 v))
WARNING: Final GC required 1.508801076780115 % of runtime
WARNING: Final GC required 13.47335649374595 % of runtime
Evaluation count : 11114412 in 6 samples of 1852402 calls.
View gist:40dd3ec22fdb5836d1eb
This file has been truncated, but you can view the full file.
Compiled from "eclipse.clj"
public final class ccw.eclipse$goto_editor_line extends clojure.lang.AFunction {
public static final clojure.lang.Var const__0;
public static final clojure.lang.Var const__1;
public static final clojure.lang.Keyword const__2;
public static final clojure.lang.Keyword const__3;
You can’t perform that action at this time.