Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
(ns cellular-automata-basic)
(defrecord cellular-automaton [^long nrows ^long ncols data-vector])
(defn random-ca
[nrows ncols n]
(cellular-automaton.
nrows
ncols
(let [a (longs (make-array Long/TYPE (* nrows ncols)))]
(ns unchecked-remainder-test)
(defn create-test-ary []
(let [a (longs (make-array Long/TYPE 100))]
(amap a i result
(aset result i (long (rand-int 100))))))
(defn ^:static test-map [ary]
(amap ary idx result
(let [i (unchecked-remainder idx 4)
(definterface Foo
(^long bar [^long a ^long b]))
(defrecord Baz []
Foo
(bar [_ a b] (+ a b)))
(def x (Baz.))
(bar x 1 2) ; Unable to resolve symbol bar in this context
// ================== Highlights.html
<span class="TableContainer">
<span class="HighlightsSummary"></span>
<input class="HighlightsInput"></input>
<span class="HighlightsColors">
<% (6).times(function(i) { %>
<span class="GenericHighlightsColor HighlightsColor<%= i+1 %>"></span>
<% }); %>
(ns prim-this-bug)
(set! *warn-on-reflection* true)
(defprotocol VecMath
(add [this other])
(sub [this other]))
(defrecord Point [^double x ^double y]
VecMath
(let [{type :type many-side :table} (find-join-by (:model db) table :alias (first joins))
attrs (column-seq db many-side req-attrs)]
(defn test-array [n]
(let [a (longs (make-array Long/TYPE n))]
(amap a i result
(aset result i (rand-int 2)))))
(test-array 100) ; No matching method found: aset [Thrown class java.lang.IllegalArgumentException]
(defn test-array [n]
(let [a (longs (make-array Long/TYPE n))]
(amap a i result
(aset result i (long (rand-int 2))))))
(def bigv (into [] (range 1000000)))
; ~5s
(dotimes [_ 10]
(time
(dotimes [_ 10]
(doall (map inc bigv)))))
; ~1s
(dotimes [_ 10] (time (count (doall (map inc (range 1000000))))))
(ns cellular-automata-basic)
(set! *warn-on-reflection* true)
(definterface AutomataOps
(^long getCell [^long i ^long j])
(^long sumEightNeighbors [^long i ^long j])
(^long urEightNeighMinmax [^long i ^long j])
(^long rule [^long i ^long j]))
(defmacro time2 [expr times]
`(time (dotimes [_# ~times] ~@expr)))
; -------------------------------------
(time2 (+ 1 2) 100)
; expands to ->
(let*