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
| (ns wc.core | |
| (:require [clojure.core.reducers :as r])) | |
| (defn char-counter [key init pred] | |
| (fn [reducing-fn] | |
| (fn | |
| ([acc] | |
| (reducing-fn acc)) | |
| ([acc c] | |
| (reducing-fn (if (pred 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
| foo.core=> (def few-numbers (range 2)) | |
| #'foo.core/few-numbers | |
| foo.core=> few-numbers | |
| (0 1) | |
| foo.core=> (def many-numbers (range 100)) | |
| #'foo.core/many-numbers | |
| foo.core=> many-numbers | |
| (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99) | |
| foo.core=> (bench (apply + few-numbers)) | |
| Evaluation count : 543551760 in 60 samples of 9059196 calls. |
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 urls {:vg "https://www.vg.no", :ap "https://www.ap.no", :db "https://www.db.no"} ) | |
| (defn my-get-request [[k url]] | |
| [k (future (http/get url))]) | |
| (->> urls | |
| (map my-get-request) | |
| (reduce (fn [acc [k v]] | |
| (assoc acc k (deref v))) {})) |
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
| {:paths ["resources" "src"] | |
| :deps {org.clojure/clojure {:mvn/version "RELEASE"} | |
| org.clojure/test.check {:mvn/version "RELEASE"}} | |
| :aliases | |
| {:test {:extra-paths ["test"] | |
| :extra-deps {org.clojure/test.check {:mvn/version "RELEASE"}}} | |
| :runner | |
| {:extra-deps {com.cognitect/test-runner | |
| {:git/url "https://github.com/cognitect-labs/test-runner" | |
| :sha "76568540e7f40268ad2b646110f237a60295fa3c"}} |
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 checkpoints (atom (list (now)))) | |
| (defn duration [checkpoints] | |
| (/ (double (- (first checkpoints) (second checkpoints))) | |
| 1000000.0)) | |
| (defn new-checkpoint! [checkpoint checkpoints] | |
| (conj checkpoints checkpoint)) | |
| (swap! checkpoints (partial new-checkpoint! (now))) |
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
| ;; import Data.Monoid ((<>)) | |
| ;; prompt :: String -> IO (IO ()) | |
| ;; prompt attribute = do | |
| ;; putStrLn ("What is your " ++ attribute ++ "?") | |
| ;; x <- getLine | |
| ;; return (putStrLn ("Your " ++ attribute ++ " is: " ++ x)) | |
| ;; runWizard :: IO (IO a) -> IO a | |
| ;; runWizard request = do |
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
| (ns foo.core | |
| (:require [clojure.java.io :as io]) | |
| (:import [java.net URL] | |
| [java.io FileInputStream] | |
| (javax.xml.bind DatatypeConverter))) | |
| (defn- open-input-stream [^URL url] | |
| (if-let [user-info (.getUserInfo url)] | |
| (let [uc (.openConnection url) |
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
| (json-gen/add-encoder org.joda.time.DateTime | |
| (fn [c jsonGenerator] | |
| (.writeString jsonGenerator (str c)))) | |
| (defn str->date-time [_ value] | |
| (try | |
| (DateTime. value) | |
| (catch Exception e | |
| ::spec/invalid))) |
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
| (ns csv-parser.core | |
| (:require [clojure.string :as str] | |
| [clojure.data.csv :as csv] | |
| [cheshire.core :as json])) | |
| (->> "./foo.csv" | |
| slurp | |
| csv/read-csv | |
| rest | |
| (map #(zipmap [:id :first-name :given-name :yob] %)) |
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
| #!/usr/bin/env planck | |
| (ns colorblock.core | |
| (:require [planck.core :refer [*command-line-args* slurp]] | |
| [planck.shell :refer [sh]] | |
| [clojure.string :as s])) | |
| (def usage-str "USAGE:\ncolorblock example.clj SomeTagName\ncolorblock example.clj SomeTagName [OUTPUT FORMAT]\n") | |
| (def pygmentize-opts "style=friendly,fontface=Inconsolata,fontsize=62") |