This Gist shows how you may want to implement a forkable Ring Session Store for development and testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn exponential-backoff | |
"Implements exponential backoff. | |
* af is a function which accepts 3 channels (af =success= =error= =retry=), and should do exactly one of the following operations without blocking: | |
- put a successful value in =success= | |
- put an error in =error= (will break the loop) | |
- put an error which causes a retry in =retry=. | |
* the exponential backoff loop can be configured with :get-delay-ms, a function which returns a (potentially infinite) seq of backoff intervals, | |
and :imprecision-ms, a maximim number of milliseconds with which to randomly blurr the backoff intervals. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:db/ident :bsu.fns/reset-to-many-by, | |
:db/doc "Resets the set of entities which are related to `eid` via `ref-attr` to the set given by `val-maps`. | |
Assumptions: | |
* `ref-attr` is a cardinality-many, ref attribute. | |
* `e` is an entity identifier for an _existing_ entity | |
(you have to know whether an entity exists before using this function, | |
and it's pointless to use it on a non-existing entity as opposed to just asserting all the new values.) | |
* `val-maps` is a seq of transaction maps, all of which have the `v-id-attr` key provided. | |
* `retract-target-entity?`: whether to call :db.fn/retractEntity on the old entities which get removed from the relationship. | |
* the old values of the relationship all have the `id-attr` attribute." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns utils.supdate | |
"A macro for transforming maps (and other data structures) using a spec reflecting the | |
schema of the value to transform.") | |
;; ------------------------------------------------------------------------------ | |
;; Example Usage | |
(comment | |
;;;; nominal cases | |
(supdate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var br1 = process.argv[2]; | |
var br2 = process.argv[3]; | |
var exec = require('child_process').exec; | |
function setDiff(s1, s2){ | |
return s1.filter(function(e){ | |
return s2.indexOf(e) < 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(set! *warn-on-reflection* true) | |
;; 3 competing implementations which test if a string is uppercase (note that the StringUtils one has some caveats regarding its semantics) | |
(defn p1 [^String s] | |
(= s (str/upper-case s))) | |
(defn p2 [^String s] | |
(every? (fn [^Character c] (Character/isUpperCase c)) s)) | |
(import org.apache.commons.lang3.StringUtils) | |
(defn p3 [^String s] | |
(StringUtils/isAllUpperCase s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro m:p "Makes a map from a list of symbols, using the symbol names to create keyword keys. | |
--- | |
(let [a 1 b 2 c \"3\"] | |
(m:p a b c)) | |
=> {:a 1, :b 2, :c \"3\"} | |
" [& syms] | |
(reduce (fn [m sym] | |
(assert (symbol? sym) "m:p only accepts symbols") | |
(assoc m (keyword (name sym)) sym)) | |
{} syms)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns bs.utils.schema-cleaner "TL;DR look in the tests how the `cleaner` function is used." | |
(:require [schema.core :as s] | |
[schema.coerce :as sco] | |
[schema.utils :as scu] | |
) | |
(:use clojure.repl clojure.pprint)) | |
(deftype ^:private GarbageType []) | |
(def ^:private garbage-const (GarbageType.)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; defining helper function | |
[{:db/id #db/id[:db.part/user] | |
:db/doc "Helper function for defining entity fields schema attributes in a concise way." | |
:db/ident :utils/field | |
:db/fn #db/fn {:lang :clojure | |
:require [datomic.api :as d] | |
:params [_ ident type doc opts] | |
:code [(cond-> {:db/cardinality :db.cardinality/one | |
:db/fulltext true | |
:db/index true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Instead of this version, where you have to manage the lifecycle of my-stateful-component with React lifecycle methods | |
(defn parent-component [] | |
[:div | |
;; ... | |
[my-stateful-component dynamic-id arg1 arg2 etc.] | |
;; ... | |
]) | |
;; ... you can use this trick |