I hereby claim:
- I am matthewdowney on github.
- I am matthewdowney (https://keybase.io/matthewdowney) on keybase.
- I have a public key ASA5-6Rf3lYjOJowTXj54xl2nhKdjc1jvET1YsVd4Q0YcQo
To claim this, I am signing this object:
(import java.util.concurrent.CountDownLatch) | |
(defmacro dothreads | |
"Like (dotimes [i n] ...) except the body is executed concurrently, and the result is | |
a map from `i` to the result (or an exception if one is thrown). | |
Spins up `n-threads` threads and execute `body` in each with the thread number bound to | |
the given `tid-binding`, but use a CountDownLatch to make sure they all start at as close | |
to the same exact time as possible." | |
[[tid-binding n-threads] & body] |
(ns blessed-cljs.core | |
"Compiles for :node-js. Attempts to connect to a TCP socket at the port | |
given as a command line argument, and receives pure data specifications | |
for a blessed-contrib dashboard which it updates in real time. | |
Expects JSON data following the format: | |
{:type (a string in gauge, table, sparkline, bar, donut, gauge, lcd, log, markdown, map) | |
:meta (a map to pass to grid.set along the the contrib.object) | |
:data (data to display)} |
(defn parsed-file-delay | |
"A delay that returns `(parse-fn (slurp file-path))` on each dereference, | |
recalculating the return value only when `(.lastModified (io/file file-path))` | |
changes. | |
Useful if you don't need any sort of push notification when the file changes." | |
[file-path parse-fn] | |
(let [last-contents (atom {:modified -1 :contents nil}) | |
^File f (io/file file-path)] | |
(reify IDeref |
I hereby claim:
To claim this, I am signing this object:
(defn stats | |
"Calculate :mean :min :max :stdev and :n given a data point, and possibly a prior `stats` result. | |
I.e. to calculate statistics from scratch: | |
``` | |
(def statistics (reduce stats nil data-set)) | |
``` | |
Or to maintain statistics for a constantly updating data series that you don't want to keep in memory: | |
``` | |
(def statistics (atom (stats 0)) | |
(defn add-data-point! [dp] |
(defn xf-sort | |
"A sorting transducer. Mostly a syntactic improvement to allow composition of | |
sorting with the standard transducers, but also provides a slight performance | |
increase over transducing, sorting, and then continuing to transduce." | |
([] | |
(xf-sort compare)) | |
([cmp] | |
(fn [rf] | |
(let [temp-list (java.util.ArrayList.)] | |
(fn |
The blockchain.info API for XPUBs only works with Legacy Bitcoin XPUBs, whereas their web interface confusingly works with Segwit as well.
I provide a couple solutions at the end, and we end up with three useful functions:
legacy_wallet_balance
segwit_wallet_balance
segwit_wallet_balance_hack
# Pipe some data to stdin. Each line should contain a number. | |
import csv | |
from collections import defaultdict | |
from math import log10 | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import functools | |
import fileinput |
import hmac | |
from functools import wraps | |
def safe_equal(a, b): | |
""" | |
Perform an equality check between strings that guards against a timing attack by checking every index in the each | |
string. Note that length is compared first, so the length may be leaked through a timing attack, which does not | |
compromise the security of an HMAC. |
""" | |
Implementation of "Pay to Witness Public Key Hash nested in BIP16 Pay to Script Hash" (P2WPKH-P2SH) address generation. | |
Described in BIP 141 (SegWit) https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH | |
I.e.: Public key -> SegWit address | |
""" | |
import hashlib | |
from hashlib import sha256 |