View lcm.py
from math import gcd
from functools import reduce
def lcm(numbers):
return reduce(lambda x, y: int((x * y) / gcd(x, y)), numbers, 1)
print(lcm([3,4,2,5,5])
View cnn_resize.py
import math
import skimage.transform
import numpy as np
# you use this just before passing any image to a CNN
# which usually expects square images
# however your input images can be of variable size
# you don't want to just squash the images to a square
# because you will lose valuable aspect ratio information
# you want to resize while preserving the aspect ratio
View socat_unix_pipes_tcp.md

Using socat to convert unix pipes to TCP connections

Imagine you have:

program-a | program-b

But now program-a and program-b are on different computers.

View inverter_array_index.py
# this is cool trick to invert array indices
# basically the first becomes the last
# and the last becomes the first
arr = [1,2,3,4]
arr_is = list(range(0, len(arr)))
# iterate forwards
for i in arr_is:
print(arr[i])
View cli_merge.md

CLI Merging of Text Files

The opposite of diff turns out to be sdiff which is distributed in the same package.

Use it like this:

sdiff --output=./merged file1 file2
View coroutines.js
// sometimes you need cooperative multitasking
// you don't want to rely on the JS event loop mechanism
// because either you're not doing any IO
// or you want to more tightly control the exact allocation
// of task computation time
// below we show 2 ways of achieving cooperative multitasking
// the first just uses normal function closures
// each time a coroutine step is done
// we return the result plus a closure that can take the next number
View safe_max_safe_min.py
# sometimes you're streaming through values in a for loop
# and you need to maintain a running max or min
# it's not elegant to get the head separately from the loop
# to solve this, we need a sentinel value to fold the max/min
# operation over the stream
# also known as the "identity element" of the max/min monoid
# in real world use cases, this could be a CSV stream
stream = (i for i in [1, 2, 3])
View condensed_distance_matrix_and_pairwise_index.py
# sometimes you want to get the distance matrix
# and once you have that distance matrix
# you want to be able to know what pairs contributed to that distance
# instead of converting it to the squareform
# which has redundant data
# we can do a little calculation
# note that there's a parallel version of pdist https://stackoverflow.com/a/29639465/582917
# however it doesn't return the condensed matrix
View memmap_numpy.py
import tempfile
import numpy as np
# the backing type is important
# numpy arrays must have a fixed size element
# so if you want to do out-of-core analytics, you need to know your element size
# for example here, we bytelength of 10
# the 'S' here means ASCII bytes, thus you can put bytestrings into it
# you can also use `('U', 10)` for utf-8 strings, this would mean 10 unicode codepoints
backing_type = np.dtype(('S', 10))
View transferring_ledger_nano_s_to_electrum.md

Transferring Ledger Nano S to Electrum

Electrum supports importing of the BIP39 24 word seed.

I recommend trying this to make sure you have written your seed down correctly.

You just need to start a new wallet, select a standard wallet and state that you already have a seed.

In the seed entry, select options and enable BIP 39.