Skip to content

Instantly share code, notes, and snippets.

View rauhs's full-sized avatar

Andre W. rauhs

  • Bavaria, Germany
View GitHub Profile
(ns srs-c.utils.keyboard
(:require-macros
[klang.macros :refer [log! debg! trac! info! warn! erro! crit! fata! env!]]
[srs-c.macros :refer [onlydev onlyprod]])
(:require [goog.events])
(:import [goog.ui KeyboardShortcutHandler]))
(defn install-shortcut!
"Installs a Keyboard Shortcut handler.
SHELL=/bin/bash
NGINX:=$(abspath software/nginx/sbin/nginx)
CONF:=$(abspath conf/nginx.conf)
OPENRESTY_V:=1.9.15.1
OPENRESTY_F:=openresty-$(OPENRESTY_V)
OPENRESTY_RUN_DIR:=$(PWD)/openresty
.PHONY: def_target run reload stop auto-reload
@rauhs
rauhs / datomic-squuid.lua
Last active June 24, 2016 10:09
Generate a squuid in nginx (openresty)
-- Datomic SQUUID layout:
-- xxxxxxxx-xxxx-4xxx-Vxxx-xxxxxxxxxxxx
-- ^^^^^^^^ ^^^^ ^
-- | | |^^^ ^
-- | | | | |^^^-^^^^^^^^^^^^
-- | | | | | |
-- | | | | | |- random
-- | | | | |- IETF variant {8,9,a,b}
-- | | | |- random
-- | | |- Version 4
(spec/def :datascript.db/id int?)
(spec/def :datomic.db/id #(instance? DbId %))
(spec/def :db/id (spec/or :datascript :datascript.db/id
:datomic :datomic.db/id))
(defn datomic-id?
"Checks a conformed spec and ensures the :db/id was a datomic id"
[{[kw] :db/id}]
(= kw :datomic))
(defn datascript-id?
"Checks a conformed spec and ensures the :db/id was a datascript id"
(ns your.macros-for-cljs.ns
(:require [sablono.compiler :as sablono-c]))
;; Make sablono also walk into other forms:
;; if, for, let, do: Already exist
(.addMethod @(var sablono-c/compile-form) "when"
(fn
[[_ bindings & body]]
`(when ~bindings ~@(for [x body] (sablono-c/compile-html x)))))
(defn take-while+
"Identical to take-while but includes the false element."
[pred coll]
(lazy-seq
(when-let [[f & r] (seq coll)]
(if (pred f)
(cons f (take-while+ pred r))
[f]))))
(defn partition-after
(defn updated-entity
"Updates the given entity if the db has changed since the entity was last pulled."
[entity]
(let [prev-db (d/entity-db entity)
curr-db @conn]
(if (identical? prev-db curr-db)
entity
(d/entity curr-db (:db/id entity)))))
(defn qes
@rauhs
rauhs / map-all.clj
Last active November 24, 2016 17:51
(defn map-all
"Like map but if given multiple collections will call the function f
with as many arguments as there are elements still left."
([f] (map f))
([f coll] (map f coll))
([f c1 & colls]
(let [step (fn step [cs]
(lazy-seq
(let [ss (keep seq cs)]
(when (seq ss)
(defmacro datomic-fn
"Creates a datomic function given (fn [db e a ...] code...)"
[[_ args & body]]
`(d/function '{:lang "clojure"
:params ~args
:code (do ~@body)}))
(defn trinity-new
"1. If a is a ref:
Ensures that
(defn startup-time
[]
(into []
(for [v [18 19]]
(let [jar (case v
18 "/tmp/clojure-1.8.0.jar"
19 "/tmp/clojure-1.9.0-alpha14.jar")
jvm-opts ["-Xverify:none"
"-XX:+TieredCompilation"