Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
@swannodette
swannodette / web.clj
Created April 1, 2010 13:19 — forked from devn/web.clj
(ns defn-test
(:use clj-html.core
[net.cgrand.moustache :only [app]]
[ring.adapter.jetty :only [run-jetty]]
[ring.util.response :only [response]]))
(defhtml application [text body]
[:html
[:head
[:title text]]
(ns vector-math.core
(:import [javax.vecmath Vector2d]))
(defprotocol Vec2Math
(add [this other]))
(deftype vec2
[#^float x #^float y] :as this
Vec2Math
(add [other] (vec2. (+ x (.x #^vec2 other))
(ns vector-math.core
(:import [javax.vecmath Vector2d]))
(def epsilon 1e-6)
(defprotocol Vec2Math
(add [this other])
(sub [this other])
(mul [this scalar])
(div [this scalar])
(ns flocking.flocking3
(:use [vecmath.vec2 :only [vec2 zero sum]]
clojure.contrib.pprint)
(:require [rosado.processing :as p]
[rosado.processing.applet :as applet]
[vecmath.core :as vm]))
(deftype dist-boid
[loc vel acc r max-speed max-force dist]
clojure.lang.IPersistentMap)
(use '[clojure.walk :only [postwalk]])
(use '[clojure.contrib.macro-utils :only [mexpand-all]])
(defn casted? [expr]
(when-let [[_ x] expr]
(when (and (coll? x) (#{'float 'int 'double 'long 'short 'byte} (first x)))
true)))
(defn to-prim-op [type]
(fn [expr]
(defn pearson-fast
[v1 v2]
(let [v1 (doubles v1)
v2 (doubles v2)
dim (double (count v1))
meanv1 (/ (areduce v1 i ret 0
(+ ret (aget v1 i))) dim)
meanv2 (/ (areduce v2 i ret 0
(+ ret (aget v2 i))) dim)
sum (areduce v1 i ret 0
; from Learn You A Haskell Real Good
; rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24 ]
(def right-triangles
(let [r (range 1 11)]
(for [c r
b r :when (< b c)
a r :when (< a b)
:when (and (= (+ (* a a) (* b b)) (* c c))
(= (+ a b c) 24))]
(ns cellular-automata-basic)
(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]))
(defprotocol Automata
(update [this]))
(definterface IntToIntFn
(#^int call [^int n]))
(def fibr
(let [one (int 1)
two (int 2)]
(reify
IntToIntFn
(call [this n]
(if (>= one n) one (+ (.call this (dec n)) (.call this (- n two))))))))
(defn ^:static sum-8-neighbors ^long [dv ^long i ^long j ^long ncols]
(let [dv (longs dv)
v (longs (let [v1631 (longs (make-array Long/TYPE 8))]
(aset v1631 0 (aget dv (+ (* (dec i) ncols) (dec j))))
(aset v1631 1 (aget dv (+ (* (dec i) ncols) j)))
(aset v1631 2 (aget dv (+ (* (dec i) ncols) (inc j))))
(aset v1631 3 (aget dv (+ (* i ncols) (inc j))))
(aset v1631 4 (aget dv (+ (* (inc i) ncols) (inc j))))
(aset v1631 5 (aget dv (+ (* (inc i) ncols) j)))
(aset v1631 6 (aget dv (+ (* (inc i) ncols) (dec j))))