Skip to content

Instantly share code, notes, and snippets.

View terjesb's full-sized avatar

Terje Sten Bjerkseth terjesb

  • Outnordic
  • Norway
View GitHub Profile
@terjesb
terjesb / datomic-helpers.clj
Created November 29, 2012 15:00 — forked from bobby/datomic-helpers.clj
Some Datomic helpers I use with Ring apps
(ns datomic-helpers
(:require [clojure.java.io :as io]
[clojure.walk :as walk]
[datomic.api :as d :refer (db)]))
;;; Expose Datomic vars here, for convenience
(def tempid d/tempid)
(def connect d/connect)
(def create-database d/create-database)
@terjesb
terjesb / deps.edn
Created March 1, 2018 11:33
Pull Query
{:paths ["."]
:deps
{com.datomic/datomic-free {:mvn/version "0.9.5656"}}}
@terjesb
terjesb / logicrels-lucene.clj
Created July 26, 2012 08:39 — forked from jsmorph/logicrels-lucene.clj
Lucenalog: Datalog interface to Lucene in 10 lines
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
@terjesb
terjesb / joda-transit.clj
Created December 2, 2015 14:36 — forked from casperc/joda-transit.clj
Joda DateTime handler for Transit
;; Adds support to Transit for emitting Joda DateTimes in the same format as standard java.util.Date.
;; Dependencies: [clj-time "0.9.0"] and [com.cognitect/transit-clj "0.8.259"] (newer version will likely still work)
(require '[cognitect.transit :as transit])
(require '[clj-time.coerce :as coerce])
(import '[java.io ByteArrayOutputStream])
(def ^:private joda-time-verbose-handler
(transit/write-handler
@terjesb
terjesb / translate.clj
Created October 9, 2017 12:16 — forked from robert-stuttaford/translate.clj
Language translations for Datomic entities with fallback to base entity
(ns cognician.db.translate
(:require [datomic.api :as d])
(:import [clojure.lang MapEntry]
[datomic.query EntityMap]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Language
(def default-language :en-GB)
@terjesb
terjesb / gist:3388327
Created August 18, 2012 16:52 — forked from jsnikeris/gist:3386949
Macro for defining Datomic database functions
(require '[datomic.api :as d])
(defn maybe-assoc [m k v]
(if v (assoc m k v) m))
(defmacro defn-db [name & args]
(let [[doc-string & args] (if (string? (first args)) args (cons nil args))
[attr-map & args] (if (map? (first args)) args (cons {} args))
[[& params] & body] args
@terjesb
terjesb / feed.clj
Created November 26, 2016 17:01 — forked from hlship/feed.clj
(def payment-codes-per-block 4096)
(defn create-payment-code-feed
[db]
(let [payment-code-feed (chan 10)]
(go-loop []
(let [block-id (allocate-block db)
block-start (* block-id payment-codes-per-block)]
(-> (onto-chan payment-code-feed
(->>

Keybase proof

I hereby claim:

  • I am terjesb on github.
  • I am terjesb (https://keybase.io/terjesb) on keybase.
  • I have a public key ASCs6Fb0IkKiaWnHlzmw-wss8s4NI5EUOs8k-wynxTREwgo

To claim this, I am signing this object:

@terjesb
terjesb / gist:8494273
Created January 18, 2014 18:28 — forked from bpsm/gist:613279
(ns bpsmannschott
(:import java.io.File)
(:import java.io.FileNotFoundException))
(defn as-file [s]
"Return whatever we have as a java.io.File object"
(cond (instance? File s) s ; already a file, return unchanged
(string? s) (File. s) ; return java.io.File for path s
:else (throw (FileNotFoundException. (str s)))))
(defn optify
"Helper that examines paths with the supplied prefix and either subs
in their cache-busting URLs or returns them unchanged."
[req prefix]
(fn [^String src]
(or (and (.startsWith src prefix)
(not-empty (link/file-path req src)))
src)))