Skip to content

Instantly share code, notes, and snippets.

View nha's full-sized avatar
🐢
https://turtlequeue.com

nha

🐢
https://turtlequeue.com
View GitHub Profile
@onetom
onetom / dialog.clj
Created June 30, 2023 17:49
Pop up an Apple Script Yes/No dialog from Clojure
(ns dialog
"Display a Yes/No dialog, which appears on the very top of every app and grabs
the focus and also gives it back to the REPL, after making the choice, unlike
a Swing dialog, for example.
It's useful for confirming irreversible operations, like file or DB deletion.
It uses AppleScript, so it only works on macOS and on a local REPL."
(:require
[clojure.java.shell :as shell]))
@holyjak
holyjak / defdecorator.clj
Last active October 15, 2021 13:59
Macro to create a decorator (wrapper) for a objects implementing a Java interface
;; A macro to create a decorator (wrapper) for a objects implementing a Java interface
;; Disclaimer: The code most certainly is not perfect and does not handle some corner cases
;; License: The Unlicense http://unlicense.org/
(require '[clojure.string :as str])
(defn type->tag [parameter-type]
(let [array? (-> parameter-type name (str/ends-with? "<>"))
primitive? '#{int long float double short boolean byte char}
type (if array?
(-> parameter-type name (str/replace #"<>$" "") symbol)
@inscapist
inscapist / tailwind.cljs
Last active November 15, 2022 00:36
ChakraUI inspired tailwind *layouts*, in reagent/hiccup
(ns myapp.tailwind
(:require
[clojure.spec.alpha :as s]
[clojure.string :as str]
[vl.config :as config]))
(s/def ::class (s/or :string string? :vector vector?))
(s/def ::cs sequential?) ;; shorthand for classes
(s/def ::dim #{:screen :fill :h :vh :w :vw})
(s/def ::position #{:x-center :y-center :center}) ;; position utils for relative elements
@holyjak
holyjak / oidc_client.clj
Last active January 31, 2024 09:43
A stateful CLI tool for getting access token from an OIDC provider
#!/usr/bin/env bb
(ns oidc-client
"Get end-user access token from an OIDC provider, caching the access/refresh token in an encrypted file. Code in https://babashka.org
Usage:
/path/to/oidc_client.clj
When there are no cached, valid tokens, it will open a browser with the OIDC provider login URL and start a HTTPS-enabled
callback server on localhost. Make sure that the resulting redirect_uri is registered with your provider.
@borkdude
borkdude / jasentaa.clj
Last active May 8, 2021 12:15
Jasentaa parser combinator with babashka
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {jasentaa/jasentaa
{:git/url "https://github.com/borkdude/jasentaa"
:sha "7161b0bd8029eb29760abd1eb3026a48a8cde318"}}})
(ns jasentaa.worked-example-1
(:require
@borkdude
borkdude / kern.clj
Created May 6, 2021 20:56
Kern parser combinator with bb
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {org.blancas/kern {:git/url "https://github.com/borkdude/kern"
:sha "34a8c2f0c1ec5ab3e0e9aac56e6278abc3ed5a0b"}}})
(use 'blancas.kern.core
'blancas.kern.lexer.basic)
@thiagokokada
thiagokokada / test_runner.clj
Last active November 14, 2023 15:02
Babashka's test runner that dynamically discover the tests
#!/usr/bin/env bb
;; Inspired from https://book.babashka.org/#_running_tests
(require '[clojure.test :as t]
'[clojure.string :as string]
'[babashka.classpath :as cp]
'[babashka.fs :as fs])
(cp/add-classpath "src:test")
@littleli
littleli / paillier.clj
Last active July 20, 2021 11:49
The implementation of Paillier cryptosystem for Clojure and Babashka
(ns fun.clojure.paillier
(:import [java.math BigInteger]
[java.security SecureRandom]
[java.nio.charset StandardCharsets]))
(defn- random-number! [end]
(let [start (BigInteger/valueOf 2)
interval (.subtract end start)
i (BigInteger. (.bitCount interval) (SecureRandom.))]
(.add start i)))
@Em-AK
Em-AK / check.clj
Created February 24, 2021 16:29
Get an alert when the bike is in stock with Babashka
#!/usr/bin/env bb
(require
'[babashka.pods :as pods]
'[babashka.curl :as curl]
'[cheshire.core :as json]
'[clojure.java.shell :refer [sh]])
(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
(require
@borkdude
borkdude / gen-deps.clj
Last active September 14, 2021 08:06
Gen deps.edns in mono-repo using babashka script. Merge default dep versions.
#!/usr/bin/env bb
(ns update-deps
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pp :refer [pprint]]
[clojure.walk :as walk]))
(defn- merge-defaults [deps defaults]
(let [ff (some-fn deps (complement (partial contains? deps)))