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 conways.core | |
(:gen-class)) | |
(def board [5 5]) | |
(def coords (for [x (range (first board)) y (range (second board))] [y x])) | |
(def neighbour-coords [[-1 -1] [0 -1] [1 -1] | |
[-1 0] [1 0] | |
[-1 1] [0 1] [1 1]]) |
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 zip-fail.core | |
(:require | |
[clojure.xml :as c-xml] | |
[clojure.data.xml :refer [parse parse-str]] | |
[clojure.zip :refer [xml-zip]] | |
[clojure.data.zip.xml | |
:refer [xml-> xml1-> attr text= attr= text]])) | |
(def xml "<foo id = \"qix\">bar</foo>") |
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
;; | |
;; When refactoring this kind of stuff, I tend to create functions to transform one of the items | |
;; This way, the threading stuff doesn't get to complicated. | |
;; | |
(defn ->sku-name-type [product] | |
(let [type (:type product)] | |
(->> product | |
:variations | |
(map val) |
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 recipe [{:action :grab | |
:item :sugar} | |
{:action :add-to-bowl} | |
{:action :grab | |
:item :flour} | |
{:action :add-to-bowl} | |
{:action :grab | |
:item :milk} | |
{:action :add-to-bowl} | |
{:action :mix} |
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 barbershop.core | |
(:require [clojure.core.async :refer | |
[dropping-buffer timeout chan go-loop <! chan ]])) | |
(def shop (chan (dropping-buffer 3))) | |
(defn customer [i shop] | |
(put! shop i (fn [v] (println "customer" i "going to the barber")))) | |
(defn barber [shop] |
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 my-ns.core | |
(:require [clojure.core.async :refer | |
[timeout thread alt! alts! chan go-loop <! >! put! chan close!]])) | |
(defn takes-a-while [chan x] | |
(println "starting long running query") | |
(thread (Thread/sleep 5000) | |
(put! chan x))) | |
(defn run-it [] |
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 cljs.core-test-generative | |
(:require [clojure.test.check :as tc] | |
[clojure.test.check.generators :as gen] | |
[clojure.test.check.properties :as prop])) | |
(def samples 100) | |
(def shuffle-prop | |
(prop/for-all [v (gen/such-that not-empty (gen/vector gen/any))] | |
(seq (shuffle 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
(defn percentile [xs n] | |
(let [idx (Math/floor (* (count xs) (/ n 100)))] | |
(nth (sort xs) idx))) | |
(defn percentiles [xs] | |
(let [p (partial percentile xs)] | |
(into {} (map (juxt (comp keyword str) p) [50 90 95 99])))) |
NewerOlder