Skip to content

Instantly share code, notes, and snippets.

View zimolzak's full-sized avatar

Andy Zimolzak zimolzak

View GitHub Profile
@zimolzak
zimolzak / links.html
Created April 1, 2022 11:19
How many training examples do you need?
@zimolzak
zimolzak / inverse_survival_function.py
Created March 15, 2022 15:41
Inverse survival function of standard normal: pretty-print the polynomial approximation
print("""What is the "inverse survival function" of the standard normal?
The cdf is based on erf(x), the survival function is based on erfc(x),
and the inverse survival is based on 1/erfc(x). The error function
erf(x) is not an elementary function, but it can be approximated as
1 - 1 / (p(x))^4 , where p(x) is a 4th degree polynomial in x, with
coefficients a = 0.278393, b = 0.230389, c = 0.000972, d = 0.078108.
[https://en.wikipedia.org/wiki/Error_function] This means that
1/erfc(x) can be approximated as (p(x))^4 .
@zimolzak
zimolzak / dots.py
Created August 11, 2020 12:26
Make string with specified number of dots, in rows of 10. Useful to show a toddler which is the bigger number.
def arrange_dots(number):
"""Make string with specified number of dots, in rows of 10.
Useful to show a toddler which is the bigger number.
"""
tens = number // 10
ones = number % 10
row_of_ten = '.' * 10 + '\n'
rectangle = '\n' + row_of_ten * tens
return(rectangle + '.' * ones)
@zimolzak
zimolzak / dist.py
Created February 20, 2018 20:15
How often a random real matrix has complex eigenvalues
from random import uniform
def myvariate():
return uniform(-2,2)
for i in range(1000000):
a = myvariate()
b = myvariate()
c = myvariate()
d = myvariate()
\documentclass{article}
\title{This Mug Exaggerates My Grandfathering Skills To An Embarrassing Degree}
\author{Herman Fraser}
\date{1/31/01 3:00pm}
\begin{document}
\maketitle
COMMENTARY
My word. I still can't believe I was even nominated.
@zimolzak
zimolzak / rand_fake_btc_addr.py
Last active November 8, 2017 14:52
Random valid-hash Bitcoin address, highly UNlikely to be spendable (have valid keys, or private key known by someone)
#!/usr/bin/env python3
import random
from hashlib import sha256
digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
# No big I, big O, digit 0, or little l. 26 * 2 + 10 - 4 = 58.
base_count = len(digits58)
def encode_base58(bitcoin_bytes):
num = int.from_bytes(bitcoin_bytes, 'big')
library(ggplot2)
X = data.frame(d=c(0,1,2,3,4,5,6,7,8,9), segments=c(6,2,5,5,4,5,6,3,7,6), bits=c(0,1,1,2,1,2,2,3,1,2))
ggplot(X, aes(bits, segments, label=d)) + geom_path(position = position_jitter(width=0.1, height=0.1)) + geom_label(position = position_jitter(width=0.3, height=0.3))
@zimolzak
zimolzak / curses_brightness.py
Last active February 22, 2017 22:26
Control Linux screen brightness using keys in a Curses terminal
#!/usr/bin/env python3
import curses
max_b = int(open('/sys/class/backlight/radeon_bl0/max_brightness', 'r').read())
min_b = 40
columns = 70
def main(stdscr):
stdscr.clear()
k = 'x'
stdscr.addstr(1, 0, 'q to quit')
@zimolzak
zimolzak / cardware.py
Created February 14, 2017 18:38
Construct deck of only broadway cards. Draw 3 without replacement. 6840 seqs, 12.7 bits entropy.
from random import sample
from itertools import product
 
p = product(['A', 'K', 'Q', 'J', 'T'],
['s', 'h', 'd', 'c'])
 
deck = [''.join(e) for e in p]
 
print(sample(deck, 3))
@zimolzak
zimolzak / dedup.py
Created January 2, 2017 23:09
Deduplicate MP3s and AACs
from subprocess import getoutput
import os
command_b = "find /Users/ajz/Music/iTunes/iTunes\ Media/Music"
#command_b = "find /Users/ajz/Music/iTunes/iTunes\ Media/Music/Weezer"
command_a = "find /Users/ajz/powerbook/Users/ajz/Music/iTunes/iTunes\ Music"
debug = False
########