Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 07:48 (UTC +02:00)
View GitHub Profile
@claj
claj / clojurerng.clj
Created May 12, 2014 19:58
Testing RNG
(ns clojurerng.core
(:import [com.modp.random LinearSunJDK])
(:use [ criterium.core]))
(def ^:LinearSunJDK linsun (LinearSunJDK.))
;;this is salvaged from
;; javarng.googlecode.com/svn/trunk/com/modp/random/LinearSunJDK.java
;;and the openJDK source code for .nextDouble
@claj
claj / enlive_vs_unicode.clj
Last active January 1, 2016 09:49
Enlive with special unicode characters - it's possible
;;create a lein new something
;;add [enlive "1.1.5"] to project.clj
;;lein repl:
(use 'net.cgrand.enlive-html)
;;define a simple template "inline"
(deftemplate abc
(java.io.StringReader.
"<html>
@claj
claj / countertest.clj
Created September 26, 2013 08:47
Testing performance on clojure atom vs java.util.concurrent.atomic.AtomicInteger counters.
(ns countertest)
(set *warn-on-reflection* true)
(def atom-cnt (atom 0))
(time (dotimes [_ 1e6] (swap! atom-cnt inc)))
;; 156 ms
(def ^java.util.concurrent.atomic.AtomicInteger atomic-integer-counter (java.util.concurrent.atomic.AtomicInteger. 0))
@claj
claj / kibit-arithmetic-rules.clj
Created September 11, 2013 16:57
Some rules I've found useful in Kibit.
;;trivial identites
[(+ ?x 0) ?x]
[(- ?x 0) ?x]
[(* ?x 1) ?x]
[(/ ?x 1) ?x]
[(* ?x 0) 0]
;;Math/pow
[(* ?x ?x) (Math/pow ?x 2) ]
[(* ?x ?x ?x) (Math/pow ?x 3) ]
@claj
claj / heatmapfromarray.clj
Last active December 22, 2015 11:09
John Szakmeister asked for a way to show matrixes in the Incanter google group. I gave a bad suggestion wrapping it in a function, which is to complicated things severly. Here's a modified version of incanter.chart/heat-map* which eats a vector-of-vectors of data and a nil-value. https://groups.google.com/forum/#!topic/incanter/spyQuB5c87k The d…
;;This is released under EPL (same as Clojure) and is most
;;welcomed to be included to Incanter or anything else
;;after some bettering (it would be nice to be able
;;to push DefaultXYZDatasets into the heat-map-thing
;;instead of function + xy-box
(ns heatmapfromarray
"show an vector-of-vectors without missing important parts of it"
(use [incanter core charts]))
(use 'seesaw.core)
;; the state, when was the last keypress?
(def last-tap (atom nil))
(defn nanoseconds-diff-to-bpm [now then]
(let [nanosecs-in-a-minute (* 60 1000 1000 1000.0)
diff (- now then)]
(/ nanosecs-in-a-minute diff)))
(ns async-math)
(require '[clojure.core.async :as async :refer :all])
(defn query-maker
"generates a simple math-query and the answer to it"
[]
(let [a (rand-int 10) b (rand-int 10)]
{:query (str "what is " a " + " b "?")
:answer (+ a b)}))
@claj
claj / testblog.clj
Created July 11, 2013 12:21
Testing embedding GIST in my blog
(use 'hello)
(println "hello world!")
@claj
claj / no-cardinality-stacktrace
Created October 22, 2012 15:02
When transcating a datomic attribute without cardinality attribute the following stacktrace occurs
java.util.concurrent.ExecutionException: java.lang.Error: Assert failed: (every? identity [key vtypeid cardinality])
at datomic.common$throw_executionexception_if_throwable.invoke (common.clj:381)
datomic.common$promise$reify__253.get (common.clj:423)
datomic.common$promise$reify__253.deref (common.clj:431)
clojure.core$deref.invoke (core.clj:2117)
datomic.peer.Connection.transact (peer.clj:106)
datomic.api$transact.invoke (api.clj:63)
datest.core$eval935.invoke (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6603)
clojure.lang.Compiler.eval (Compiler.java:6566)
@claj
claj / swarmec2.txt
Created September 19, 2012 11:04
Swarm on EC-2
How to get started with a swarm-setup on EC-2
=============================================
Launch instance
---------------
Switch to the close region (EU West for us).
Start an EC-2 instance, I selected Ubuntu 12 server, Small instance type.