Skip to content

Instantly share code, notes, and snippets.

@geraldodev
geraldodev / migrate.clj
Last active January 22, 2023 12:49
Babashka script to download and invoke the awesome MyBatis Migrations https://mybatis.org/migrations/index.html
View migrate.clj
#!/usr/bin/env bb
; migrate command, invoker of org.apache.ibatis.migration.Migrator
; Downloads maven artifact
; it adds --path=migrations if not specified as command-line-args
; this script is meant to be on root of the project, and when executed
; like ./migrate.clj it applies the migrations on the migrations subdirectory
; to initialize migrations path use:
; ./migrate.clj init
;
; After initializing the migrations subdirectory configure the credentials
@geraldodev
geraldodev / promises-cljs.md
Created August 16, 2022 09:39 — forked from pesterhazy/promises-cljs.md
Promises in ClojureScript
View promises-cljs.md

Chaining promises

Chaining promises in ClojureScript is best done using the thread-first macro, ->. Here's an example of using the fetch API:

(-> (js/fetch "/data")
    (.then (fn [r]
             (when-not (.-ok r)
               (throw (js/Error. "Could not fetch /data")))
             (.json r)))
@geraldodev
geraldodev / use_fetcher.cljs
Created July 9, 2022 01:35
react-router use-fetcher hook "beanified" use-fetcher hook that encaspulate keeps you from using useLoaderData just for getting the result of the router load function
View use_fetcher.cljs
(ns crudis.ui.hooks.use-fetcher
(:require
["react-router-dom" :refer [useLoaderData useFetcher]]
[cljs-bean.core :refer [bean]]
))
(defn use-fetcher
[]
(let [fetcher (useFetcher)
first-page (useLoaderData)
@geraldodev
geraldodev / countries.cljs
Created June 26, 2022 12:56
react-router-dom useLoaderData example
View countries.cljs
(ns crudis.ui.routes.countries
(:require
["react-router-dom" :refer [useLoaderData]]
[crudis.util.helix :refer [defnc]]
[helix-window.fixed-size-list :as fsl]
[helix.core :as hx :refer [$ <> fnc]]
[helix.dom :as d :refer [div]]
[paqueta.fetch :as fetch]
[promesa.core :as p]
))
@geraldodev
geraldodev / client.cljs
Created June 26, 2022 12:55
root cljs app defining DataBrowserRouter from react-router
View client.cljs
(ns crudis.client
(:require
["react-dom" :as rdom]
["react-dom/client" :refer [createRoot]]
["react-router-dom" :refer [DataBrowserRouter Route]]
[crudis.util.helix :refer [defnc]]
[crudis.ui.root :as root]
[crudis.ui.routes.countries :as countries]
[helix.core :refer [$]]
[helix.dom :as d]
View row_virtualizer_example.cljs
(ns crudis.ui.root
(:require
["@tanstack/react-virtual" :refer [useVirtualizer]]
["react" :as React]
[goog.object :as gobj]
[helix.core :as hx :refer [defnc $ <> fnc]]
[helix.dom :as d :refer [div a button]]
[helix.hooks :as hooks :refer [use-state]]
[paqueta.fetch :as fetch] ;; lambdaisland fetch
))
@geraldodev
geraldodev / button.cljs
Created May 18, 2022 23:57
stitches button in cljs
View button.cljs
(ns stitches.componentes.button
(:require
[applied-science.js-interop :as j]
[stitches.config :refer [styled jsvec-to-obj]]
))
(def Button
(styled
"button"
(jsvec-to-obj
@geraldodev
geraldodev / jsx_to_helix.clj
Created May 16, 2022 09:55
Generates helix clojurescript output of a React JSX input file. The files are defined on the input-jsx and output-clj variables. the executing function is on the first line of the comment
View jsx_to_helix.clj
(ns jsx-to-helix.core
(:require
[clojure.data.xml :as xml]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
[clojure.walk :as walk]
[superstring.core :as str]
)
(:import [clojure.data.xml.node Element]))
View heading.cljs
(ns stitches.componentes.heading
(:require
["lodash.merge" :as js-merge]
["react" :as React]
[applied-science.js-interop :as j]
[crudis.util.helix :refer [defnc]]
[helix.core :refer [$]]
[stitches.componentes.text :refer [Text]]
))
@geraldodev
geraldodev / helix-autocomplete.cljs
Last active November 27, 2020 17:58
Thin layer over mui autocomplete.
View helix-autocomplete.cljs
(ns app.helix_autocomplete
(:require
["@material-ui/lab/Autocomplete" :default Autocomplete]
["@material-ui/core/TextField" :default TextField]
["react" :as r]
[goog.object :as gobj]
))
(defnc AutocompleteHelix