Skip to content

Instantly share code, notes, and snippets.

Avatar

Oliver George olivergeorge

  • Tasmania, Australia
View GitHub Profile
View openssl-fix.md

Fix is to link openssl@1.1 as openssl

1069  cd /opt/homebrew/opt                 # OR WHEREVER?
1070  rm openssl
1071  ln -s openssl@1.1 openssl
@olivergeorge
olivergeorge / deps.edn
Created Aug 22, 2021
Create calendars from your git commits. Produces a CSV which Google Calendar can import.
View deps.edn
{:deps {clj-jgit/clj-jgit {:mvn/version "1.0.1"}
org.clojure/data.csv {:mvn/version "1.0.0"}}}
View actions.md

Looking at some old code there were a couple of undesirable features. One particular code smell is a good motiviating example: handlers calling other handlers.

It encourages the developer to "register handlers as reusable components" but that's a pretty clumsy way to write utilties. Over time those util handlers were collecting barnicles and were becoming very hard to reason about or refactor.

Handlers, actions and utils

With the advent of :fx we have a clean composable alternative with some desirables traits.

My app has three namespaces (app.handlers, app.actions and app.utils)

View snapshotdb.md

Some code to generate an SQLite dump from a database via a JDBC connection.

First we need a deps.edn file

{:deps {org.clojure/java.jdbc {:mvn/version "0.7.12"}
        org.xerial/sqlite-jdbc {:mvn/version "3.34.0"}
        com.oracle.database.jdbc/ojdbc8 {:mvn/version "21.1.0.0"}}}
View README.md

Experiment

Put a clj-statechart somewhere in my mobile app! Learn from the process.

Observations

Certainly better for orchestrating interesting behaviour when compared with simple re-frame handlers. The registration process has lots of corner cases. More of those are covered. The code is by rights more maintainable. I was able to refactor as I expanded it with confidence. So lots of wins there.

Actions tend to be hardcoded to a specific use case. Primarily because they have to dispatch an event which the fsm expects.

View statechart->interceptor.md
(def machine
  (fsm/machine
    {:id      ::traffic
     :initial :red
     :states  {:red    {:on {::tick :green}}
               :green  {:on {::tick :orange}}
               :orange {:on {::tick :red}}}}))
View authfsm.clj
(ns app.statecharts
(:require [app.utils :as utils]
[statecharts.core :as fsm]
[interop.anomalies :as anom]
[re-frame.core :as rf]))
; Guards
(defn offline? [state event] (not (get-in state [:db :app/online?])))
(defn has-errors? [state event] (seq (utils/login-form-errors (get-in state [:db :app/login-form]))))
(defn incorrect? [state event] (anom/incorrect? (:data event)))
View a-terser.md

package.json

{
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@blueprintjs/core": "^3.22.0",
    "@blueprintjs/datetime": "^3.15.1",
View app-fx.cljs
(rf/reg-fx ::navigate (fn [a] (navigation/dispatch (navigation/navigate-action a))))
(rf/reg-fx ::navigate2 (fn [[a b]] (navigation/navigate a b)))
(rf/reg-fx ::back (fn [] (navigation/dispatch (navigation/go-back-action))))
(rf/reg-fx ::reset-stack-by-key (fn [m] (navigation/dispatch (navigation/reset-action m))))
(rf/reg-fx ::pop (fn [n] (navigation/dispatch (navigation/pop-action n))))
(rf/reg-fx ::pop-to-top #(navigation/dispatch (navigation/pop-to-top-action)))