Skip to content

Instantly share code, notes, and snippets.

View Hendekagon's full-sized avatar

Matthew Chadwick (work) Hendekagon

View GitHub Profile
@Hendekagon
Hendekagon / gist:2957594
Created June 20, 2012 01:36
lamina.core.graph.propagator: error in aleph.http.core/expand-writes
lamina.core.graph.propagator: error in aleph.http.core/expand-writes
java.lang.NullPointerException
at clojure.lang.RT.intCast(RT.java:1065)
at aleph.http.core$ring_map__GT_netty_response.invoke(core.clj:341)
at aleph.http.core$expand_writes$fn__822.invoke(core.clj:177)
at lamina.core.graph.propagator$bridge_join$fn__2582.invoke(propagator.clj:162)
at lamina.core.graph.propagator.BridgePropagator.propagate(propagator.clj:57)
at lamina.core.graph.node.Node.propagate(node.clj:273)
at lamina.core.channel.SplicedChannel.enqueue(channel.clj:102)
at lamina.core$enqueue.invoke(core.clj:101)
{
:id "dev"
:source-map true
:source-map-timestamp true
:source-map-path "public/js"
:output-to "public/js/main.js"
:output-dir "public/js"
:asset-path "js"
:foreign-libs [
{:file "http://ariutta.github.io/svg-pan-zoom/dist/svg-pan-zoom.min.js"
(defmacro explanatory-cond->
"Adapted from Clojure's cond-> macro to keep a list of conditions and results"
[expr & clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep
(fn [[test step]]
`(if ~test
[(-> (if (vector? (first ~g)) (ffirst ~g) (first ~g)) ~step)
(cons [(quote ~test) (quote ~step) (first ~g)] (second ~g))]
@Hendekagon
Hendekagon / cheese-hat
Last active May 23, 2016 17:06
Add a jaunty cheese-hat to any div
div::before {
width: 3em;
top: -2.6em;
height: 3em;
transform-origin: 50% 50%;
transform: rotate(-29deg);
position: relative;
z-index: 10000000;
margin-bottom: -3em;
content: url("data:image/svg+xml;utf8,<svg height='100%' viewBox='-8 -8 16 16' width='100%' xmlns='http://www.w3.org/2000/svg'><g><rect fill='white' height='5' stroke-width='0.25' stroke='black' transform='rotate(45) translate(8,8)' width='5' x='-10.5' y='-10.5'></rect><rect fill='white' height='5' stroke-width='0.25' stroke='black' width='15' x='-7.5' y='0'></rect><text font-family='monospace' font-size='2.5' x='-5' y='3.25'>CHEESE</text></g></svg>");
(defn lca
"Last common ancestor"
[db name1 name2]
(d/q '[
:find [(pull ?anc [:db/id :name]) ...]
:in $ % ?name1 ?name2
:where
(?node1 :name ?name1)
(?node2 :name ?name2)
(anc ?anc1 ?node1)
@Hendekagon
Hendekagon / gist:bcbdbd2edc841b4c326d7060683897ac
Last active August 6, 2016 09:55
Clojure arity vs map destructure cost
(require '[criterium.core :as crit])
=> nil
(defn Q ([x y z] [x y z]) ([{:keys [x y z]}] [x y z]))
=> #'repl/Q
(crit/quick-bench (Q 4 5 6))
Evaluation count : 43141050 in 6 samples of 7190175 calls.
Execution time mean : 12.030810 ns
Execution time std-deviation : 0.313706 ns
Execution time lower quantile : 11.631011 ns ( 2.5%)
Execution time upper quantile : 12.336856 ns (97.5%)
# https://query.wikidata.org/#PREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20p%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2F%3E%0APREFIX%20ps%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20pq%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20bd%3A%20%3Chttp%3A%2F%2Fwww.bigdata.com%2Frdf%23%3E%0A%0ASELECT%20%3Fitem%20%3FitemLabel%20%3Fcountry2Label%20%3FlinkTo%0AWHERE%0A%7B%0A%09%3Fitem%20wdt%3AP47%20%3Fcountry2.%0A%20%20%09%3Fcountry2%20wdt%3AP31%20wd%3AQ6256.%0A%20%20%09%3Fitem%20wdt%3AP47%20%3FlinkTo.%0A%20%20%09SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%0A%7D
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFI
(use 'criterium.core)
=> nil
(def v1 (vec (range 1000000)))
=> #'user/v1
(def m1 (into {} (map vector (range 1000000) (range 1000000))))
=> #'user/m1
(quick-bench (get m1 71))
Evaluation count : 9861456 in 6 samples of 1643576 calls.
Execution time mean : 60.482667 ns
Execution time std-deviation : 1.681717 ns
@Hendekagon
Hendekagon / gta
Last active April 16, 2017 11:31
Cyclic tag system in Clojure
; t a list of productions, a an initial sequence
; note this halts with a NPE - it should really
; check for (empty? a) and reduced
(defn g [t a]
(reductions
(fn [[g & t] a]
(if (== 1 g) (concat t a) t))
a (cycle t)))
@Hendekagon
Hendekagon / F.st
Last active May 1, 2017 17:01
bit pattern symmetry layout for Roassal
'From Pharo3.0 of 18 March 2013 [Latest update: #30846] on 1 May 2017 at 5:58:40.759228 pm'!
Object subclass: #F
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'fredkin'!
!F commentStamp: 'mjc 3/26/2015 10:19' prior: 0!
bits
!