Skip to content

Instantly share code, notes, and snippets.

(defn task-list []
(let [visible-todos @(subscribe [:visible-todos])
all-complete? @(subscribe [:all-complete?])]
[:section#main
[:input#toggle-all
{:type "checkbox"
:checked all-complete?
:on-change #(dispatch [:complete-all-toggle])}]
[:label
{:for "toggle-all"}
@alexanderjamesking
alexanderjamesking / errors.clj
Created October 7, 2021 20:02 — forked from adambard/errors.clj
An example of functional error handling in clojure.
(ns example.errors)
(defn clean-address [params]
"Ensure (params :address) is present"
(if (empty? (params :address))
[nil "Please enter your address"]
[params nil]))
(defn clean-email [params]
"Ensure (params :email) matches *@*.*"
(try
(d/catch (d/chain (throw (ex-info "standard failure" {:type :foo})))
(fn [e]
(println "d/catch e" (.getMessage e))))
(catch Exception e
(println "try/catch e" (.getMessage e))))
(try
(d/catch (d/chain (d/error-deferred (ex-info "deferred error" {:type :bar})))
(fn [e]
@alexanderjamesking
alexanderjamesking / RDF in Turtle to PDF Graph
Created September 15, 2018 10:11 — forked from crstn/RDF in Turtle to PDF Graph
Create a graph visualization from an RDF file using http://librdf.org/raptor/ and http://www.graphviz.org.
rapper -i turtle -o dot model.ttl | dot -Tpdf -omodel.pdf
### Keybase proof
I hereby claim:
* I am alexanderjamesking on github.
* I am ajking (https://keybase.io/ajking) on keybase.
* I have a public key ASD5bNI-pQZ6-aYSsCLkh8HAxsGsr2YevK3WVSSl-3HBmAo
To claim this, I am signing this object:
(ns spy-example.core-test
(:require [clojure.test :refer [deftest testing is]]
[spy.core :as spy]))
(def beatle->email
{:john "[email protected]"
:paul "[email protected]"
:george "[email protected]"
:ringo "[email protected]"})
(def beatle->email
{:john "[email protected]"
:paul "[email protected]"
:george "[email protected]"
:ringo "[email protected]"})
(defn lookup-email [beatle-id]
(get beatle->email beatle-id))
(defn send-message [email message]
(require '[clojure.test :refer [is]])
(defn random-beatle []
(case (rand-int 4)
0 "John"
1 "Paul"
2 "George"
3 "Ringo"))
(defn hello-beatle [get-beatle]
(require '[clojure.test :refer [is]])
(defn random-beatle []
(case (rand-int 4)
0 "John"
1 "Paul"
2 "George"
3 "Ringo"))
(defn hello-beatle []