This file contains hidden or 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 datomic-cdc.core | |
"proof-of-concept that shows how setup change-data-capture for datomic" | |
(:require [datomic.api :as d])) | |
(def processed-t- (atom nil)) | |
(defn start-cdc-thread | |
"starts a new thread to processes all past transactions starting at start-t, then continues processing incoming transactions, using the provided `change-handler` | |
`change-handler` must be a function that takes a single map argument with |
This file contains hidden or 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
import com.github.benmanes.caffeine.cache.Caffeine | |
import com.github.benmanes.caffeine.cache.Ticker | |
import io.kotest.matchers.shouldBe | |
import org.junit.jupiter.api.Test | |
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.atomic.AtomicLong | |
import kotlin.time.Duration | |
import kotlin.time.Duration.Companion.seconds | |
import kotlin.time.toJavaDuration |
This file contains hidden or 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
import io.micrometer.core.instrument.MeterRegistry | |
import io.micrometer.core.instrument.Tag | |
import java.time.Instant | |
import java.util.concurrent.TimeUnit | |
import java.util.concurrent.atomic.AtomicLong | |
import java.util.function.ToDoubleFunction | |
fun MeterRegistry.timeGaugeMillis(name: String, tags: Iterable<Tag>, initialValue: Long = 0): (Instant) -> Unit { | |
val a = AtomicLong(initialValue) | |
a.apply { |
This file contains hidden or 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
(let [l [0 0 1 1 1 14 5 13 6 3 ] | |
m [0.01 0.02 0.05 0.1 0.2 0.5 1 2 5 10 20 50 100] | |
subtotals (map * m l) | |
total (reduce + subtotals)] | |
(doseq [[munt totaal] (sort-by key > (zipmap m subtotals))] | |
(printf "%s\t%.2f%n" munt (float totaal))) | |
total) |
This file contains hidden or 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
(defun add-clj-format-before-save () | |
(interactive) | |
(add-hook 'before-save-hook | |
'cider-format-buffer | |
t | |
t)) | |
(add-hook 'clojure-mode-hook 'add-clj-format-before-save) |
This file contains hidden or 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 invert | |
"inverts a graph represented as a map from source to target nodes" | |
[graph] | |
(reduce-kv (fn [acc src trgs] | |
(if (seq trgs) | |
(reduce (fn [acc- trg] | |
(update acc- trg (fnil conj #{}) src)) | |
acc | |
trgs) | |
;; to preserve nodes without edges |
This file contains hidden or 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
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo | |
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo | |
sudo yum install -y apache-maven | |
mvn --version |
This file contains hidden or 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
{"AWSTemplateFormatVersion":"2010-09-09", | |
"Description":"Creates a classic-link enabled VPC, the custom resource hangs", | |
"Parameters":{}, | |
"Resources": | |
{"VPC": | |
{"Type":"AWS::EC2::VPC", | |
"Properties": | |
{"EnableDnsSupport":true, | |
"EnableDnsHostnames":true, | |
"CidrBlock":"10.0.0.0/16", |
This file contains hidden or 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
;; Toggle a counter that tracks how manny times a function is called | |
(defn instrument-fn [f] | |
(let [counter (atom 0)] | |
(-> (fn [& args] ;; NOTE could unroll for 1-n args for speed | |
(swap! counter inc) | |
(apply f args)) | |
(with-meta | |
{:uninstrumented f | |
:counter counter})))) |
This file contains hidden or 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 eval-with-bindings [bindings form] | |
(assert (even? (count bindings)) "an even number of forms in binding vector") | |
(let [binding-pairs (partition 2 bindings) | |
args (mapv first binding-pairs) | |
vals (map second binding-pairs)] | |
`((eval (fn ~args ~form)) | |
~@vals))) | |
(let [foo inc] | |
(eval '(foo 1))) |
NewerOlder