Skip to content

Instantly share code, notes, and snippets.

@pmbauer
pmbauer / async_thread_ring.clj
Last active December 19, 2015 21:59
thread ring, clojure core.async style
(require '[clojure.core.async :refer [chan go <! <!! >! >!!]])
(defn thread-ring [size n]
{:pre [(> size 1)]}
(let [result (chan 1)
[head :as ring] (vec (repeatedly size #(chan 1)))]
(dotimes [i size]
(let [id (inc i)
in (ring i)
out (ring (mod id size))]
@pmbauer
pmbauer / metrics
Created September 3, 2013 10:49
criterium report for psplit
amd64 Linux 3.2.0-52-generic, 6 cores
Java HotSpot(TM) 64-Bit Server VM 23.21-b01
*** Single UseConcMarkSweepGC ***
Runtime arguments: -XX:-UseConcMarkSweepGC
Evaluation count : 300 in 60 samples of 5 calls.
Execution time sample mean : 207.175228 ms
Execution time mean : 207.185921 ms
Execution time sample std-deviation : 1.012513 ms
Execution time std-deviation : 1.022277 ms
<link rel="import" href="../code-mirror/code-mirror.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
I1212 22:03:27.103919 4515 fetcher.cpp:76] Fetching URI 'http://10.88.236.8:9000/proxy'
I1212 22:03:27.104070 4515 fetcher.cpp:126] Downloading 'http://10.88.236.8:9000/proxy' to '/tmp/mesos/slaves/20141212-210553-149706762-5050-2275-S5/frameworks/20141212-210553-149706762-5050-2275-0002/executors/KubeleteExecutorID/runs/f300609d-cb59-4851-a22f-7e57c183590f/proxy'
I1212 22:03:27.389055 4515 fetcher.cpp:76] Fetching URI 'http://10.88.236.8:9000/kubernetes-executor'
I1212 22:03:27.389119 4515 fetcher.cpp:126] Downloading 'http://10.88.236.8:9000/kubernetes-executor' to '/tmp/mesos/slaves/20141212-210553-149706762-5050-2275-S5/frameworks/20141212-210553-149706762-5050-2275-0002/executors/KubeleteExecutorID/runs/f300609d-cb59-4851-a22f-7e57c183590f/kubernetes-executor'
sh: 1: ./kubernetes-executor: Permission denied
@pmbauer
pmbauer / build.boot
Created December 17, 2014 19:44
there's a snake in my boot
(deftask snake []
(letfn [(copy-uri-to-file [uri file]
(with-open [in (clojure.java.io/input-stream uri)
out (clojure.java.io/output-stream file)]
(clojure.java.io/copy in out)))]
(let [snake-mp3 (java.io.File/createTempFile "snake" ".mp3")]
(copy-uri-to-file "http://movie-sounds.org/quotes/toys2/VOlCE-BOX-Theres-a-snake-in-my-boot.mp3" snake-mp3)
(speak :success (.getPath snake-mp3)))))
;; One example of why one might want to generate platform specific feature macros
;; I'm not saying this is a good DSL, just possible with https://github.com/feature-macros/clojurescript/tree/feature-macros/feature-macros-demo
(deftype-unified Foo [bar]
unified/Counted [(count [_] {:cljs (-count bar)
:clj (.count bar)})]
BazProtocol
(fizz [_] :buzz))
;; where unified/Counted [...] expands to clojure.lang.Counted/count on :clj and ICounted/-count on :cljs
(defn define-node-repl-launcher []
(fn [handler]
(fn [fileset]
(defn node-repl []
(require 'cemerick.piggieback 'cljs.repl.node)
((resolve 'cemerick.piggieback/cljs-repl)
:repl-env ((resolve 'cljs.repl.node/repl-env))
:output-dir ".noderepl"
:optimizations :none
:cache-analysis true

Keybase proof

I hereby claim:

  • I am pmbauer on github.
  • I am pmbauer (https://keybase.io/pmbauer) on keybase.
  • I have a public key ASDmZjgJDzG5JMMYT1S8p0m62lTcUo1PZ0oCbj81ebGzjAo

To claim this, I am signing this object:

@pmbauer
pmbauer / udacious_operator.md
Last active November 30, 2016 16:31
Udacious Operator, open rec

Come democratize education with Udacity, change lives.

You might be a Udacious Operator if ...

If typing the same thing twice makes you break out in hives ...
If automating manual operations cures those hives ...
If action without measuring nauseates you ...
If monitoring is your Meclozine ...
If you take extreme pride in your work ...
If you feel deeply responsible for your work ...

@pmbauer
pmbauer / seven.clj
Last active December 21, 2015 01:25
advent of code 2015: day seven
(require '[instaparse.core :as insta])
(require '[clojure.core.match :refer [match]])
(def circuit-parser
(insta/parser
"<S> := (INSTRUCTION <'\n'*>)*
INSTRUCTION := EXP <#'\\s*->\\s*'> WIRE
<EXP> := ATOM | UNARY_EXP | BINARY_EXP
ATOM := LITERAL | WIRE
UNARY_EXP := OP <WHITESPACE> ATOM