Skip to content

Instantly share code, notes, and snippets.

@ynonp
ynonp / clojurescript-useeffect.cljs
Created February 18, 2022 18:42
ClojureScript useEffect example
(ns reagent-useeffect-demo.core
(:require
[reagent.core :as r]
[react :as react]
[cljs.core.async :refer [go]]
[cljs.core.async.interop :refer-macros [<p!]]
[reagent.dom :as rdom]))
(defn use-pokemon [id]
(let [[data set-data] (react/useState {})
@thomasdarimont
thomasdarimont / index.html
Last active April 8, 2024 14:10
Mini SPA with Keycloak.js with support for PKCE and RAR
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Keycloak SPA Demo</title>
<style>
body {
@hindol
hindol / bag.clj
Last active March 13, 2020 11:27
Bag / MultiSet in Clojure (How to create a custom collection in Clojure)
(ns com.github.hindol.euler.collections
(:import
(clojure.lang IPersistentCollection
IPersistentSet
Seqable)))
(deftype Bag [^clojure.lang.IPersistentMap m
^long n]
IPersistentSet
(get [this k]
@jogo3000
jogo3000 / vdottii.clj
Last active July 12, 2024 10:07
Some formulas for finding equivalent performances based on a reference
;; Adaptations of equations found in Jack Daniels - Daniels' Running Formula in clojure
(import (java.lang Math))
(defn %VOmax
"Returns the percentage of VOmax a runner can sustain for the given duration"
[seconds]
(let [mins (/ seconds 60)]
(+ 0.8
(* 0.1894393
(Math/exp (* -0.012778 mins)))
@raymcdermott
raymcdermott / decoding-jwt.clj
Last active October 26, 2022 05:47
Simple JWT Decoder in Clojure
(defn base64-decode
"Utility function over the Java 8 base64 decoder"
[to-decode]
(String. (.decode (Base64/getDecoder) ^String to-decode)))
(defn string->edn
"Parse JSON from a string returning an edn map, otherwise nil"
[string]
(when-let [edn (json/decode string true)]
(when (map? edn)
@oliyh
oliyh / clj-sse.clj
Last active September 19, 2024 14:37
Clojure client for Server Sent Events (SSE)
(require '[clj-http.client :as http])
(require '[clojure.core.async :as a])
(require '[clojure.string :as string])
(require '[clojure.java.io :as io])
(import '[java.io InputStream])
(def event-mask (re-pattern (str "(?s).+?\r\n\r\n")))
(defn- parse-event [raw-event]
(->> (re-seq #"(.*): (.*)\n?" raw-event)
@brianfay
brianfay / my-assoc-in.clj
Created November 22, 2015 00:57
my-assoc-in
(defn my-assoc-in
[m [k & ks] v]
(if (empty? ks)
(assoc m k v)
(assoc m k (my-assoc-in (k m) ks v))))
@chinshr
chinshr / Jenkinsfile
Last active October 24, 2024 17:13
Best of Jenkinsfile, a collection of useful workflow scripts ready to be copied into your Jenkinsfile on a per use basis.
#!groovy
# Best of Jenkinsfile
# `Jenkinsfile` is a groovy script DSL for defining CI/CD workflows for Jenkins
node {
}
(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(dedupe)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)