Skip to content

Instantly share code, notes, and snippets.

@dustingetz
dustingetz / electric-todomvc.md
Last active August 6, 2023 03:30
Photon TodoMVC, with a twist!

TodoMVC, with a twist! — Electric Clojure

  1. it's multiplayer! 0 LOC cost
  2. state is durable! (server side database) 0 LOC cost
  3. See those pending spinners? We've added a server delay to demonstrate managed load states.
20220817.todomvc.mp4

Electric is a "multi tier" Clojure/Script dialect for full-stack web application development. It uses macros to let you interweave client and server code in a single .CLJC file, so you can define a full-stack frontend/backend webapp all in one place. Electric is designed for rich dynamic applications with reactive user interfaces and complex frontend/backend data sync requirements.

@dustingetz
dustingetz / photon todomvc .cljc
Last active August 18, 2022 17:13
Photon TodoMVC, with a twist!
(ns user.demo-5-todomvc
"Requires -Xss2m to compile. default 1m JVM ThreadStackSize is exceeded by photon compiler due to large macroexpansion
resulting in false StackOverflowError during analysis."
(:require #?(:clj [datascript.core :as d])
[hyperfiddle.photon :as p]
[hyperfiddle.photon-ui :as ui]
[hyperfiddle.photon-dom :as dom])
#?(:cljs (:require-macros user.demo-5-todomvc)))
(defonce !conn #?(:clj (d/create-conn {}) :cljs nil)) ; server
(ns user.demo-4-webview
"Photon fullstack query/view composition with client/server transfer"
(:require [datascript.core :as d]
[hyperfiddle.photon :as p]
[hyperfiddle.photon-dom :as dom]
[hyperfiddle.photon-ui :as ui]
user.util)
#?(:cljs (:require-macros user.demo-4-webview)))
(defonce conn #?(:cljs nil ; state survives reload
@dustingetz
dustingetz / photon todo demo .cljc
Last active August 15, 2022 21:47
Full stack, multiplayer todo list app in one file
(ns app
"Full stack, multiplayer todo list app in one file"
(:require [datascript.core :as d]
[hyperfiddle.photon :as p]
[hyperfiddle.photon-dom :as dom]
[hyperfiddle.photon-ui :as ui])
#?(:cljs (:require-macros app)))
(defonce !conn #?(:clj (d/create-conn {}) :cljs nil))
(require '[hyperfiddle.photon :as p]
'[hyperfiddle.api :as hf])
(hfql [{(submissions "")
[{(:dustingetz/shirt-size . {::hf/options (shirt-sizes gender)})
[:db/id :db/ident]}
{(:dustingetz/gender . {::hf/options (genders)})
[:db/id (:db/ident . {::hf/as gender})]}]}
{(genders)
[:db/ident]}])
@dustingetz
dustingetz / crud.cljc
Last active February 20, 2022 02:06
100 LOC crud app
(ns user.blog-100-loc-crud-app
"Concrete minimum viable crud app that demonstrates strong composition and real world edge cases"
(:require
[clojure.spec.alpha :as s]
#?(:clj [datomic.api :as d])
[hyperfiddle.api :as hf]
[hyperfiddle.photon :as p]
[hyperfiddle.photon-dom :as dom]
[hyperfiddle.html5 :as-alias html]))
(ns dustin.y2021.missionary_promise
(:require [hyperfiddle.rcf :as rcf :refer [tests % !]]
[missionary.core :as m]))
; We want to turn a promise-thing into a Task
; Leo: The problem with Promise and CompletableFuture is no cancellation
; What task do we want? Is the task listening to the promise? Or is the task the process backing the promise?
; Background: when you get a promise, there is a process in the background which eventually completes the promise.
; Do you want to await the result of an already running promise
; or do you want to run the process of the promise when the task is run?
(ns leo.file-watcher
(:require
[clojure.edn :as edn]
[clojure.java.io :as io]
[missionary.core :as m])
(:import
(java.nio.file Path FileSystems Paths WatchEvent$Modifier StandardWatchEventKinds
StandardWatchEventKinds$StdWatchEventKind WatchEvent)
(com.sun.nio.file SensitivityWatchEventModifier)
(java.io File PushbackReader)))
(ns hyperfiddle.via
(:require
[meander.epsilon :as m :refer [match]]
[meander.strategy.epsilon :as r]
[minitest :refer [tests]]))
(comment
; Goal here is to implement async/await sugar like this:
(via* (->Maybe)
(ns user.dustin.bind10
(:require
[contrib.do :refer [Do-via via* !]]
[meander.epsilon :as m :refer [rewrite]]
[meander.strategy.epsilon :as r]))
(declare do> mlet pure fmap fapply bind)
(comment