Skip to content

Instantly share code, notes, and snippets.

View prestancedesign's full-sized avatar

Michael Salihi prestancedesign

View GitHub Profile
#!/bin/env/bb
;; script for creating DigitalOcean's droplet snapshot
(require '[babashka.curl :as curl])
(require '[cheshire.core :as json])
(def token (System/getenv "DO_TOKEN"))
(def droplet-id (System/getenv "DO_DROPLET_ID"))
(when (not token)
@plexus
plexus / lookup.clj
Created March 12, 2021 12:45
Doing key lookup in Clojure
;; If it's a record-like thing then we want to emphasize
;; that it's a key-lookup, so use (:key coll)
(:uri req)
(:email member)
;; Some collections behave more like functions, here use (coll key),
;; that way someone reading the code without context can understand it,
;; without having to know that it's really a map or set
(def allowed-role? #{:admin :mod})
(ns example.counter
(:require
[shadow.experiments.grove :as sg :refer (defc <<)]))
(defc ui-counter []
;; create a local state atom once on mount
(bind state-ref
(atom 0))
;; watch state-ref and bind deref result to val
@holyjak
holyjak / http-server.bb
Last active March 19, 2023 04:36
Babashka HTTP server for serving static files, similar to `python -m http.server` but more flexible :)
#!/usr/bin/env bb
#_" -*- mode: clojure; -*-"
;; Based on https://github.com/babashka/babashka/blob/master/examples/image_viewer.clj
(ns http-server
(:require [babashka.fs :as fs]
[clojure.java.browse :as browse]
[clojure.string :as str]
[clojure.tools.cli :refer [parse-opts]]
[org.httpkit.server :as server]
@adam-james-v
adam-james-v / qblock.cljc
Last active July 13, 2022 08:33
Code for a mario Question Block Model (Clojure compiled to openscad)
;; code related to a youtube video:
;; https://youtu.be/3euk0-JF_tc
(ns qblock.main
(:require [clojure.string :as st]
[scad-clj.model :refer :all]
[scad-clj.scad :refer [write-scad]]))
(fn! 30)
@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)))
@adam-james-v
adam-james-v / vidwiz.clj
Last active January 22, 2023 09:42
Clojure/babashka script to help automate some of my video editing pipeline
#!/usr/bin/env bb
(ns vidwiz.main
"This is a prototype script for automating a portion of my video editing using ffmpeg."
(:require [clojure.java.shell :refer [sh]]
[clojure.string :as st]
[cheshire.core :refer [parse-string]]))
;; util
(defn get-extension
@borkdude
borkdude / logger.clj
Last active April 27, 2021 20:23
Simple logger that works in bb
(ns logger)
(defmacro log [& msgs]
(let [m (meta &form)
_ns (ns-name *ns*) ;; can also be used for logging
file *file*]
`(binding [*out* *err*] ;; or bind to (io/writer log-file)
(println (str ~file ":"
~(:line m) ":"
~(:column m))
@borkdude
borkdude / router.clj
Last active April 9, 2024 15:03
Small ring router using core.mach in babashka
(require '[clojure.core.match :refer [match]]
'[clojure.string :as str]
'[hiccup2.core :refer [html]]
'[org.httpkit.server :as server])
(defn router [req]
(let [paths (vec (rest (str/split (:uri req) #"/")))]
(match [(:request-method req) paths]
[:get ["users" id]] {:body (str (html [:div id]))}
:else {:body (str (html [:html "Welcome!"]))})))
@adam-james-v
adam-james-v / hc-main.cljc
Last active March 15, 2021 14:47
Minimal implementation of a Hiccup Compiler
;; source code related to the project shown in this video:
;; https://youtu.be/_XiEc0g2wL8
;; author: adam-james
(ns hc.main)
(defn hiccup?
[item]
(and (vector? item)
(keyword? (first item))))