Skip to content

Instantly share code, notes, and snippets.

@pmbauer
pmbauer / recommended_channel_remover.js
Created October 31, 2012 03:39
youtube recommended channel remover
(get-in {:k :v} [:k]) ;; => :v
(update-in {:k :v} [:k] (constantly :x)) ;; => {:k :x}
(get-in {:k :v} []) ;; => {:k :v}
(update-in {:k :v} [] (constantly {:k :x})) ;; => {nil {:k :x}, :k :v}
# wget -O https://gist.github.com/pmbauer/5166100/raw/c72b880ba82dfd598c3cf27a3045833cadec32e2/install_python.sh
# chmod +x install_python.sh
# ./install_python.sh
#!/bin/sh
pushd /usr/local/src
echo " - Install compilers"
yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
;; based on my code from test.benchmark
(ns raw-threadring
(:import [java.util.concurrent Exchanger]))
(def ^Exchanger output-pipe (Exchanger.))
(defn relay [state msg]
(if (> msg 0)
(send (:next state) relay (dec msg))
@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 / 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
@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
@pmbauer
pmbauer / extra_layers.dockerfile
Created April 20, 2016 15:23
build containers post
FROM alpine:3.3
RUN apk add --update curl drill
# cleanup index package cache since this is dead weight
# that should not be deployed
RUN rm -rf /var/cache/apk/*
@pmbauer
pmbauer / docker_history.shell
Last active April 20, 2016 15:29
build containers post
$ docker build -t extra_layers -f extra_layers.dockerfile .
[...]
$ docker history extra_layers
IMAGE CREATED CREATED BY SIZE COMMENT
6c6fffb28c43 3 weeks ago /bin/sh -c rm -rf /var/cache/apk/* 0 B
636b0662bc76 3 weeks ago /bin/sh -c apk add --update curl drill 3.009 MB
70c557e50ed6 6 weeks ago /bin/sh -c #(nop) ADD file:81ba6f20bdb99e6c13 4.794 MB
$ docker build -t without_cached -f without_cached.dockerfile .
[...]
$ docker history without_cached
IMAGE CREATED CREATED BY SIZE COMMENT
19b3d76d50f5 3 weeks ago /bin/sh -c apk add --update curl drill && rm 2.26 MB
70c557e50ed6 6 weeks ago /bin/sh -c #(nop) ADD file:81ba6f20bdb99e6c13 4.794 MB