Skip to content

Instantly share code, notes, and snippets.

Avatar

Michiel Borkent borkdude

View GitHub Profile
@borkdude
borkdude / extension.js
Created Apr 22, 2022
Nbb in VSCode extension
View extension.js
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const path = require('path');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
@borkdude
borkdude / reaction.cljs
Last active Apr 12, 2022
Reagent ratom / reaction
View reaction.cljs
(require '[promesa.core :as p]
'[reagent.ratom :as ratom])
(def app-state (ratom/atom {:state-var-1 {:var-a 2
:var-b 3}
:state-var-2 {:var-a 7
:var-b 9}}))
(def app-var2a-reaction (ratom/make-reaction
#(get-in @app-state [:state-var-2 :var-a])))
@borkdude
borkdude / class_to_package.clj
Last active Apr 10, 2022
Retrieve the package string from a .class file
View class_to_package.clj
(require '[clojure.java.io :as io]
'[clojure.string :as str])
(defn class->package
"Implementation by Marco Marini."
[class-file]
(with-open [dis (java.io.DataInputStream. (io/input-stream class-file))]
;; skip first 8 bytes
(.skipBytes dis 8)
(let [constant-pool-count (.readUnsignedShort dis)
@borkdude
borkdude / deploy.sh
Created Mar 18, 2022 — forked from jackrusher/deploy.sh
Writing and deploying Google Cloud Functions in Clojure using NBB
View deploy.sh
# command line to deploy the project
gcloud functions deploy hello --runtime nodejs14 --trigger-http
@borkdude
borkdude / find_git_dirs.clj
Last active Mar 16, 2022
find_git_dirs.clj
View find_git_dirs.clj
(require '[babashka.fs :as fs])
(let [counter (volatile! 0)]
(fs/walk-file-tree "." {:pre-visit-dir (fn [d _]
(if (= ".git" (fs/file-name d))
(do (vswap! counter inc )
:skip-subtree)
:continue))})
@counter)
@borkdude
borkdude / polyglot.cljs
Created Jan 31, 2022
GraalVM Node + nbb + JVM Clojure
View polyglot.cljs
$ $GRAALVM_HOME/bin/node --jvm --polyglot --vm.cp=$(clojure -Spath) $(which nbb)
user=> (.-version js/process)
"v14.18.1"
user=> (require '["path" :as path])
nil
user=> (path/resolve ".")
"/Users/borkdude"
user=> (def Clojure (js/Java.type "clojure.java.api.Clojure"))
#'user/Clojure
user=> (def clj:require (.var Clojure "clojure.core" "require"))
View dev.docgen.clj
(ns dev.docgen
(:require [clojure.pprint :refer [pprint]]
[rewrite-clj.zip :as z]
[clojure.string :as str]
[clojure.java.io :as io])
(:import (java.io File)))
(defn -form->markdown
"Clojure forms are evaluated and the result is automatically inserted in the generated markdown.
There is a special handling for 'def, we show their var binding instead"
View guestbook.clj
(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 Dec 26, 2021
Mix and match older tools from nixpkgs
View shell.nix
{ 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";
}) {};
View Segfault
$ 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)