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 / db-spec.clj
Last active Sep 24, 2021
Simple script to generate clojure.spec info for a database.
View db-spec.clj
(ns db-spec.core
(:require [clojure.java.jdbc :as j]
[clojure.spec :as s])
(:import (java.sql Types)))
(defn db-tables-raw
[db-spec {:keys [catalog schemaPattern tableNamePattern]}]
(j/with-db-metadata [meta db-spec]
(j/metadata-result
(.getTables meta catalog schemaPattern tableNamePattern (into-array String ["TABLE"])))))
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)

@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"}}}
@olivergeorge
olivergeorge / Makefile
Last active Aug 13, 2021
Devops tools for simple Datomic Ions app
View Makefile
provision:
clojure -A:dev -m devops provision
teardown:
clojure -A:dev -m devops teardown
cloud-on:
clojure -A:dev -m devops cloud-on
View gist:718687
from django.core.exceptions import ValidationError
from django.db.models import Field, CharField
__all__ = ['MultiColumnField']
try:
from hashlib import md5
except ImportError:
from md5 import new as md5
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)))