This file contains hidden or 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
| (extend-type js/NodeList | |
| ISeq | |
| (-first [nodes] | |
| (aget nodes 0)) | |
| (-rest [nodes] | |
| (for [n (range 1 (.-length nodes))] | |
| (aget nodes n))) | |
| ISeqable | |
| (-seq [nodes] nodes)) |
This file contains hidden or 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
| (def ads-api "http://192.241.130.213:8080/user/15/ads-api/") | |
| (defmodel account | |
| {:url "accounts/:id" :api ads-api}) | |
| (defcollection accounts | |
| {:url "accounts" :model account :api ads-api}) | |
| (defmodel campaign | |
| {:url "accounts/:account-id/campaigns/:id" :api ads-api}) |
This file contains hidden or 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 render [view to-el] | |
| (dommy/append! (sel1 to-el) view)) | |
| (defn gen-clock [] | |
| (let [time (model/model {} {:time (str (js/Date.))})] | |
| (go! [time time] | |
| (<! (timeout 1000)) | |
| (pub! time :update {:time (str (js/Date.))})) | |
| time)) |
This file contains hidden or 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
| (extend-type object | |
| IWithMeta | |
| (-with-meta [obj meta] | |
| (set! (.-meta obj) meta) obj) | |
| IMeta | |
| (-meta [obj] (.-meta obj)) | |
| IEquiv | |
| (-equiv [obj other] |
This file contains hidden or 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
| (defmacro future | |
| [& body] | |
| `(mvc.impl.future/future-call (fn [] (cljs.core.async.macros/go ~@body)))) | |
| (defn future-call | |
| ([f] | |
| (let [p (promise) | |
| task (fn [] | |
| (try (let [val (atom {:done false :cancelled false :value p}) | |
| val-chan (chan)] |
This file contains hidden or 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
| (def resource-agent | |
| (memoize | |
| (fn [url] | |
| (agent #{} | |
| :validator (fn [state] (set? state)) | |
| :error-handler #(.log js/console "ERROR: " %1 %2) | |
| :error-mode :fail)))) | |
| ;; now what's an agent? |
This file contains hidden or 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
| (let [rs (resource-agent (:url account)) | |
| a (model-agent (:foreign-key (meta rs) id model))] | |
| (add-watch rs (:id (meta a)) | |
| (fn [k ref old-state new-state] | |
| (when (empty? (clojure.set/intersection @a new-state)) | |
| (reset! a (select #(= (:id (meta a)) (:id %)) new-state))))) | |
| (add-watch a :update | |
| (fn [k ref old-state new-state] | |
| (when (empty? (clojure.set/intersection @rs new-state)) | |
| (send rs #(-> % |
This file contains hidden or 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
| (def campaigns @campaign-agent) | |
| ;; after being deref'd it's just a normal persistent data structure! The power of functional programming at our fingertips! | |
| (def names (project campaigns [:name])) | |
| #{{:name "Calling Max Steel fans_KW in Timeline Mobile"} {:name "Calling Max Steel \ | |
| fans"} {:name "First Promoted Account campaign"} {:name "Meet Max Steel_#myhero"} {\ | |
| :name "You and Your Child_#myhero"} {:name "First Promoted Tweets campaign"} {:name\ | |
| "You and Your Child_ DJ Cole"} {:name "You and Your Child_#myhero Search KW"} {:na\ | |
| me "Calling Max Steel fans_-KW in Timeline Desktop_Media Targets"} {:name "Calling \ |
This file contains hidden or 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 as-usd | |
| [n] | |
| (/ n 1e6)) | |
| (defn avg-daily-budget | |
| [campaigns] | |
| (->> (project campaigns [:daily-budget-amount-local-micro]) | |
| (map vals) | |
| (map first) |
This file contains hidden or 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 usd | |
| [n] | |
| (/ n 1e6)) | |
| (defn avg-daily-budget | |
| [campaigns] | |
| (->> (project campaigns [:daily-budget-amount-local-micro]) | |
| (map vals) | |
| (map first) | |
| (reduce +) |