Skip to content

Instantly share code, notes, and snippets.

@andfadeev
andfadeev / kafka-consume-from-timestamp.md
Created June 26, 2018 09:29
Consume kafka topic from timestamp with kafka-console-consumer.sh

Sometime it is usefull to consume kafka topic starting from specific timestamp (ex. for debug and faster search specific records).

  1. (Optional) Start docker container with kafka bin
docker run -it wurstmeister/kafka bash
  1. Choose unique group-id and reset offsets
$KAFKA_HOME/bin/kafka-consumer-groups.sh \
(ns concurrency
(:require [clj-http.client :as client]
[clojure.tools.logging :as log]
[com.climate.claypoole :as cp]))
;; we won't touch STM (software transactional memory), agents, refs etc
;; let's focus on things that are actually used a lot in real applications
;; first of all we have immutable DS in clojure and just that removed a huge slice of all
@andfadeev
andfadeev / closeable.clj
Created June 13, 2024 20:30
Clojure Closeable Systems
(ns closeable-system.core
(:gen-class)
(:import (clojure.lang IDeref)
(java.io Closeable)))
(defn new-database
[db-spec]
(println "Starting database component" db-spec)
(ns do-until-helper.core-test
(:require [clojure.test :refer :all]
[do-until-helper.core :refer :all]))
(defn do-async
[result]
(future
(doseq [v [1 2 3 4 5]]
(swap! result conj v)
@andfadeev
andfadeev / median-finder-test.clj
Created April 8, 2025 17:09
median-finder-test.clj
(ns median-finder-test
(:require [clojure.test :refer :all])
(:import [java.util PriorityQueue Collections]))
;; Leetcode reference: https://leetcode.com/problems/find-median-from-data-stream/description/
;; Find Median from Data Stream
;; The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.
;For example, for arr = [2,3,4], the median is 3.
;For example, for arr = [1,2,3,10], the median is (2 + 3) / 2 = 2.5.