Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active May 26, 2016 09:10
Show Gist options
  • Save Deraen/42fd892648c24e96a12b0881b8e3488a to your computer and use it in GitHub Desktop.
Save Deraen/42fd892648c24e96a12b0881b8e3488a to your computer and use it in GitHub Desktop.
var db = new PouchDB('mydb');
db.post({}).then(function (result) { // post a new doc
return db.get(result.id); // fetch the doc
}).then(function (doc) {
console.log(doc); // log the doc
}).catch(function (err) {
console.log(err); // log any errors
});
let db = new PouchDB('mydb');
try {
let result = await db.post({});
let doc = await db.get(result.id);
console.log(doc);
} catch (err) {
console.log(err);
}
(.setTimeout
(fn [_] (js/console.log "Hello World"))
1000)
(def beers (atom 0))
(defn beer-counter [{:keys [name]}]
[:div
[:h1 "Hello, " name]
[:p "You have drank " @beers " beers"]
[:button
{:on-click #(swap! beers inc)}
"Drink a beer"]])
(defn beer-counter [{:keys [name]}]
(let [beers (r/atom 0)]
(fn [{:keys [name]}]
[:div
[:h1 "Hello, " name]
[:p "You have drank " @beers " beers"]
[:button
{:on-click #(swap! beers inc)}
"Drink a beer"]])))
;; HelsinkiJS
(def a {:a-map "This is a map"})
(def b (assoc a :new-key "Value"))
(let [c ["a" "vector" "is" "like" "an" "array"]
d (map clojure.string/upper-case c))]
d) ;; => ("A" "VECTOR" ...)
;; Map is lazy and the result is only realized when needed
(reduce + 0 [1 2 3]) ;; => 6
(go
(let [response (<! (http/get "/url"))]
(if (http/success? response)
(do-something response)
(js/console.error response))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment