Skip to content

Instantly share code, notes, and snippets.

@thosmos
thosmos / specfn.clj
Created September 5, 2018 06:46 — forked from borkdude/specfn.clj
Use a spec for defining function arguments and get validation automatically
(ns specfn.core
(:require [clojure.spec :as s]
[clojure.spec.test :as t]))
(defn- spec-symbols [s]
(->> s
(drop 1)
(partition-all 2)
(map first)
(map name)
@thosmos
thosmos / 1_routing.cljs
Last active February 7, 2019 18:04
fulcro dynamic routing + code splitting
(defsc-route-target AboutPage [this props]
{:query [{:about-comp ['*]}]
:ident (fn [] [:PAGE/by-id :about])
:initial-state {:about-comp {}}
:route-segment (fn [] ["about"])
:route-cancelled (fn [_])
:will-enter (fn [reconciler route-params]
(if (get-in @st/pending-route [:about :is-loaded])
(dr/route-immediate [:PAGE/by-id :about])
(dr/route-deferred [:PAGE/by-id :about]
@thosmos
thosmos / about.cljs
Created February 16, 2019 04:56
fulcro code-split routing
(defsc AboutComp [this {:keys [about/hello]}]
{:query [:about/hello]
:initial-state {:about/hello "Hello from the About module!"}}
(do
(debug "Rendering AboutComp")
(segment
(header
"ABOUT COMP")
(message
hello))))
@thosmos
thosmos / validation.cljs
Created February 9, 2020 20:51
Fulcro Validator with custom error strings
(defn make-validator
"Create a form/field validation function using a supplied field checker. The field checker will be given
the entire form (denormalized) and a single field key that is to be checked. It must return
a boolean indicating if that given field is valid or not, or a custom error map if invalid.
During a recursive check for a form, the validation function will be in the correct context (e.g. the form supplied will contain
the field. There is no need to search for it in subforms).
make-validator returns a three arity function:
- `(fn [form] ...)` - Calling this version will return :unchecked, :valid, or :invalid for the entire form.
- `(fn [form field] ...)` - Calling this version will return :unchecked, :valid, or :invalid for the single field.
@thosmos
thosmos / benchmark-pristine->entity
Created February 10, 2020 19:59
benchmark a few options for fulcro3 form-state/pristine->entity*
(in-ns 'user)
(require
'[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
'[com.fulcrologic.fulcro.algorithms.form-state :as fs]
'[com.fulcrologic.fulcro.algorithms.normalize :as fnorm])
(defsc Person [this props]
{:query [:db/id ::person-name ::person-age
fs/form-config-join]
:ident [:person/id :db/id]
@thosmos
thosmos / benchmark-pristine->entity.cljs
Last active February 10, 2020 21:09
cljs benchmark pristine->entity
(ns riverdb.ui.bench
(:require
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
[com.fulcrologic.fulcro.dom :as dom :refer [div]]
[com.fulcrologic.fulcro.algorithms.form-state :as fs]
[com.fulcrologic.fulcro.algorithms.normalize :as fnorm]))
(defsc Person [this props]
{:query [:db/id ::person-name ::person-age
fs/form-config-join]

Keybase proof

I hereby claim:

  • I am thosmos on github.
  • I am thosmos (https://keybase.io/thosmos) on keybase.
  • I have a public key ASDr34LMnE3iK29HEAqWRne-zjMLUUaMIFwQSGTNQbpWYwo

To claim this, I am signing this object:

@thosmos
thosmos / gravity_val_notes.txt
Last active February 1, 2022 15:51
gravity validator useful commands
# query balances of a delegator key (AKA validator key)
gravity q bank balances gravity1dt7zu2evtce5mx7n6t0fledu0dsnglkfdk8e3w
# query pending delegator rewards (rewards for delegating to a validator)
gravity q distribution rewards gravity1dt7zu2evtce5mx7n6t0fledu0dsnglkfdk8e3w
# query pending validator commission (rewards for running a validator, often ~%10 of a validator's rewards)
gravity q distribution commission gravityvaloper1dt7zu2evtce5mx7n6t0fledu0dsnglkfua78m6
# withdraw delegator rewards from a specific validator
#!/bin/bash
START="2022-04-01"
END="2022-05-01"
IPS=(
"fdab:4482:93bf:548b:6f7b:df86:84ee:9847"
"fd58:6f40:8a64:c3a2:43f0:dad6:26f6:5c03"
)
const START = process.env.START || "2022-01-01"
const END = process.env.END || "2023-01-01"
/*
On Mac OS zsh Call like:
ssh j11 "PASS=`grep dashboard_password /etc/rita.toml | tr -d '\"' | sed \"s/rita_dashboard_password = //\"`; curl -u rita:$PASS localhost:4877/usage/client" | node process-usage.js
In bash, call like: