Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 06:37 (UTC +02:00)
View GitHub Profile
@claj
claj / alephNoir.clj
Created October 3, 2011 06:37 — forked from ibdknox/alephNoir.clj
aleph and noir
(require '[noir.server :as server])
(use 'noir.core 'aleph.http 'lamina.core)
(defn async-response [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
:body "async response"}))
(defpage "/" [] "hey from Noir!")
@claj
claj / dsstuff.clj
Created December 3, 2011 23:57
duck-stream stuff
(ns dsstuff
"things i used to do in duckstreams in clojure 1.2.0")
;;read-lines from files
(defn read-lines-from-file [filename]
(with-open [rdr (clojure.java.io/reader filename)]
(line-seq rdr)))
;;thank you Abhinav Sarkar (http://stackoverflow.com/questions/4118123/read-a-very-large-text-file-into-a-list-in-clojure)
@claj
claj / testoi.clj
Created January 20, 2012 12:56
create mongoId
(ns testoi)
;; http://api.mongodb.org/java/2.6.3/org/bson/types/ObjectId.html
testoi> (import 'org.bson.types.ObjectId)
org.bson.types.ObjectId
testoi> (ObjectId. "d1700430f92f194fad7ce85a")
#<ObjectId d1700430f92f194fad7ce85a>
;; claj's solution to Anagram Finder
;; https://4clojure.com/problem/77
(fn [a]
(set
(map set
(filter #(< 1 (count %))
(vals
(group-by
(fn [b] (reduce conj #{} b))
;; claj's solution to Set Intersection
;; https://4clojure.com/problem/81
(fn [a b] (set (filter a b)))
;; claj's solution to Reverse Interleave
;; https://4clojure.com/problem/43
(fn [a b] (map #(take-nth b (drop % a)) (range b)))
@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)