Skip to content

Instantly share code, notes, and snippets.

View fr33m0nk's full-sized avatar

fr33m0nk fr33m0nk

View GitHub Profile
@fr33m0nk
fr33m0nk / fr33m0nk.clj-java-streams.core.clj
Created October 17, 2022 13:47
Functions for creating sequential and parallel streams. Parallel streams are very useful when working with Datomic's `d/datom` api
(ns fr33m0nk.clj-java-streams.core
(:refer-clojure :exclude [filter map distinct take drop sort take-while drop-while concat])
(:import
(java.util Collection Comparator)
(java.util.function BinaryOperator Consumer Function Predicate)
(java.util.stream BaseStream Collectors Stream StreamSupport)))
(defn iterable?
[coll]
(let [class-of-coll (class coll)]
@Vikasg7
Vikasg7 / double-cola.clj
Last active January 5, 2023 20:44
double-cola kata in Clojure
(ns cola.core)
(def names ["Sheldon" "Leonard" "Penny" "Rajesh" "Howard"])
(defn double-size [[size name]]
[(* 2 size) name])
(def group (map vector (repeat 1) names))
(def groups (lazy-cat group (map double-size groups)))
@travisbrown
travisbrown / response-de-goes.md
Last active March 31, 2024 14:41
Response to cease and desist letter from John A. De Goes, CEO of Ziverge
@dvingo
dvingo / map-zipper.clj
Last active May 9, 2022 09:45
Clojure zipper for recursively traversing a map
;; 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))
(ns scratch)
(defn map [f]
(fn [xf]
(fn
([] (xf))
([acc] (xf acc))
([acc itm]
(xf acc (f itm))))))
@JulienRouse
JulienRouse / clojure-java-interop.clj
Last active September 4, 2022 04:19
Notes about clojure-java interop for a Montreal Clojure Meetup lightning talk
;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
@marwei
marwei / how_to_reset_kafka_consumer_group_offset.md
Created November 9, 2017 23:39
How to Reset Kafka Consumer Group Offset

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
@inkrement
inkrement / clickhousedump
Created August 19, 2017 14:26
dump all clickhouse databases and tables
#!/bin/bash
OUTDIR=.
while read -r db ; do
while read -r table ; do
if [ "$db" == "system" ]; then
echo "skip system db"
continue 2;
@favila
favila / async-util.clj
Created November 28, 2014 17:06
Some missing pieces of core.async. as-transducer: Make a transducer function easily without Clojure 1.7. go-pipe: async/pipe, but returns the go-loop. fast-pipeline-blocking: faster than async/pipeline-blocking, but unordered results. blocking-consumer: consume a channel with multiple worker threads.
(ns favila.async-util
"Some missing pieces of core.async.
as-transducer: Make a transducer function easily without Clojure 1.7.
go-pipe: async/pipe, but returns the go-loop.
fast-pipeline-blocking: faster than async/pipeline-blocking, but unordered results.
blocking-consumer: consume a channel with multiple worker threads."
(:require [clojure.core.async :as async
:refer [go go-loop <! >! <!! >!! close! take! put! chan]]))
@john2x
john2x / 00_destructuring.md
Last active July 9, 2024 01:38
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

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.

Vectors and Sequences