Skip to content

Instantly share code, notes, and snippets.

View andradefil's full-sized avatar
😎

Filipe Andrade andradefil

😎
View GitHub Profile
;; test larger gzip bytes
(defn gzip-bytes
[arr]
(let [os (java.io.ByteArrayOutputStream.)]
(with-open [gz (java.util.zip.GZIPOutputStream. os)]
(.write gz arr))
(.toByteArray os)))
(def arr1 (byte-array 65536 (byte 0)))
(def arr2 (gzip-bytes arr1 ))
(alength arr1)
@andradefil
andradefil / gzip_bench.clj
Created July 7, 2026 18:20
Benchmark approaches for unzip gzip bytes
(ns gzip-bench
(:import [java.io ByteArrayInputStream ByteArrayOutputStream]
[java.util.zip GZIPInputStream]))
(defn gzip
[arr]
(let [os (java.io.ByteArrayOutputStream.)]
(with-open [gz (java.util.zip.GZIPOutputStream. os)]
(.write gz arr))
(.toByteArray os)))
@andradefil
andradefil / ssm-test.clj
Last active July 6, 2026 22:40
ssm test
(ns ssm-test)
(require '[cognitect.aws.client.api :as aws])
(def ssm (aws/client {:api :ssm}))
(aws/invoke ssm {:op :GetParametersByPath
:request {:Path "/foo"}})
;; works com.cognitect/http-client 1.0.127
* Update JSR (Java Specification Request) to 4.0
- Questions about the update
- What is changed?
- Changelog JSR-000366
https://jcp.org/aboutJava/communityprocess/maintenance/jsr366/366ChangeLog.html
- What is involved in the update?
- JSR 366 overview of the Java EE 8 platform
- JSR 365 CDI 2.0
- JSR 367 JSON binding JSON-B 1.0
- JSR 369 Java Servlet 4.0
@andradefil
andradefil / thread-pool.clj
Created April 29, 2026 02:05
handoff thread pool
(ns http-thread-pool.core
(:import
[java.net URI]
[java.net.http HttpClient HttpClient$Version
HttpRequest HttpResponse$BodyHandlers]
[java.time Duration]
[java.util.concurrent CompletableFuture
Executors LinkedBlockingQueue RejectedExecutionHandler
ThreadFactory ThreadPoolExecutor TimeUnit]))
@andradefil
andradefil / dep-graph-db.clj
Created April 10, 2026 14:00
Queries Maven Central to build a dependency graph of tracked artifacts
(ns dep-graph-db
"Queries Maven Central to build a dependency graph of tracked artifacts"
(:require [datomic.api :as d]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.xml :as xml]
[clojure.pprint :as pp]))
(def tracked-artifacts
#{"com.datomic/peer"
@andradefil
andradefil / gen_and_select.clj
Created December 19, 2025 12:52
gen and select
(require '[clojure.test.check.generators :as tgen])
(def gen-vals-and-select
(tgen/bind
gen-db-vals
(fn [db-vals]
(def db-vals db-vals)
(if (seq db-vals)
(tgen/let [nth1 (tgen/choose 1 3)
nth2 (tgen/choose 1 3)
sz1 (tgen/choose 1 (count db-vals))
@andradefil
andradefil / thread_interrupt.repl
Created November 27, 2025 12:58
Testing Thread Interruption
(require '[clojure.core.async :as a])
(a/<!! (a/thread (Thread/sleep 3000) "Foo"))
(def c (a/chan 2))
(def o (a/thread (a/<!! c)))
(a/>!! c "Foo")
(Thread/getAllStackTraces)
@andradefil
andradefil / pipe-async.clj
Created November 3, 2025 23:51
example pipeline-async
(require '[clojure.core.async :as a])
(def from (a/chan 10))
(def to (a/chan 10))
(a/onto-chan!! from [1 2 3 4 5])
(a/<!! from)
(a/pipeline-async 4
@andradefil
andradefil / task.clj
Created October 22, 2025 14:59
Long Running Task
(ns system.process)
;; Define a Long Running Task
(defprotocol LongRunningProcessLifecycle
(start [this] "Start a long running task")
(finish [this] "Stop the runnig task"))
;; Implements lifecycle protocol
(defrecord LongRunningProcess
[worker]
LongRunningProcessLifecycle