Skip to content

Instantly share code, notes, and snippets.

(ns testapp.core
(:require
[criterium.core :as cr]
[primitive-math :as p]
[no.disassemble :as nd]))
(set! *warn-on-reflection* true)
(defn ^double test0 [a b]
(let [^doubles a a
@si14
si14 / core.clj
Created March 1, 2014 22:00
Visualizing "Missionaries and cannibals" problem
(ns mercanviz.core
(:require
[clojure.string :as s]
[hiccup.core :as h]
[clojure.data.priority-map :as pm])
(:gen-class))
(defn update-state [state & updates]
(reduce (fn [acc [key op]]
(update-in acc [key] op))
@si14
si14 / tmp.erl
Created November 13, 2013 12:44
-module(tmp).
-behaviour(gen_server).
%% API
-export([start_link/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-module(foobar_tests).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
prop_delete() ->
?FORALL({X,L}, {integer(),list(integer())},
not lists:member(X, lists:delete(X, L))).
proper_test() ->
?assertEqual(
(defrecord GHCache [^TTLCache ttl-cache etagged cleaner-c])
(defn init-cache []
(let [control-c (chan)
old-killer (fn [etagged]
(let [now (System/currentTimeMillis)]
(->> etagged
(filter #(> (- now (-> % value :created-at))
(* 6 60 60 1000)))
(into {}))))
curl -XPOST -d "source=`git config user.name`&from_address=`git config user.email`&subject=pushed to production&content=`git log --pretty=format:'%s %H' -n 1`" https://api.flowdock.com/v1/messages/team_inbox/YOUR_TOKEN_GOES_HERE
@si14
si14 / code.clj
Created September 23, 2013 20:38
(defn gaussian [m mu gamma]
(let [m (mp/clone m)
t (/ 1 (* gamma (Math/sqrt (* 2 Math/PI))))]
(magic/specialize :double
(loop-over [m]
(let [x (aget m-data m-idx)
exparg (* -0.5 (Math/pow (/ (- x mu) gamma) 2))
g (* t (Math/exp exparg))]
(aset m-data m-idx g))))))
(defn tags-types [form]
(clojure.walk/prewalk
(fn [form]
(when-let [m (meta form)]
(when-let [t (:tag m)]
(prn m t (type t))))
form)
form))
;; enable printing of meta in repl with (set! *print-meta* true)
(def test-form1
'(let [^String a "a"]
:ok))
(def test-form2
`(let [^String ~'a "a"]
:ok))
(def test-form3
`(let [^String a# "a"]
@si14
si14 / examples.md
Last active December 20, 2015 12:29

NDArray examples

An obvious stuff:

> (identity-matrix :ndarray 3)
#<NDArray [[1.0 0.0 0.0] [0.0 1.0 0.0] [0.0 0.0 1.0]]>
> (identity-matrix :ndarray-long 3)
#<NDArrayLong [[1 0 0] [0 1 0] [0 0 1]]>
> (identity-matrix :ndarray-double 3)