Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
@jeroenvandijk
jeroenvandijk / user.clj
Created June 15, 2016 08:56
Repl commands for Onyx development
(ns user
(:require [clojure.tools.namespace.repl :refer [refresh]]
[com.stuartsierra.component :as component]
[onyx api
[test-helper :refer [load-config validate-enough-peers!]]]
;; Implicit requires for env
[onyx.plugin.seq]
))
@jeroenvandijk
jeroenvandijk / nrepl_port.clj
Created June 8, 2016 13:45
Finds nrepl port of repl
;; From https://github.com/ChrisBlom/dotfiles/blob/132db1a82d012dc495f762654b544b7c3a82d844/lein/tracetool.clj#L10
(def pid
"Get current process PID"
(memoize
(fn []
(-> (java.lang.management.ManagementFactory/getRuntimeMXBean)
(.getName)
(clojure.string/split #"@")
(first)))))
@jeroenvandijk
jeroenvandijk / compiled-get-in.clj
Created May 4, 2016 07:49
Compiled get-in for optimizing get-in for arguments defined at runtime (no macro expansion)
(defn compile-get-in [path]
(let [f (reduce
(fn [acc k]
(fn [m] (get (acc m) k)))
identity path)]
(fn [m]
(f m))))
(let [m {:a {:b 1}}]
(time (dotimes [i 100000]
@jeroenvandijk
jeroenvandijk / aleph.sse.clj
Last active May 28, 2016 05:58
Server Side Events with Aleph
(comment
;; Deps
[cheshire "5.4.0"]
[manifold "0.1.1"]
[aleph "0.4.1-beta2"]
[org.clojure/clojure "1.7.0"]
[org.clojure/core.async "0.2.371"]
)
(require '[clojure.core.async :as a]
@jeroenvandijk
jeroenvandijk / datomic.schema_dump.clj
Last active January 23, 2020 10:58
(A) method to dump a datomic database schema
(ns datomic.schema-dump
(:require
[datomic.api :as d]
[clojure.pprint]))
(defmethod clojure.pprint/simple-dispatch datomic.db.DbId [v] (pr v))
(defmethod clojure.pprint/simple-dispatch datomic.function.Function [v] (pr v))
(defn database-url [name]
(str "datomic:mem://" name))
@jeroenvandijk
jeroenvandijk / mock-connection.clj
Created October 21, 2015 11:13 — forked from vvvvalvalval/mock-connection.clj
Mocking datomic.Connection for fast in-memory testing
(ns bs.utils.mock-connection
"Utilities for using Datomic"
(:require [datomic.api :as d])
(:use clojure.repl clojure.pprint)
(:import (java.util.concurrent BlockingQueue LinkedBlockingDeque)
(datomic Connection)))
(defrecord MockConnection
[dbAtom, ^BlockingQueue txQueue]
@jeroenvandijk
jeroenvandijk / kahn.clj
Created October 4, 2015 09:52 — forked from alandipert/kahn.clj
Kahn's topological sort in Clojure
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
@jeroenvandijk
jeroenvandijk / update.clj
Created October 2, 2015 08:38
Illustration of problem with update and infinite/large lazy sequences
(defn alt-update [m k f]
;; Don't hold on to the old value of k by setting it to nil before the update
(assoc (assoc m k nil)
k (f (get m k))))
(doseq [f [alt-update update]
n [10
100
1000
10000
@jeroenvandijk
jeroenvandijk / incanter.clj
Last active October 2, 2015 15:20
Incanter transducer prototype
(ns adgoji.incanter.core
(:require [incanter.core :as incanter]))
(defn update-dataset [col-fn row-fn {:keys [column-names rows] :as dataset}]
(assoc (assoc dataset :rows nil)
:column-names (col-fn column-names)
:rows (row-fn rows)))
(defn wrap-with-transducer [xf]
(fn [coll] (sequence xf coll)))
@jeroenvandijk
jeroenvandijk / group_by.clj
Last active October 1, 2015 07:56 — forked from fxposter/group_by.clj
group-by as a transducer
(defn group-by
([f]
(fn [rf]
(let [grouped-value (volatile! (transient {}))]
(fn
([] (rf))
([result]
(rf result (persistent! @grouped-value)))
([result input]
(let [key (f input)]