Small dev utility for copying REPL output to the clipboard.
Via deps.edn
, typically in an alias:
{:deps
(ns utils.keywordize-at-keys | |
(:require [clojure.walk :as walk])) | |
(defn- coerced-to-keyword | |
[k] | |
(when (string? k) | |
(keyword k))) | |
(defn keywordize-at-keys |
import java.io.File | |
import java.util.* | |
import java.util.concurrent.atomic.AtomicInteger | |
data class Coordinate(val x: Int, val y: Int) | |
data class Point(val label: Int, val coordinate: Coordinate) | |
data class area(val associatedToPoint: Point, val size: Int = 0) | |
var seqId = AtomicInteger(1) |
;; # EMULATING DATOMIC EXCISION VIA MANUAL DATA MIGRATION | |
;; ************************************* | |
;; ## Introduction | |
;; ************************************* | |
;; This Gist demonstrates a generic way to migrate an entire Datomic database | |
;; from an existing 'Origin Connection' to a clean 'Destination Connection', | |
;; while getting rid of some undesirable data and otherwise preserving history. |
(defn pprint-to-clipboard | |
"Copies a pretty-printed representation of value `v` to the clipboard. | |
When `v` is not supplied, copies the last REPL output (*1). | |
Useful for copying and pasting REPL output to an editor buffer." | |
([] | |
(pprint-to-clipboard *1)) | |
([v] | |
(-> (java.awt.Toolkit/getDefaultToolkit) | |
.getSystemClipboard | |
(.setContents |
(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. |
{: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." |
(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 |
#!/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; |
(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)) |