Skip to content

Instantly share code, notes, and snippets.

(defn memoize-async
"Returns a memoized version of a referentially transparent function. The
memoized version of the function keeps a cache of the mapping from arguments
to results and, when calls with the same arguments are repeated often, has
higher performance at the expense of higher memory use.
http://stackoverflow.com/questions/24698536/"
[f]
(let [mem (atom {})]
(fn [& args]
(go
(ns clojure-nen2580.core
(:require [thi.ng.geom.core :as g]
[thi.ng.geom.line :as l))
(defn normal [l]
(let [[p q] (:points l)]
(g/normalize (g/- q p))))
(defn continuous? [a b]
(let [na (normal a)
;; -- clj macros
(defmacro defmodel
([name init [[state & args] & clauses]]
`(defmodel ~name
~(str "Reducing following messages into " name ": "
(clojure.string/join ", " (map first clauses)))
~init ([~state ~@args] ~@clauses)))
([name doc-string init [[state & args] & clauses]]
`(do
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Mouse
import Window
import Time
import Signal
main : Signal Element
{:description "FIXME: write description",
:compile-path "/tmp/test/target/classes",
:deploy-repositories
[["clojars"
{:url "https://clojars.org/repo/",
:password :gpg,
:username :gpg}]],
:group "test",
:license
{:name "Eclipse Public License",
float sdPlane(vec3 p, vec4 n) {
// n must be normalized
return dot(p, n.xyz) + n.w;
}
vec3 opTx(mat4 m, vec3 p) {
vec4 q = m * vec4(p, 1.0);
return q.xyz;
}
@skrat
skrat / foo.glsl
Created September 30, 2015 14:23
// DEPTH
varying vec3 vViewPosition;
vertex:
attribute vec3 position;
uniform mat4 proj;
uniform mat4 view;
@skrat
skrat / graph.clj
Created August 6, 2015 13:06
Some graph implementations
(ns nines.mesh
(:require [thi.ng.ndarray.core :as nd]))
(defprotocol Graph
(add-node [this x])
(set-edge [this [u v] val])
(get-edge [this [u v]])
(del-edge [this [u v]])
(neighbors [this x]))
macro @ {
case { _ $x } => {
letstx $sx = [makeValue(unwrapSyntax(#{$x}), #{here})];
return #{ Symbol.for($sx) }
}
}
function todoApp(state, action) {
if (state === undefined) state = initialState;
switch (action.type) {
a = m.map(e => m.vector.apply(null, e), a_poly.vertices)
b = m.map(e => m.vector.apply(null, e), b_poly.vertices)
m.equals(m.set(a),
m.set(b))
// you could cache the hash, so whenever and area (or polygon) is created/updated
// you would store the hash on it; inside the poly class (or Area)
v = m.map(e => m.vector.apply(null, e), this.vertices)