Skip to content

Instantly share code, notes, and snippets.

@madvas
madvas / handlers.cljs
Created October 3, 2016 17:26
:contract/settings-loaded
(reg-event-db
:contract/settings-loaded
interceptors
(fn [db [[max-name-length max-tweet-length]]]
(assoc db :settings {:max-name-length (.toNumber max-name-length)
:max-tweet-length (.toNumber max-tweet-length)})))
@madvas
madvas / handlers.cljs
Last active October 3, 2016 17:29
:blockchain/my-addresses-loaded
(reg-event-fx
:blockchain/my-addresses-loaded
interceptors
(fn [{:keys [db]} [addresses]]
{:db (-> db
(assoc :my-addresses addresses)
(assoc-in [:new-tweet :address] (first addresses)))
:web3-fx.blockchain/balances
{:web3 (:web3 db/default-db)
:addresses addresses
@madvas
madvas / handlers.cljs
Created October 3, 2016 17:34
:new-tweet/send
(reg-event-fx
:new-tweet/send
interceptors
(fn [{:keys [db]} []]
(let [{:keys [name text address]} (:new-tweet db)]
{:web3-fx.contract/state-fn
{:instance (:instance (:contract db))
:web3 (:web3 db)
:db-path [:contract :send-tweet]
:fn [:add-tweet name text
0xbBC5eE8be95683983dF67260B0AB033c237Bde60
@madvas
madvas / partial-right.clj
Created June 13, 2015 12:40
Clojure partial-right (Like a partial, but arguments are added to the end)
(defn partial-right
"Takes a function f and fewer than the normal arguments to f, and
returns a fn that takes a variable number of additional args. When
called, the returned function calls f with additional args + args."
([f] f)
([f arg1]
(fn [& args] (apply f (concat args [arg1]))))
([f arg1 arg2]
(fn [& args] (apply f (concat args [arg1 arg2]))))
([f arg1 arg2 arg3]
@madvas
madvas / cljs-react-material-ui-reagent-example.cljs
Created May 13, 2016 16:26
Snippet example of using library cljs-react-material-ui with Reagent
(ns crmui-reagent.core
(:require
[cljsjs.material-ui]
[cljs-react-material-ui.core :as ui]
[cljs-react-material-ui.reagent :as rui]
[cljs-react-material-ui.icons :as ic]
[reagent.core :as r :refer [atom]]
[reagent.session :as session]
[secretary.core :as secretary :include-macros true]
[accountant.core :as accountant]