Skip to content

Instantly share code, notes, and snippets.

Avatar
💓
Loving Clojure

Jakub Holy holyjak

💓
Loving Clojure
View GitHub Profile
@holyjak
holyjak / http-server.bb
Last active Apr 6, 2021
Babashka HTTP server for serving static files, similar to `python -m http.server` but more flexible :)
View http-server.bb
#!/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-exercises---repl.clj
Last active Mar 4, 2021
Learn Fulcro through small, progressively more complicated, tasks
View fulcro-exercises---repl.clj
(ns fulcro-exercises.core
"This is a series of exercises to help you learn Fulcro, via the REPL.
Prerequisities:
- running Shadow-cljs via `clojure -M:serve`
- opened the webpage in Chrome, with Fulcro Inspect installed and open
- connected to its cljs REPL
How to use:
- Load this file into the cljs REPL
@holyjak
holyjak / fulcro-gotchas.adoc
Last active Mar 3, 2021
WIP Fulcro Gotchas document
View fulcro-gotchas.adoc

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 Feb 16, 2021
Problem with factoring out common code in Rust
View rust_factor_out_tuple_issue.rs
// 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 };
View fulcro-rationale.adoc

Why Fulcro?

Fulcro was born out of the search for sustainable software development of full-stack, non-trivial (web) applications. In other words, it aims to keep complexity under control so that it does not explode as your codebase grows and time goes. It also distinguishes itself by the focus on developer-friendliness: related things are located together and it is easy to navigate (Command/Control-click) to all important code artifacts (instead of being forced to search for string IDs or keywords).

This leads to the following decisions:

  • UI = f(state) - React came with the idea that the UI is just a pure function of data but Fulcro really means it. When you have a problem, look at the data, not the UI. 99% of the time it is there.

  • Components declare their data needs ("query") - because nobody else knows or should care about what data the component needs. And these queries are composable so that we can fetch the data needed by the whole UI (sub)tree at once.

  • Graph API: The UI is a a tree (i.e. a

@holyjak
holyjak / fulcr-ssr-test.clj
Created Jan 22, 2021
Experiments in Fulcro SSR with dynamic routers
View fulcr-ssr-test.clj
(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 Apr 13, 2021
Fulcro RAD - assorted notes
View fulcro-rad-notes.md

Unsorted notes on Fulcro RAD.

Reports

Displaying to-one :ref attributes

If you have a :ref attribute, you typically do not want to display it directly, i.e. its ident, but a more display-friendly prop of the child entity. This is handled automatically for you by Pathom, you only need to specify the attribute you want.

Let's assume you have a Person entity with the ref attribute person/home-address with the target address/id. You can simply have ro/columns [person/name ... address/city address/country] (assuming these attributes are defined and have :address/id among their ao/identities). Pathom can navigate from person/home-address -> address/id -> address/city etc.

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

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

@holyjak
holyjak / deps.edn
Last active Oct 30, 2020
cryogen deps
View deps.edn
;; Put this inside your blog and use the clojure CLI instead of leiningen to run `clojure -X:serve`
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
ring-server/ring-server {:mvn/version "0.5.0"}
ring/ring-devel {:mvn/version "1.7.1"}
compojure/compojure {:mvn/version "1.6.1"}
#_#_cryogen-core/cryogen-core {:mvn/version "0.3.2"}
cryogen-asciidoc/cryogen-asciidoc {:mvn/version "0.3.2"}
cryogen-flexmark/cryogen-flexmark {:mvn/version "0.1.4"}
cryogen-core/cryogen-core {:git/url "https://github.com/cryogen-project/cryogen-core" :sha "17cdf3837f17b9b921dce09e4638495984e65a2a"}
}
@holyjak
holyjak / troubleshooting 404 in Spring MVC.md
Created Oct 22, 2020
WIP - troubleshooting 404 in Spring MVC 4
View troubleshooting 404 in Spring MVC.md

Spring 4 - 404 troubleshooting

See https://www.baeldung.com/spring-handler-mappings - explains BeanNameUrlHandlerMapping, SimpleUrlHandlerMapping

Debug DispatcherServlet - DispatcherServlet.getHandler