Skip to content

Instantly share code, notes, and snippets.

import numpy as np
np.set_printoptions(suppress=True)
stdevs = [i / 2 for i in range(1, 24 + 1)]
TRIALS = 1_000
WOMEN = 500_000
trial_results = {k: list() for k in stdevs}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
def analyze_data(df: pd.DataFrame):
"""This function lets the data speak for itself."""
print(df)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""Run this file like this:
>>> python jinja_cli.py path/to/my/file.txt --foo bar
and it will render the file as a Jinja template with foo="bar".
"""
import os
import click # pip install click
import jinja2 # pip install jinja2
@ryxcommar
ryxcommar / function_mixin.py
Last active August 22, 2020 20:34
Make classes look a little bit more like the functions they're wrapping.
"""This module makes a class look like a function. The function is stored in
``self._func,`` and (most of) the function's properties are exposed in the
class's top-level. The biggest issue with the mixin is that ``__call__`` hides
the signature of the original function; I'm not sure how to address that.
"""
def _create_getter_and_setter(name: str):
def getter(self):
return getattr(self._func, name)
@ryxcommar
ryxcommar / mpl_in_flask.py
Last active August 15, 2020 21:00
How to render static Matplotlib in Flask
"""Static Matplotlib Figures in Flask - Tutorial
To run:
1. Copy this file.
2. Make sure the dependencies are installed (see after the docstring)
3. Run in the command line: >>> python mpl_in_flask.py
4. Fire up your browser and view the site (default: http://127.0.0.1:5000/)
If you want to implement this solution:
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import us # pip install us
# Data is available here: https://covidtracking.com/data/download
df = pd.read_csv(os.path.expanduser('~/Downloads/daily.csv'))
# Filter the data, rename stuff