Skip to content

Instantly share code, notes, and snippets.

{ :animatable sphere
:animation {:rotation
{:x (partial + 0.075)
:y (partial + 0.025)
:z (partial + 0.050)
:position
{:x #(js/Number (.toFixed (mod (+ % 0.025) 1) 2))}}}
(extend-type Mesh
IRenderable
IAnimatable
(animate! [this options]
(doto this
(apply-nested! options))))
defn pmap
"Like map, except f is applied in parallel. Semi-lazy in that the
parallel computation stays ahead of the consumption, but doesn't
realize the entire result unless required. Only useful for
computationally intensive functions where the time of f dominates
the coordination overhead."
{:added "1.0"
:static true}
([f coll]
(let [n (+ 2 (.. Runtime getRuntime availableProcessors))
@aamedina
aamedina / gist:6025882
Created July 18, 2013 00:51
opencl stupid toy kernel
const sampler_t sampler =
CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_NEAREST | CLK_ADDRESS_CLAMP_TO_EDGE;
float add_color(float color) {
return color + 0.75;
}
__kernel void identity(read_only image2d_t inputImage,
write_only image2d_t outputImage) {
translation-unit:
external-declaration+
external-declaration:
<ws> function-definition <ws> |
<ws> declaration <ws>
function-definition:
declaration-specifiers <ws> declarator <ws> declaration-list? <ws> compound-statement
declaration-list:
(<ws> declaration)+ <ws>
ws:
(defmacro pub!
[coll port-key val]
`(cljs.core.async/put! (~port-key (:channels (meta ~coll))) ~val))
(defmacro sub!
[[coll port-key] & body]
`(go! ;; this is just an infinite (go) loop, waiting for stuff to be pushed onto the channel
(let [~coll (cljs.core.async/<! (~port-key (:channels (meta ~coll))))]
~@body)))
(defn page!
[init-res req]
(reduce
(fn [coll n]
(if (not (= (mod (count coll) 200) 0)) (reduced coll)
(let [req (update-in
req [:query-params]
merge
{:since_id (:id_str (last coll))})]
(into coll (<!! (async-request req))))))
(defn page!
[init-res req page-size]
(reduce
(fn [coll n]
(let [req (update-in
req [:query-params]
merge
{:max_id (:id_str (first coll))})
res (<!! (async-request req))
new-coll (into coll res)]
(defn page!
[init-res req]
(go
(loop [coll (into (sorted-set-by #(compare (:id %1) (:id %2))) init-res)]
(let [req (update-in
req [:query-params]
merge
{:max_id (:id_str (first coll))})
res (<! (async-request req))
new-coll (into coll res)]
(defn foldl
[f init xs]
(println xs)
(cond (empty? xs) (f)
(nil? init) (recur (partial f (first xs)) nil (rest xs))
:else (recur (partial f init (first xs)) nil (rest xs))))
(foldl + 0 (range 10))
(0 1 2 3 4 5 6 7 8 9)
(1 2 3 4 5 6 7 8 9)