Skip to content

Instantly share code, notes, and snippets.

View slipset's full-sized avatar
🙃

Erik Assum slipset

🙃
View GitHub Profile
(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]))))
(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))))
(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 []
@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]
(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}
;;
;; 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)
@slipset
slipset / core.clj
Last active April 27, 2016 19:24
why is :foo not working
(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>")
(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]])

Keybase proof

I hereby claim:

  • I am slipset on github.
  • I am slipset (https://keybase.io/slipset) on keybase.
  • I have a public key whose fingerprint is EBFB 04B0 F2F4 C211 7168 5EDE 90A9 5705 B80F C796

To claim this, I am signing this object:

#!/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")