Skip to content

Instantly share code, notes, and snippets.

View slipset's full-sized avatar
🙃

Erik Assum slipset

🙃
View GitHub Profile
;;
;; 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)
(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}
@slipset
slipset / barbershop
Created December 29, 2014 08:55
Implementation of the barbershop problem with core.async
(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]
(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 []
(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))))
(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]))))