Skip to content

Instantly share code, notes, and snippets.

View borkdude's full-sized avatar

Michiel Borkent borkdude

View GitHub Profile
(ns guestbook
(:require [cheshire.core :as cheshire]
[hiccup2.core :as hiccup]
[clojure.string :as str]))
(require '[babashka.pods :as pods])
(pods/load-pod "./pod-babashka-postgresql")
(def db {:dbtype "postgresql"
:user "guestbook"
@borkdude
borkdude / shell.nix
Created December 26, 2021 13:07
Mix and match older tools from nixpkgs
{ pkgs ? import <nixpkgs> {} }:
let
graalvm21_2_0 = import (builtins.fetchGit {
# Descriptive name to make the store path easier to identify
name = "graalvm-21.2.0";
url = "https://github.com/NixOS/nixpkgs";
ref = "refs/heads/nixpkgs-unstable";
rev = "e4dda76e6397fb1e30b907abeaf6a72bb055a1e6";
}) {};
$ bb nrepl-server
Started nREPL server at 127.0.0.1:1667
For more info visit: https://book.babashka.org/#_nrepl
[ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007feb86c0ae00 ] ]
siginfo: si_signo: 11, si_code: 1, si_addr: 0x0000000000000039
General purpose register values:
RAX 0x0000700003f2bf60 points into the stack for thread 0x00007feb86c0ae00
RBX 0x0000000107d78120 points into the image heap (read-only huge)
@borkdude
borkdude / zip.clj
Created December 7, 2021 13:08
tools.build zip in bb
(ns clojure.tools.build.util.zip
(:require
[clojure.java.io :as jio]
[clojure.string :as str])
(:import
[java.io File BufferedInputStream FileInputStream FileOutputStream]
[java.nio.file Files LinkOption]
[java.nio.file.attribute BasicFileAttributes]
[java.util.zip ZipOutputStream ZipEntry]))
@borkdude
borkdude / aoc21_01.clj
Last active December 22, 2021 02:32
Advent of Code 2021 - in Clojure / babashka 0.6.8
(ns aoc21-01
(:require [clojure.string :as str]))
(def input (map parse-long (str/split-lines (slurp "input.txt"))))
(defn answer-01 [input]
(count (filter true? (map < input (rest input)))))
(def three-sliding-window
(map + input (next input) (nnext input)))
#!/usr/bin/env bash
# temp file
t=/tmp/bipe.$$.txt
touch $t
# read from stdin
if [ ! -t 0 ]; then
cat > $t
@borkdude
borkdude / tools_namespace_lite.clj
Created November 23, 2021 17:28
tools-namespace-lite: discover namespaces in pure clojure/bb
(ns tools-namespace-lite
(:require [clojure.java.io :as io]))
(defn source? [f]
(re-matches #".*\.clj[cs]?$" (str f)))
(defn source-files [dir]
(filter source? (file-seq (io/file dir))))
(defn find-namespaces-in-file [f]
@borkdude
borkdude / konsami.clj
Last active January 13, 2022 15:26
clj-kondo + asami
;; deps.edn:
;; {
;; :deps {
;; clj-kondo/clj-kondo {:mvn/version "2021.10.19"}
;; org.clojars.quoll/asami {:mvn/version "2.2.3"}
;; }
;; }
@borkdude
borkdude / gist:5071a7e45dcab3569df434952e97348e
Created November 11, 2021 22:16
uber: too long filename
{:clojure.main/message
"Execution error (IOException) at java.lang.ProcessImpl/create (ProcessImpl.java:-2).\r\nCreateProcess error=206, The filename or extension is too long\r\n",
:clojure.main/triage
{:clojure.error/class java.io.IOException,
:clojure.error/line -2,
:clojure.error/cause
"CreateProcess error=206, The filename or extension is too long",
:clojure.error/symbol java.lang.ProcessImpl/create,
:clojure.error/source "ProcessImpl.java",
:clojure.error/phase :execution},
@borkdude
borkdude / runner.cljs
Created November 9, 2021 13:37
Nbb browser test runner @ Nextjournal
(ns com.nextjournal.tests.browser.runner
(:require [clojure.string :as str]
[clojure.test :as t :refer [test-vars]]
[com.nextjournal.tests.browser.article-test-nbb :as article-test]))
(defmethod t/report [:cljs.test/default :begin-test-var] [m]
(println "===" (-> m :var meta :name))
(println))
(defn print-summary []