Skip to content

Instantly share code, notes, and snippets.

@ggeoffrey
ggeoffrey / top_threads.org
Last active January 21, 2022 14:14
How to find and kill a runaway JVM thread, at the REPL

How to find and kill a runaway JVM thread at the REPL

Problem

A thread I spawned is consuming resources, and I’d like to stop it, but I don’t have a reference to it.

Solution

@ggeoffrey
ggeoffrey / jwt.clj
Last active February 16, 2024 07:57
Checking a JWT validity using JWKs in Clojure (tested with Cognito)
(ns services.jwt
(:require [buddy.sign.jwt :as jwt]
[clojure.data.codec.base64 :as b64]
[clojure.string :as str]
[cheshire.core :as json]
[buddy.core.keys :as keys] ;; You need to use [buddy/buddy-core "1.5.0-SNAPSHOT"]
[clojure.java.io :as io]))
(defn decode-b64 [str] (String. (b64/decode (.getBytes str))))
(defn parse-json [s]
@ggeoffrey
ggeoffrey / Sort-strings.clj
Last active May 25, 2016 20:33
This is clean and elegant … I guess… Way better then the first version.
(defn re-extract
"Try to re-find all given regexps until one matches.
nil if none matches."
[value & regexps]
(cond
(nil? value) nil ;; safe fallback
(empty? regexps) nil ;; no params or no more regexps to try
:else (let [pattern (first regexps) ;; take the first one
extracted (re-find pattern value)] ;; search for it