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
| // Demonstration of how easy it is for this to mess up your loops. | |
| var txt = ["a","b","c"]; | |
| for (var i = 0; i < 3; ++i ) { | |
| var msg = txt[i]; | |
| setTimeout(function() { alert(msg); }, i*1000); | |
| } | |
| // Alerts 'c', 'c', 'c' |
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
| # Should enable the little battery icon. | |
| xfce4-power-manager | |
| echo "Setting middle button emulation" | |
| xinput set-int-prop 12 "Evdev Middle Button Emulation" 8 1 | |
| echo "Turning off dual mode video" | |
| sudo sh -c "echo OFF > /sys/kernel/debug/vgaswitcheroo/switch" | |
| echo "Turhing off bluetooth" |
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
| ;; Start of what the above flow in clojure would look like. | |
| ;; Tokenization step. | |
| (->> (clojure.string/split (slurp "/tmp/X") #" ") tokenize-word) | |
| ;; For debugging, just look at the first 100 words... | |
| (->> (clojure.string/split (slurp "/tmp/X") #" ") tokenize-word (take 100)) | |
| ;; or, look at some in the middle... | |
| (->> (clojure.string/split (slurp "/tmp/X") #" ") |
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
| ;; Install dependencies | |
| lein deps | |
| ;; Build my ClojureScript. | |
| lein cljsbuild once | |
| ;; Start me listening on port 8888. | |
| lein run |
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
| ;; All the visitors to my site. | |
| #> (->> (all-visitors) count) | |
| 1000 | |
| ;; Which browsers? | |
| #> (->> (all-visitors) (map :browser) frequencies) | |
| {:ie-10 50 :ie-9 250 :ie-8 200 :firefox 140 :chrome 360} | |
| ;; Average spend? | |
| #> (let [spent (->> (all-visitors) (keep :spend))] | |
| (/ (reduce + spent) (count spent))) | |
| 123.12 |
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
| ;; Simple mean function. | |
| #> (defn compute-mean [xs] (/ (reduce + xs) (count xs))) | |
| ;; Check the average spend for firefox. | |
| #> (->> (all-visitors) | |
| (filter #(-> % :browser (= :firefox))) | |
| (keep :spend) | |
| compute-mean) | |
| 100.2 |
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
| ;; Create a function that given visitors, computes | |
| ;; the spend for each - here, just a random number. | |
| user> (defgraphfn spends [raw-visitors] | |
| (map (fn [_] (rand-int 10)) | |
| raw-visitors)) | |
| #'user/spends | |
| ;; Create a function that given visitors, computes the | |
| ;; browser for each - here, just randomly assigned. | |
| user> (defgraphfn browsers [raw-visitors] |
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
| ;; Update our 'browsers' function to print when it's run. | |
| user> (defgraphfn browsers [raw-visitors] | |
| (println "Running browsers on" (count raw-visitors) "visitors") | |
| (map (fn [_] (rand-nth [:chrome :firefox :ie-9]) ) | |
| raw-visitors)) | |
| #'user/browsers | |
| ;; and run our computation graph lazily. | |
| user> (defn all-visitors [] | |
| (run-graph-strategy |
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
| ;; Babbage provides some built-in simple accumulators. | |
| user> (use 'babbage.core) | |
| user> (require '[babbage.provided.core :as p]) | |
| nil | |
| ;; Create several sets of interest. | |
| user> (def mysets | |
| (sets {:firefox? #(-> % :browser (= :firefox)) | |
| :chrome? #(-> % :browser (= :chrome)) | |
| :ie? #(-> % :browser #{:ie-7 :ie-8 :ie-9 :ie-10}) |
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
| ;; In project.clj | |
| :plugins [[s3-wagon-private "1.1.2"]] | |
| :repositories {"private" {:url "s3p://mybucket/releases/" | |
| :passphrase :env | |
| :username :env}} | |
| ;; Gotcha 1: Using :creds :env didn't seem to work for me. | |
| ;; Gotcha 2: Using a location of just s3p://mybucket didn't | |
| ;; seem to work, the releases/ directory is needed. |