Skip to content

Instantly share code, notes, and snippets.

@cwindolf
cwindolf / bwdrawer.py
Last active April 1, 2020 16:19
You just wanna draw a black and white image into an array real quick
import numpy as np
import matplotlib.pyplot as plt
class bwdrawer:
"""Draw one pixel at a time on a black and white canvas.
Usage (in a script or a repl):
```
drawer = bwdrawer(my_width, my_height)
@cwindolf
cwindolf / rdr.py
Last active March 29, 2020 17:50
Syntactic sugar for reductions in numpy
import numpy as np
class _redder:
"""Syntactic sugar for reductions in numpy.
Users interact with the global instance `rdr` defined below rather
than using this class itself.
Probably a dumb idea but whatever. Basically a sugar to batch out
@cwindolf
cwindolf / teqn
Last active May 22, 2024 21:44
teqn: Quickly typeset a single LaTeX expression to .png, .svg, .pdf
#!/usr/bin/env python3
r"""teqn
Quickly turn your math mode expression into cropped png, svg, or pdf.
Then you can drag and drop it into slack or illustrator or whatever.
This is basically just a wrapper around the standalone document class.
Pass your math expression (in quotes) on the command line. It will be
typeset in the align* environment by default, unless you pass --nomath,
in which case you can put the environment in the expression too.
@cwindolf
cwindolf / noint.py
Last active February 23, 2020 21:12 — forked from tcwalther/delayedinterrupt.py
Interrupt-atomic decorator / context manager
"""noint: Shield a code block or function from SIGINT.
Based on: http://stackoverflow.com/a/21919644/487556.
Useful for running training loops in Jupyter: if your learning
step is inside a `with noint:`, when you want to interrupt your
training routine, you can do that without getting halfway through
some set of operations and leaving the model state inconsistent,
which would make it impossible to rerun the cell without
restarting the whole training loop.
@cwindolf
cwindolf / whiten.py
Last active July 13, 2021 15:30 — forked from joelouismarino/whiten.py
Python library for whitening and coloring data
'''Python library for decorrelating and correlating data
Forked from joelouismarino/whiten.py.
Also based on R's rdrr.io/cran/whitening/src/R/whiteningMatrix.R,
and an SAS blog post:
blogs.sas.com/content/iml/2012/02/08/use-the-cholesky-
transformation-to-correlate-and-uncorrelate-variables.html
'''
import numpy as np
import scipy.linalg as la