This file contains 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
;; Example of reducing fn that computes sufficient | |
;; statistics for a mean. | |
=> (defn mean-reducer [memo x] | |
(-> memo | |
(update-in [:sum] + x) | |
(update-in [:count] inc))) | |
=> (reduce mean-reducer {:sum 0 :count 0} (range 10)) | |
{:count 10, :sum 45} |
This file contains 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
http://example.com/js/main__V0123456789abcdef__.js |
This file contains 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
#!/usr/bin/env python | |
import os | |
import re | |
from optparse import OptionParser | |
parser = OptionParser() | |
(options, args) = parser.parse_args() |
This file contains 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. |
This file contains 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 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 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 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 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 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 |
NewerOlder