Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains 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
<configuration> | |
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender"> | |
<target>System.err</target> | |
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | |
<level>WARN</level> | |
</filter> | |
<encoder> | |
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | |
</encoder> | |
</appender> |
This file contains 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
;; inspired by: https://clojuredocs.org/clojure.zip/zipper#example-54d91161e4b081e022073c72 | |
(defn map-zipper | |
[m ref-keys] | |
{:pre [(set? ref-keys)]} | |
(z/zipper | |
(fn is-branch? [x] | |
(let [ret | |
(cond | |
(not (coll? x)) |
This file contains 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
;Montreal Clojure Meetup 2019 | |
;;sources | |
; - https://clojure.org/reference/java_interop | |
; - https://leanpub.com/clojure-java-interop/read_sample | |
; - http://blog.jayfields.com/2011/12/clojure-java-interop.html | |
; - https://stackoverflow.com/questions/2181774/calling-clojure-from-java | |
; - https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.2-200 |
This file contains 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 scratch) | |
(defn map [f] | |
(fn [xf] | |
(fn | |
([] (xf)) | |
([acc] (xf acc)) | |
([acc itm] | |
(xf acc (f itm)))))) |
This file contains 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 r-some? | |
"Super fast version of clojure.core/some that does minimal allocation" | |
[pred coll] | |
(reduce | |
(fn [acc v] | |
(if-let [val (pred coll)] | |
(reduced val) | |
acc)) | |
false | |
coll)) |
This file contains 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 tx-pipeline-inorder | |
"Transact transactions in core.async channel `from-ch` against datomic connection `conn` with a pipeline depth of `n`. | |
Returns a map with keys `:stop!` and `:result`. `:stop!` is a no-arg function you can call to immediately | |
cease sending transactions (already sent transactions cannot be stopped). `:result` is a promise channel | |
returning a variant of the result of the tx-pipelining after from-ch is closed and drained, or | |
:stop! is called and all send transaction futures are deref-ed, or a transaction produces an exception. | |
The variant returned from the :result channel may be one of: | |
This file contains 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 kafka-workbench | |
(:require [franzy.clients.consumer.protocols :as c] | |
[franzy.clients.producer.protocols :as p] | |
[franzy.serialization.serializers :as serializers] | |
[franzy.serialization.deserializers :as deserializers] | |
[franzy.clients.consumer.client :as consumer] | |
[franzy.clients.producer.client :as producer])) | |
(def kafka-brokers []) |
This file contains 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
#!/bin/bash | |
OUTDIR=. | |
while read -r db ; do | |
while read -r table ; do | |
if [ "$db" == "system" ]; then | |
echo "skip system db" | |
continue 2; |
This file contains 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
// Get the list of partitions | |
List<PartitionInfo> partitionInfos = consumer.partitionsFor(topicName); | |
// Transform PartitionInfo into TopicPartition | |
List<TopicPartition> topicPartitionList = partitionInfos | |
.stream() | |
.map(info -> new TopicPartition(topicName, info.partition())) | |
.collect(Collectors.toList()); | |
// Assign the consumer to these partitions | |
consumer.assign(topicPartitionList); | |
// Look for offsets based on timestamp |
OlderNewer