This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn route-matches? | |
[method url req] | |
(and (= url (get req :url)) | |
(= method (get req :method)))) | |
(defn create-route | |
[method url handler] | |
(fn [continue] | |
(fn [req] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn route-matches? | |
[verb path req] | |
(and (= path (get req :url)) | |
(= verb (get req :method)))) | |
(defn create-route | |
[verb path handler] | |
(fn [continue] | |
(fn [req] | |
(if (route-matches? verb path req) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn create-route | |
[verb path handler] | |
(fn [continue] | |
(fn [req] | |
(if (= path (get req :path)) | |
(handler req) | |
(continue req))))) | |
(def dispatcher | |
((comp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (def dispatcher (comp | |
(fn [continue] | |
(fn [req] | |
(if (= "/" (get req :path)) | |
"index" | |
(continue req)))) | |
(fn [continue] | |
(fn [req] | |
(if (= "/users" (get req :path)) | |
"users" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn dispatcher [req] | |
(if (= "/" (get req :path)) | |
(index-handler) | |
(if (= "/users" (get req :path)) | |
(users-handler) | |
(404-handler) ;; no route matched, reply 404 | |
))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn text-input-cell [name id label-text cell] | |
(let [setter-fn #(reset! cell (val-id id))] | |
(span | |
(label :name name | |
(text "~{label-text}")) | |
(input :type "text" | |
:name name | |
:id id | |
:value cell | |
:on-change setter-fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Given data like [?name ?count], I want to find the maximum count among all the counts and return the name attached to it. | |
;; This query works but only gives me the count when I want ?name: | |
(d/q '[:find (max ?count) | |
:where [?name ?count]] | |
[["Bob" 2] | |
["Chris" 3] | |
["Doug" 1]]) | |
;=> [[3]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(page "foo.html") | |
(defc cells []) | |
(defn make-text-field [cell id lbl] | |
"Makes a text field. Arguments: the cell the on-change function | |
looks up its id in to change the value for the text given, and a label for the field." | |
(div | |
(label :name id lbl) | |
(br) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(page "foo.html") | |
(defn make-text-field [cell id lbl] | |
"Makes a text field. Arguments: the cell the on-change function | |
looks up its id in to change the value for the text given, and a label for the field." | |
(div | |
(label lbl) | |
(br) | |
(input :id id | |
:type "text" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tessel run home-sensors.js --listen all | |
TESSEL! Connected to TM-00-04-f000da30-004e4f3c-26682586. | |
INFO Bundling directory /Users/mathiasx/dev/tessel-weather | |
INFO Deploying bundle (1.94 MB)... | |
Tessel is reading 2031104 bytes... | |
Populating filesystem... | |
Starting script: /_start.js | |
Initializing runtime... |