Skip to content

Instantly share code, notes, and snippets.

View mathias's full-sized avatar

Matt Gauger mathias

View GitHub Profile
(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]
(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)
(defn create-route
[verb path handler]
(fn [continue]
(fn [req]
(if (= path (get req :path))
(handler req)
(continue req)))))
(def dispatcher
((comp
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"
(defn dispatcher [req]
(if (= "/" (get req :path))
(index-handler)
(if (= "/users" (get req :path))
(users-handler)
(404-handler) ;; no route matched, reply 404
)))
(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
;; 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]]
(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)
(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"
$ 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...