Skip to content

Instantly share code, notes, and snippets.

View borkdude's full-sized avatar

Michiel Borkent borkdude

View GitHub Profile
@jeeger
jeeger / get-input.clj
Created December 14, 2022 14:04
Get Advent of Code input in babashka.
#!/bin/env bb
(require '[babashka.fs :as fs])
(require '[babashka.curl :as curl])
(defn get-day-component []
(let [components (fs/components (fs/cwd))]
(-> (filter #(str/starts-with? % "day") components)
first)))
(defn get-day-number [day-name]
@bobbicodes
bobbicodes / friends.clj
Last active January 6, 2023 15:35
Who unfriended me?
(ns friends
(:require [cheshire.core :as json]
[clojure.set :as set]))
;; The way this works is you download your own Facebook data as JSON
;; (Settings -> Privacy -> Your Facebook information -> Download Your Information)
;; All that you need is Connections -> Friends and followers selected.
;; It will be ready in a few minutes and will be less than 1MB.
;; Place 2 files spanning a certain period of time in this folder,
;; and pass the 2 filenames to `friends/unfriended`.
@yogthos
yogthos / README.md
Last active March 24, 2024 10:35
command line util for grabbing current weather for a city using OpenWeather API

usage

Create an account at https://openweathermap.org and get an API key. Note that it can take up to a couple of hours for the key to become active. Add an environment variable OPEN_WEATHER_API_KEY with the value of the key.

run the script:

./weather.clj Toronto,CA
@jeeger
jeeger / bookstats.clj
Last active November 26, 2022 15:37
Sum up page counts of books from Calibre library with babashka
#!/usr/bin/env bb
(ns bookstats
(:require [babashka.pods :as pods]
[clojure.pprint :as pprint]))
(pods/load-pod 'org.babashka/go-sqlite3 "0.1.0")
(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
(require '[pod.babashka.go-sqlite3 :as sqlite]
'[pod.retrogradeorbit.hickory.select :as s]
'[pod.retrogradeorbit.bootleg.utils :as utils])
(import [java.net URLEncoder]
@CarnunMP
CarnunMP / cotd.clj
Last active November 23, 2022 15:15
tiny babashka script that returns a random clojure doc
#!/usr/bin/env bb
(require '[clojure.repl])
(def namespaces ; well, readily available ones
['clojure.core
'clojure.edn
'clojure.instant
'clojure.java.browse
'clojure.java.io
@henryw374
henryw374 / kroki-read.bb
Last active July 4, 2022 17:50
encode and decode files as kroki url diagrams https://kroki.io/#try
#!/usr/local/bin/bb
(import '[java.io ByteArrayOutputStream])
(import '[java.util Base64]) ;
(import '[java.util.zip Inflater]) ;
(defn uncompress [source-bytes]
(let [inflater (doto (Inflater.)
(.setInput source-bytes))
outputStream (new ByteArrayOutputStream (count source-bytes))
@tylerw
tylerw / update-clj-tools.bb
Created June 18, 2022 19:23
Quick-and-dirty script to update all Clojure -Ttools
#!/usr/bin/env bb
;;;
; A babashka script to update all clojure -Ttools to the latest versions
; author: Tyler Wardhaugh
;;;
(ns update-clj-tools
(:require [babashka.fs :as fs]
[babashka.process :refer [process]]))
@jackrusher
jackrusher / deploy.sh
Created January 17, 2022 15:22
Writing and deploying Google Cloud Functions in Clojure using NBB
# command line to deploy the project
gcloud functions deploy hello --runtime nodejs14 --trigger-http
@digash
digash / get-latest-meta-data-json.clj
Last active December 2, 2021 17:45
Read all meta-data on AWS EC2
#!/bin/env bb
(let [cgb #(->> % (cons "http://169.254.169.254/latest") (str/join "/") curl/get :body)
try-json #(try (json/parse-string %) (catch Exception _ %))
dir? #(str/ends-with? (last %) "/")
paths (fn [p] (->> (cgb p)
str/split-lines
(map #(->> (str/split % #"=") first (conj p)))))
trimlslash #(str/replace % #"/$" "")]
(json/generate-stream
@rutenkolk
rutenkolk / upgrade_zig.clj
Created September 16, 2021 22:35
upgrading zig to the latest version with Babashka
#!/usr/bin/env bb
(ns script
(:require [clojure.java.io :as io]
[clojure.string :as s]
[clojure.pprint :as pprint]
[clojure.java.shell :refer [sh with-sh-dir]]
[cheshire.core :as json]))
(defn prsh
([sh]