Skip to content

Instantly share code, notes, and snippets.

@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)
@claj
claj / cas_enum_error.clj
Created June 1, 2015 15:09
CAS/enum error in Datomic 0.9.5173
(ns traktor.error
(:require [datomic.api :as d :refer [db q]]))
(d/create-database "datomic:mem://casenum")
(def conn (d/connect "datomic:mem://casenum"))
;; simple schema
@(d/transact conn [{:db/id #db/id [:db.part/db]
@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 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's solution to Reverse Interleave
;; https://4clojure.com/problem/43
(fn [a b] (map #(take-nth b (drop % a)) (range b)))