Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 20:38 (UTC +02:00)
View GitHub Profile
@claj
claj / testblog.clj
Created July 11, 2013 12:21
Testing embedding GIST in my blog
(use 'hello)
(println "hello world!")
(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)}))
(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)))
@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]))
@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 / 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 / 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 / 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 / example.clj
Last active August 29, 2015 14:05
Steam-roller function
(steam-roller [:a {1 2 3 4} 1 1 :a :a])
-> ([:a {1 2, 3 4} 1 1 :a :a] :a {1 2, 3 4} 1 3 2 4 1 1 :a :a)
count: 11
;;identityHashCodes:
(map #(System/identityHashCode %) (steam-roller [:a {1 2 3 4} 1 1 :a :a]))
(1460028191
2005509007
1545655515
504432400
@claj
claj / init.el
Created May 25, 2015 11:26
emacs clojure toolbox setup
;; put this in ~/.emacs.d/init.el :
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)