Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 14:27 (UTC +02:00)
View GitHub Profile
@claj
claj / baremud.clj
Created February 12, 2012 22:15
baremud.clj
(ns joy.baremud
(:require [clojure.set :as set]))
;;My apartment consists of
(def graph [#{:myroom :hallways} ;;my-room, connected to hallways
#{:hallways :bathroom} ;;the bathroom, connected to hallways
#{:otherroom :hallways :kitchen} ;;a loop with otherroom, kitchen, hallways all connected
#{:hallways :stairs} ;;a door out to the stairs
#{:stairs :elevator}]) ;;in the stairs there's an elevator
@claj
claj / refsymbols.clj
Created July 17, 2012 23:17
Generate datom :db.type/ref s with fn
(use '[datomic.api :only [db q] :as d])
;;LOOK IN THE BOTTOM FOR CORRECT USE OF DATOMIC :)
;;not supplied:
;;* connecting to a db named "conn"
;; (checkout awesome Jonas Edlunds gist
;; for inspiration: https://gist.github.com/3122363 )
;;* a schema that fit's the following person-datoms
@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.
@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)
(ns path-with-enlive-example
(:require [net.cgrand.xml :as xml]
[clojure.zip :as z]))
;; This is meant to be answer to the question
;; "Enlive as a hammer" posted in the enlive mailing list:
;; https://groups.google.com/forum/#!topic/enlive-clj/Da0l_Vpu05U
;; div
;; | :content
@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) ]