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
;; for context: | |
;; http://stackoverflow.com/questions/7086464/maximum-single-sell-profit/ | |
(def PRICES [5 10 4 6 7 1 7]) | |
(defn day [[ndx low profit sell-ndx] price] | |
(let [nprofit (max profit (- price (or low price))) | |
nlow (if low (min low price) price) | |
nsell-ndx (if (> nprofit profit) ndx sell-ndx)] |
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
; element at index i represents the stock price at day i | |
(def PRICES [10 1 45 12 11 4 8 2]) | |
; what is the best possible trade? | |
; (assumes 20/20 hindsight) | |
(defn possible-trades [prices] | |
(for [j (range (count prices)) | |
i (range j) | |
:let [[buy sell] (map prices [i j]) |
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
; element at index i represents the stock price at day i | |
(def PRICES [10 1 45 12 11 4 8 2]) | |
; what is the best possible trade? | |
; (assumes 20/20 hindsight) | |
(defn possible-trades [prices] | |
(for [i (range (count prices)) | |
j (range (count prices)) | |
:when (< i j) |
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
;; | |
;; Source code I used to demo mturk.clj | |
;; | |
;; added to templating.clj | |
(defn selection-q-form-xml [{:keys [instructions selections select-style]}] | |
(str XML-PREFIX | |
(html | |
[:QuestionForm {:xmlns "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd"} | |
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
(defn vdiff [v1 v2] | |
(when (not= v1 v2) | |
[v1 v2])) | |
(defn when-diffs [m] | |
(when (some identity (vals m)) | |
m)) | |
(defn aaron-diff [x y] | |
(when-diffs |
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
(defn run-opts [opts] | |
(let [opts (merge {:auto true} opts)] | |
(set-options opts) | |
(with-workflow-file #(run % (:targetv opts))))) | |
(defn -run_opts | |
"Explicitly for use from Java" | |
[opts] | |
(let [opts (into {} (for [[k v] opts] [(keyword k) v]))] | |
(run-opts opts))) |
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
{ "address" : "82 Hawarden Crescent", | |
"address_extended" : "82 Hawarden Crescent, Sunderland, United Kingdom", | |
"category" : [ "establishment" ], | |
"country" : "GB", | |
"latitude" : 54.897776999999998, | |
"locality" : "Sunderland", | |
"longitude" : -1.406487, | |
"name" : "Wallseal Preservation", | |
"postcode" : "SR4 7NL", | |
"reference" : "CoQBcwAAAEwsjwzPGUmhVEFtVY9GL6QNwaLwGw1gLV0oPYPx53RufksQ1o1vdVtgopROoawFJX9JaIJfcLKsQqRA0PItkP5VWLoJ_3EpWlEu1EOfTkdV6Ai6lql0ehk-NbOqN1LT__S4RoMBKeITH_l4f05ODidOTWFAwUmaNYAdVMWZ1jESEhBFaq4z4-gUDB2-ssAOZ2alGhS0vrEQgDIquCWroCbh3Hc3hQStZQ", |
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
{"address_components" | |
[{"long_name" "290", "short_name" "290", "types" ["street_number"]} | |
{"long_name" "Upper Richmond Rd", | |
"short_name" "Upper Richmond Rd", | |
"types" ["route"]} | |
{"long_name" "Putney", | |
"short_name" "Putney", | |
"types" ["locality" "political"]} | |
{"long_name" "London", | |
"short_name" "London", |
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
; | |
; Fetches sorted people from HDFS, keeping only a select few, and | |
; sorting by name. | |
; | |
; Output is like: | |
; Artem Boytsov,310-100-0000 | |
; Vinnie Pepi,+86-310-400-0000 | |
; Will Lao,+86-310-600-0000 | |
; | |
people <- hdfs://peeps/everyone |
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
; | |
; Grabs us some data from the Internets | |
; | |
contracts.csv <- | |
curl http://www.ferc.gov/docs-filing/eqr/soft-tools/sample-csv/contract.txt > $OUTPUT | |
; | |
; Filters out all but the evergreen contracts | |
; | |
evergreens.csv <- contracts.csv |
NewerOlder