Skip to content

Instantly share code, notes, and snippets.

View andradefil's full-sized avatar
😎

Filipe Andrade andradefil

😎
View GitHub Profile
@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
@andradefil
andradefil / fil.sh
Created October 20, 2025 13:43
Fil was here
printf '\x46\x49\x4c\x20\x57\x41\x53\x20\x48\x45\x52\x45'
@andradefil
andradefil / dns.clj
Created October 20, 2025 13:19
Raw dns resolution in Clojure
(import '[java.net DatagramSocket DatagramPacket InetAddress])
(def query
(byte-array
[(byte 0x12) (byte 0x34) (byte 0x01) (byte 0x00)
(byte 0x00) (byte 0x01) (byte 0x00) (byte 0x00)
(byte 0x00) (byte 0x00) (byte 0x00) (byte 0x00)
(byte 0x07) (byte \c) (byte \l) (byte \o)
(byte \j) (byte \u) (byte \r) (byte \e)
(byte 0x03) (byte \o) (byte \r) (byte \g)
@andradefil
andradefil / server.clj
Created October 15, 2025 23:42
Serve a Static Clojure Website
(require '[org.httpkit.server :as server]
'[hiccup2.core :as h])
(def content
(str (h/html
[:meta {:charset "UTF-8"}]
[:head
[:script {:src "https://livejs.com/live.js" :type "text/javascript"}]]
[:body {:style {:background-color :black, :text-align :center}}
[:img {:src "https://github.com/clojurehackers/website/blob/main/assets/logo.jpg?raw=true", :align :center}]
@andradefil
andradefil / morse.clj
Last active October 21, 2025 12:12
Eval and Inspect With Morse Sub Repl
(require '[dev.nu.morse :as morse]
'[clojure.main :as main])
(morse/launch-in-proc)
(main/repl
:eval
(fn [form]
(let [v (eval form)]
(morse/submit form v)
v)))