Skip to content

Instantly share code, notes, and snippets.

Avatar

Valentin Waeselynck vvvvalvalval

View GitHub Profile
@vvvvalvalval
vvvvalvalval / keywordize_at_keys.clj
Last active Jun 5, 2020
Clojure : keywordize values at specific keys
View keywordize_at_keys.clj
(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 Dec 26, 2018 — forked from ygrenzinger/Day6.kt
Advent of Code
View Day6.kt
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 Nov 7, 2018
REPLCP - Copy last REPL output
View README.md

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 Apr 25, 2018
Erasing data from Datomic via a manual data migration
View datomic-erasing-data-migration.clj
;; # 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.
View pprint-to-clipboard.clj
(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
View core-async-exponential-backoff.clj
(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.
View reset-to-many-by.edn
{: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 Dec 26, 2016
'supdate': Clojure's update with superpowers
View supdate.clj
(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 Nov 18, 2016
utility for knowing what other branches will be merged if you merge a git branch into another
View git-sim-merge
#!/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;
View bench-string-uppercase-check.clj
(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))