Skip to content

Instantly share code, notes, and snippets.

View holyjak's full-sized avatar
💓
Loving Clojure

Jakub Holý holyjak

💓
Loving Clojure
View GitHub Profile
@holyjak
holyjak / oidc_client.clj
Last active April 25, 2024 16:39
A stateful CLI tool for getting access token from an OIDC provider
#!/usr/bin/env bb
(ns oidc-client
"Get end-user access token from an OIDC provider, caching the access/refresh token in an encrypted file. Code in https://babashka.org
Usage:
/path/to/oidc_client.clj
When there are no cached, valid tokens, it will open a browser with the OIDC provider login URL and start a HTTPS-enabled
callback server on localhost. Make sure that the resulting redirect_uri is registered with your provider.
@holyjak
holyjak / fulro-modelling-puzzles.adoc
Last active February 19, 2022 18:04
Fulcro Modelling Puzzles - how would you model a requirement in code?

Fulcro Modelling Puzzles

Self note: see Obsidian

Note
Work in progress

How would you solve a requirement using code?

For some requirements it is easy to see how to map them onto the functionality and structure that Fulcro offers, while for others it might not be trivial. The goal of this document is to collect various examples of such non-trivial cases, eventually with solutions, so that people can better learn to use Fulcro.

(ns catching-transduce
"See [[catching-transduce]] below"
(:require [clojure.core.async :as a :refer [chan to-chan pipeline-blocking <!!]]))
(defmacro err-or
"If body throws an exception, catch it and return it"
[& forms]
`(try
~@forms
(catch Throwable t# t#)))
(defn stateful-map
"Returns a stateful transducer similar to `clojure.core/map-indexed` that
transforms each item with `(f state <the item>)` where `state` is built by
applying `state-building-fn` to the previous state (starting with `init`) and
the transformed item.
Ex., re-implementing map-indexed:
```clojure
(sequence (stateful-map vector (fn build-state [idx _] (if idx (inc idx) 5))) \"abc\")
; => ([nil \\a] [5 \\b] [6 \\c])
@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]
@holyjak
holyjak / fulcro-gotchas.adoc
Last active March 3, 2021 01:11
WIP Fulcro Gotchas document

Common misconceptions and pitfalls in Fulcro.

General

You query the client DB, not the server!

A common misconception is that the Root’s :query is used to load! the app data, i.e. that something like Root query → load! → Root props → rendered UI is happening. It is not. What is happening is Root query → client DB → Root props → rendered UI. You can use a query to also load some data from the backend to feed the client DB but this is up to you, has nothing to do with the just described cycle, and does not need to happen. Also, you essentially never load! the Root query. Instead, you load data for distinct UI subtrees, i.e. sub-queries. So these are two orthogonal, independent processes: rendering client data into the UI and feeding the client database.

A component’s query is relative to its parent component, only Root can "see" keys at the root of the client DB*

@holyjak
holyjak / rust_factor_out_tuple_issue.rs
Last active February 16, 2021 19:46
Problem with factoring out common code in Rust
// Read from DB, write data to CSV
extern crate csv;
extern crate oracle;
use std::error::Error;
use std::env;
use oracle::Connection;
use oracle::sql_type::FromSql;
use oracle::row
use serde::ser::{ Serialize };
@holyjak
holyjak / fulcr-ssr-test.clj
Created January 22, 2021 11:30
Experiments in Fulcro SSR with dynamic routers
(ns ssr-test
"Try server-side rendering in Fulcro where we want to display a non-default
dynamic router target.
*BEWARE*: This is an exploration. I have *no* idea what is the correct way."
(:require
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.algorithms.denormalize :as denorm]
[com.fulcrologic.fulcro.algorithms.server-render :as ssr]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
[com.fulcrologic.fulcro.dom-server :as dom :refer [div label input]]
@holyjak
holyjak / fulcro-rad-notes.md
Last active August 2, 2023 16:45
Fulcro RAD - assorted notes

Unsorted notes on Fulcro RAD.

Reports

Displaying to-one :ref attributes

Tony advises:

There are two primary ways to do this. If it is a true to one relationship, then you can simply make a resolver from person ID to address ID in pathom and then you can just include address things as columns. The other option, which works for any cardinality, is to use the report option ro/column-EQL and write a join that pulls the information you want to format in the column, and then supply a column formatter to do the formatting of the nested data.

@holyjak
holyjak / Fulcro-router-wrong-target-issue.md
Last active December 15, 2020 20:29
Description of a problem with UI displaying one target, Router beliving it displays another one.

I am running into an issue with Fulcro 3.4 and RAD 1.0.8 where the UI shows the (non-default) router target in an uninitialized state while the router believes that it is displaying the default target. I still cannot figure out why.

I have three nested routers (along with some other components): RootRouter > OrgRouter > OrgDashboard for org id=nnn > DetailsDisplayRouter with :targets [LatestBillRunList SubscriberList] and the URL .../org/123/subscribers and I expect to see the SubscriberList RAD report - which I do, but it is empty, even though the DB has the data, because the parent router believes it is displaying the other report . This only happens when I go to the URL in the browser, not when I click myself through the app to the state.

So how is it possible that DetailsDisplayRouter believes it is displaying LatestBillRunList while it should, and the UI does, show SubscriberList?!

I understand why the report is empty despite the presence of its data - Fulcro believes it is not showi