Skip to content

Instantly share code, notes, and snippets.

View borkdude's full-sized avatar

Michiel Borkent borkdude

View GitHub Profile
@borkdude
borkdude / difft.bb
Last active November 14, 2022 09:19
Difftastic wrapper with support for viewing transit.json as edn files in git diff
#!/usr/bin/env bb
;; To use, call `git config diff.external "/path/to/difft.bb"`
;; Original by https://twitter.com/OneMore2ThePile/status/1589355270995836928
;; See https://twitter.com/borkdude/status/1589359697710133248/photo/1 for a demo
(ns difft
(:require
[babashka.fs :as fs]
[babashka.process :refer [shell]]
@borkdude
borkdude / partial.md
Last active September 11, 2023 14:24
partial.md

Here's a list of things I collected a conversation on partial. Personally I think using partial almost never has a benefit, while there are some downsides to using it. There are exceptional cases where partial has a benefit, e.g. if you want to "wrap" a multi-arity function or a function with an unknown amount of arguments.

Some reasons not to use partial:

@borkdude
borkdude / cli_app.clj
Last active August 3, 2022 10:16
babashka.cli args->opts
(ns cli-app
(:require [babashka.cli :as cli]))
(def spec {:hello {:desc "something"}
:foo {:desc "foo"}
:bar {:desc "bar"
:coerce []}})
(def cli-opts {:spec spec
:args->opts (cons :foo (repeat :bar))})
@borkdude
borkdude / pw.clj
Created August 1, 2022 21:25
Playwright browser + bb chrome devtools
;; run npx playwright install to install a browser
(require '[babashka.deps :as deps])
(deps/add-deps
'{:deps {tatut/devtools {:git/url "https://github.com/tatut/clj-chrome-devtools"
:git/sha "cc96255433ca406aaba8bcee17d0d0b3b16dc423"}
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}})
@borkdude
borkdude / scriptjure.clj
Last active July 19, 2022 14:35
Scriptjure!
((requiring-resolve 'babashka.deps/add-deps)
'{:deps {scriptjure/scriptjure #_{:mvn/version "0.1.24"}
{:git/url "https://github.com/borkdude/scriptjure"
:git/sha "8d1f303557a0f4a021f33f2b01eb10b33509f46e"
:deps/manifest :deps}
#_{:local/root "/tmp/scriptjure" :deps/manifest :deps}}})
(ns scriptjure
{:clj-kondo/config
'{:config-in-call {com.reasonr.scriptjure/js
@borkdude
borkdude / new
Last active July 23, 2022 14:25
Create clojure project with babashka using deps-new
#!/usr/bin/env bb
(require '[babashka.classpath :as cp]
'[babashka.deps :as deps])
(deps/add-deps '{:deps {org.corfield/deps-new {:git/url "https://github.com/borkdude/deps-new"
:git/sha "76259a27c57dba4530671a3d18c610ed904297d7"}
org.babashka/cli {:mvn/version "0.3.31"}
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
:git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}}})
@borkdude
borkdude / zazzle.md
Last active June 18, 2022 20:00
Zazzle products
@borkdude
borkdude / bbsh.clj
Last active May 27, 2022 14:26
Fun (non-serious) small shell in babashka
#!/usr/bin/env rlwrap bb
(ns bbsh
(:require
[babashka.fs :as fs]
[babashka.process :as process]
[clojure.string :as str]))
(defmacro % [& args]
`(do @(process/$ {:inherit true} ~@args)
@borkdude
borkdude / install-dev-certificate
Created May 26, 2022 11:59
install_dev_certificate.clj
#!/usr/bin/env bash
set -eo pipefail
CERT_FILE="./certs/dev/dev-ca/rootCA.pem"
CERT_NAME="Nextjournal Development Root CA"
echo "Installing development Root CA into system store..."
if uname -a | grep -q Darwin; then
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain $CERT_FILE
@borkdude
borkdude / project.md
Last active May 24, 2022 11:51
Project conventions

Some of my conventions:

  • Create initial build.clj with neil add build :deps-deploy true and then tweak. Use vanilla tools.build for maximum control and better startup time.
  • Have bb directory with task code which you can require from bb.edn
  • bb dev launches the dev REPL
  • bb publish prepares repo for publish (e.g. by updating something and creating tag), pushes and CI takes over. The name publish originated from vsce publish here
  • Probably going forward: use release count rather than commit count (less complicated to deal with and smaller numbers are easier to remember)
  • For new projects: neil license add mit (or epl1 or so)