This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import enum | |
from warnings import warn | |
from functools import wraps | |
class CodeIncompleteError(Exception): pass | |
class ImmatureWarning(UserWarning): pass | |
class ObsoleteWarning(UserWarning): pass | |
@enum.unique | |
class CodeStatus(enum.Enum): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import enum | |
class SmartEnum(enum.Enum): | |
""" | |
An enum with a classmethod `of` that parses a string of the member's name. | |
""" | |
@classmethod | |
def of(cls, v): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FancyCmaps: | |
""" | |
Useful colormaps for matplotlib. Most importantly: | |
- white_red | |
- white_blue | |
- blue_white | |
- white_black | |
The built-in matplotlib ones don't actually go between pure color values!! | |
For ex, 'Greys' doesn't go from pure white to pure black! | |
So colormaps to consider avoiding include Greys, Blues, Greens, (etc), bwr, and seismic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DevNull: | |
"""Pretends to write but doesn't.""" | |
def write(self, msg): | |
pass | |
def flush(self): | |
pass | |
def close(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib.axes import Axes | |
@classmethod | |
def despine(cls, ax: Axes) -> Axes: | |
""" | |
Removes all spines and ticks on an Axes. | |
""" | |
ax.set_yticks([]) | |
ax.set_yticks([]) | |
ax.set_xticklabels([]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Type | |
from functools import wraps | |
def copy_docstring(from_obj: Type): | |
""" | |
Decorator. | |
Copies the docstring from `from_obj` to this function or class. | |
""" | |
@wraps(copy_docstring) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import display, Markdown, HTML | |
display(HTML("<style>.container { width:100% !important; }</style>")) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
from pathlib import PurePath | |
def listen(path: Union[str, PurePath, bytes]): | |
""" | |
Returns an audio container that Jupyter notebook will display. | |
Must be run from a Jupyter notebook. | |
Will raise an ImportError if IPython cannot be imported. | |
:param path: The local path to the audio file | |
:return: A jupyter notebook ipd.Audio object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterator, Tuple, Dict, List | |
class MissingConfigEntry(Exception): pass | |
class TomlData: | |
"""A better TOML data structure than a plain dict. | |
Usage examples: | |
data = TomlData({'x': {'y': {'z': 155}}}) | |
print(data['x.y.z']) # prints 155 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apache License | |
Version 2.0, January 2004 | |
http://www.apache.org/licenses/ | |
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | |
1. Definitions. | |
"License" shall mean the terms and conditions for use, reproduction, | |
and distribution as defined by Sections 1 through 9 of this document. |