Skip to content

Instantly share code, notes, and snippets.

View rgm's full-sized avatar

Ryan McCuaig rgm

View GitHub Profile
@rgm
rgm / ,clerk
Created November 15, 2023 19:53
a bash script to create a new clerk notebook with emmy, plus a clojure nrepl process to render it
#!/usr/bin/env bash
if [ ! -f notebook.clj ]; then
INITIAL_FILE=$(cat <<EOF
^{:nextjournal.clerk/toc :collapsed
:nextjournal.clerk/visibility :hide-ns}
(ns user
"https://book.clerk.vision
https://emmy.mentat.org"
(:require
@rgm
rgm / ov
Created October 25, 2023 16:58
helper for overmind
#!/usr/bin/env bash
# travel upwards to find the nearest `.overmind.sock` so you can issue
# eg `ov r` or `ov c` from any subdir in a project, instead of having to
# cd up to where the Procfile is.
set -e
dnif () {
# https://stackoverflow.com/a/24642735
@rgm
rgm / gist:ca42837db8b4be665d7f256f23cb5774
Last active April 8, 2020 19:46
pulling the zoom app out of their installer - 4.6.10 (20041.0408) on 2020-04-08
❯ pkgutil --expand Zoom.pkg Zoom
❯ cd Zoom
❯ l
total 4
-rw-r--r-- 1 rgm staff 1386 Apr 8 19:05 Distribution
drwx------ 11 rgm staff 352 Apr 8 19:05 Resources/
drwx------ 6 rgm staff 192 Apr 8 19:05 zoomus.pkg/
❯ cd zoomus.pkg
❯ l
total 20116
(defn my-regular-handler
[req]
{:status 200 :headers {} :body []})
(defn my-resource-handler
[datasource req]
(let [foo (do-something-with-datasource datasource req)]
{:status 200 :headers {} :body foo}))
(defn make-top-level-handler
@rgm
rgm / re_frame_subscription_graph.cljs
Created July 31, 2019 16:10
Produce graphviz visualization of a complicated re-frame signal graph
(ns rgm.re-frame-subscription-graph
"Generate a graphviz .dot from re-frame subscriptions.
Sometimes the signal graph can get hard to grok. These two fns hijack
re-frame's subscription registration to harvest these inter-sub dependencies
as data, at which point we can produce .dot syntax and rely on graphviz
(or .dot-compatible tools like Omnigraffle) for quick-and-dirty visualization.
Usage:
- refer `subscribe` and `reg-sub` into subscription-registering
(ns rgm.kaocha-notifier
(:require [clojure.java.shell :refer [sh]]))
;; special thanks for terminal-notify stuff to
;; https://github.com/glittershark/midje-notifier/blob/master/src/midje/notifier.clj
(defmacro exists?
[program]
`(= 0 (:exit (sh "which" ~program))))
@rgm
rgm / deps.edn
Last active September 15, 2018 17:36
How to get re-frame-10x working as a foreign lib (eg. via approach in https://clojurescript.org/guides/webpack).
{:paths ["src/clj"]
:deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
org.clojure/clojurescript {:mvn/version "1.10.339"}
reagent {:mvn/version "0.8.1"
:exclusions [cljsjs/react
cljsjs/react-dom
cljsjs/react-dom-server
cljsjs/create-react-class]}
re-frame {:mvn/version "0.10.6"}}
(figwheel-sidecar.repl-api/repl-env (:figwheel-system reloaded.repl/system) nil)
;; =>
;; clojure.lang.ArityException: Wrong number of args (2) passed to: repl-api/repl-env
;; clojure.lang.Compiler$CompilerException: clojure.lang.ArityException: Wrong number of args (2) passed to: repl-api/repl-env, compiling:(user.clj:49:3)
(:figwheel-system reloaded.repl/system)
;; => #figwheel_sidecar.system.FigwheelSystem{:system #atom[#<SystemMap> 0x49742821], :system-running true}
(-> reloaded.repl/system
(get-in [:figwheel-system :system])
@rgm
rgm / charts.cljs
Created April 9, 2017 14:40
hooking up D3 and React via om.next
(ns skeleton.fourth.charts
(:require
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]
[sablono.core :as sab :refer-macros [html]]
[devcards.core :as dc :refer-macros [defcard]]
[cljsjs.d3 :as d3]))
(def canvas-size 200)
(def num-points 5)
{
"bookedQuantity": 1,
"cargoMeasurement": "PCS",
"cargoReference": 119934,
"cargoQuantity": 1,
"charterer": 10171228,
"commodity": 17890391,
"dimensionMeasurement": "M",
"freightCurrency": "USD",
"freightMeasurement": "PCS",