Skip to content

Instantly share code, notes, and snippets.

@cbillowes
Last active July 22, 2018 08:20
Show Gist options
  • Save cbillowes/b1ebd2fbc1acff1f3d7c7dbec09f7e12 to your computer and use it in GitHub Desktop.
Save cbillowes/b1ebd2fbc1acff1f3d7c7dbec09f7e12 to your computer and use it in GitHub Desktop.
Nifty Snippets
; https://stackoverflow.com/questions/36032562/extract-values-from-vector-of-maps-conditionally-in-clojure
(map val (filter (comp #{:a} key) (apply concat vector-of-maps)))
; Grab URL from JavaScript window API
(ns awesome.stuff.to.learn
(:require [cemerick.url :as url]))
(defn [] (:anchor (url/url (-> js/window .-location .-href))))
; (compare-and-swap) function takes four arguments: an entity id, an attribute, an old value, and a new value.
; htps://docs.datomic.com/on-prem/transactions.html#dbfn-cas
(defn update-entity
[params]
(let [conn awesome.db.datomic/conn
db (d/db conn)
entity-id (Long/parseLong (:entity-id params))
entity (get-entity db entity-id)]
{:db-after @(d/transact conn
[[:db.fn/cas (:id entity) :entity/name (:name entity) (:entity-name params)]
[:db.fn/cas (:user-id entity) :user/email (:user-email entity) (:user-email params)]])}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment