Source code you can find on my gist: https://gist.github.com/lkurzyniec/da61b9b5cec71730c3b89cdfe31f37ff