Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 12:13 (UTC +02:00)
View GitHub Profile
@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 / 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's solution to Reverse Interleave
;; https://4clojure.com/problem/43
(fn [a b] (map #(take-nth b (drop % a)) (range b)))
;; claj's solution to Set Intersection
;; https://4clojure.com/problem/81
(fn [a b] (set (filter a b)))
;; 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
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
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 / 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!")