Skip to content

Instantly share code, notes, and snippets.

View angerman's full-sized avatar
🇸🇬

Moritz Angermann angerman

🇸🇬
View GitHub Profile
(ns survey.maruku
(:import javax.script.ScriptEngineManager javax.script.Invocable))
;; setup jruby
(System/setProperty "jruby.base", "/Users/angerman/Library/JRuby")
(System/setProperty "jruby.home", "/Users/angerman/Library/JRuby")
(System/setProperty "jruby.lib", "/Users/angerman/Library/JRuby/lib")
(System/setProperty "jruby.script", "jruby")
(System/setProperty "jruby.shell", "/bin/sh")
<project name="emendio-survey-clj" basedir="." default="test">
<property environment="env" />
<property name="sdk.dir" location="${user.home}/Library/appengine-java-sdk-1.2.2" />
<property name="classes.dir" value="war/WEB-INF/classes" />
<property name="lib.dir" value="war/WEB-INF/lib" />
<property name="src.dir" value="src" />
<property name="test.dir" value="test" />
<property name="clojure.dir" value="${user.home}/Library/Clojure" />
<property name="jruby.dir" value="${user.home}/Library/JRuby"/>
# Installed TC to follow the following
# http://justin.harmonize.fm/index.php/tag/tokyo-cabinet/
# - Tokyocabinet: tokyocabinet-1.4.29
# - Java binding: tokyocabinet-java-1.22
$ export PREFIX=$HOME/Library/TokyoCabinet
$ export CFLAGS="-I${PREFIX}/include -arch x86_64"
$ export LDFLAGS="-L${PREFIX}/lib"
Checking out source... this will take a while...
Initialized empty Git repository in /Users/angerman/Library/Clojure/clojure/.git/
Initialized empty Git repository in /Users/angerman/Library/Clojure/clojure-contrib/.git/
Initialized empty Git repository in /Users/angerman/Library/Clojure/swank-clojure/.git/
Initialized empty Git repository in /Users/angerman/Library/Clojure/slime/.git/
Note: moving to 'origin/1.0' which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at c045881... move 1.0 to 1.0.1 alpha
(def *filters* {'= Query$FilterOperator/EQUAL
'> Query$FilterOperator/GREATER_THAN
'>= Query$FilterOperator/GREATER_THAN_OR_EQUAL
'< Query$FilterOperator/LESS_THAN
'<= Query$FilterOperator/LESS_THAN_OR_EQUAL})
;; query kind where (= :name x)
;; -> (.addFilter (Query. "Item") :name ('= *filters*) x)
(defmacro query [kind _ filters] `(.addFilter (Query. ~kind)
~(name (nth filters 1))
(import [javax.sound.sampled AudioSystem DataLine$Info SourceDataLine])
(defn audio-copy [input output] ;; copy-n-past from duck-streams 'copy
(let [buffer (make-array Byte/TYPE *buffer-size*)]
(loop []
(let [size (.read input buffer)]
(when (pos? size)
(do (.write output buffer 0 size)
(recur)))))))
;; Worker agents are there to be dipatched to, they state should be incremented
;; on each completed work unit
(def *worker* (map #(agent -1 :meta {:no %}) (range 5)))
;; a simualted work unit for the worker
(defn work-unit [s n]
(Thread/sleep 1000)
;;(send printer println+ (format "%s: %d" (str *agent*) n))
(inc s))
(defn job [state source experiment]
(let [head (format "%d" (get ((keyword source) *experiment-to-subtypeid*) experiment))
value-fmt " %d:%f"
min (ref head)
avg (ref head)
max (ref head)
i (atom 1)
row-worker (fn [row]
(alter min str (format value-fmt @i (:min row)))
(alter avg str (format value-fmt @i (:avg row)))
;; LibSVM Model parser.
(use 'clojure.contrib.duck-streams)
(use 'clojure.contrib.seq-utils)
(require '[clojure.contrib.str-utils2 :as s])
(def *root* "/data/")
;; (set! *print-length* 5) eval in repl
(defn model-file [name] (str *root* name))
(defn combine [A B]
(loop [a+ A
b+ B
acc []]
(let [a (first a+)
b (first b+)]
(if (not a) ;; list a ended
(concat acc b+)
(if (not b) ;; list b ended
(concat acc a+)