Skip to content

Instantly share code, notes, and snippets.

View vvvvalvalval's full-sized avatar

Valentin Waeselynck vvvvalvalval

View GitHub Profile
@vvvvalvalval
vvvvalvalval / log4j.properties
Last active September 1, 2018 22:29
Clojure Logging: routing Timbre logs to Papertrail via log4j
log4j.rootLogger=INFO, syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.Facility=LOCAL7
log4j.appender.syslog.FacilityPrinting=false
log4j.appender.syslog.Header=true
log4j.appender.syslog.SyslogHost=<PAPERTRAIL_HOST>.papertrailapp.com:<PAPERTRAIL_PORT>
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern==%p: (%F:%L) %x %m %n
@vvvvalvalval
vvvvalvalval / _forkable-stores.md
Last active February 28, 2016 10:19
Forkable stores

This Gist shows how you may want to implement a forkable Ring Session Store for development and testing.

(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))
@vvvvalvalval
vvvvalvalval / git-sim-merge
Created November 18, 2016 09:25
utility for knowing what other branches will be merged if you merge a git branch into another
#!/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;
@vvvvalvalval
vvvvalvalval / supdate.clj
Last active December 26, 2016 22:48
'supdate': Clojure's update with superpowers
(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
{: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."
(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.
(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
@vvvvalvalval
vvvvalvalval / datomic-erasing-data-migration.clj
Created April 25, 2018 09:59
Erasing data from Datomic via a manual data migration
;; # 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.
@vvvvalvalval
vvvvalvalval / README.md
Last active November 7, 2018 10:32
REPLCP - Copy last REPL output

REPLCP

Small dev utility for copying REPL output to the clipboard.

Installation

Via deps.edn, typically in an alias:

{:deps