Skip to content

Instantly share code, notes, and snippets.

View vvvvalvalval's full-sized avatar

Valentin Waeselynck vvvvalvalval

View GitHub Profile
@vvvvalvalval
vvvvalvalval / keywordize_at_keys.clj
Last active May 18, 2023 18:17
Clojure : keywordize values at specific keys
(ns utils.keywordize-at-keys
(:require [clojure.walk :as walk]))
(defn- coerced-to-keyword
[k]
(when (string? k)
(keyword k)))
(defn keywordize-at-keys
@vvvvalvalval
vvvvalvalval / Day6.kt
Last active December 26, 2018 21:45 — forked from ygrenzinger/Day6.kt
Advent of Code
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)
@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
@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.
(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."
@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
@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;
(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))