Skip to content

Instantly share code, notes, and snippets.

View pydis-paste
#!/usr/bin/env zsh
emulate zsh
setopt err_exit pipe_fail warn_create_global warn_nested_var no_unset
if (( ${#@} == 0 )); then
data="$(cat)"
elif (( ${#@} == 1)); then
case $1 in
-) data="$(cat)" ;;
@gwerbin
gwerbin / multiprocessing_logging.py
Created Aug 4, 2021
Demo of logging in a multi-processing context.
View multiprocessing_logging.py
"""Demo of logging in a multi-processing context.
Based on the Python "Logging Cookbook":
https://docs.python.org/3/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes
Note on `QueueListener`:
The main difference between the Cookbook example and this demo is that I use
the `QueueListener` convenience class, whereas they write a bespoke
`listener_process` function which does more or less the same thing as
@gwerbin
gwerbin / TaxExample.idr
Last active Jul 6, 2021
Example of dependent types and "proof-carrying code" in a simple, practical programming task.
View TaxExample.idr
module TaxExample
import Data.So
-- Can't use `total` as a variable name! Boo :(
%default total
-- NOTE: Weird things happen when you use the same name in both a record
-- parameter and a record field name. Don't do it.
@gwerbin
gwerbin / column_align.py
Last active Jun 16, 2021
Sketch of a solution for aligning matrix columns, intended for aligning columns emitted from Scikit-learn classifiers. See https://github.com/scikit-learn/scikit-learn/issues/12845
View column_align.py
import numpy as np
import pandas as pd
def fill_array(fillvalue, shape):
"""Create an array filled with a specific value."""
if fillvalue == 0:
if isinstance(fillvalue, int):
array = np.zeros(shape, dtype='int')
else:
@gwerbin
gwerbin / pipx-metadata_v0.2.0_draft00.json
Last active May 16, 2021
JSON Schema for Pipx Metadata v0.2.0, draft 00; see https://github.com/pipxproject/pipx/pull/660. The regex for package version is [not trivial](https://regex101.com/r/BbPqar/1), and is copied verbatim from [Pep 440](https://www.python.org/dev/peps/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions).
View pipx-metadata_v0.2.0_draft00.json
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://pipxproject.github.io/pipx/schema/pipx-metadata_v0.2.0_draft00.json",
"$defs": {
"package_name": {
"type": "string",
"pattern": "^[A-Za-z][0-9A-Za-z_-]*$"
},
"python_version": {
"type": "string",
@gwerbin
gwerbin / Dockerfile
Last active May 12, 2021
Attempt at setting up Debugpy
View Dockerfile
FROM $REDACTED
# Install basics
RUN /opt/venv/bin/python -m pip install -U pip
RUN /opt/venv/bin/pip install -U setuptools wheel
# Install runtime deps
COPY requirements.txt /app/requirements.txt
RUN /opt/venv/bin/pip install -r /app/requirements.txt
@gwerbin
gwerbin / Matrix.idr
Last active May 4, 2021
Sketch of a matrix data type in Idris
View Matrix.idr
module Matrix
import Data.Vect
%default total
---- Interface ----
AbstractMatrix : Type
@gwerbin
gwerbin / conda_env_export.py
Last active Jul 15, 2021
Export a Conda environment with --from-history, but also append Pip-installed dependencies
View conda_env_export.py
"""
Export a Conda environment with --from-history, but also append
Pip-installed dependencies
Exports only manually-installed dependencies, excluding build versions, but
including Pip-installed dependencies.
Lots of issues requesting this functionality in the Conda issue tracker, no
sign of progress (as of March 2020).
View gitpath.zsh
# TODO: should this have a --flag for dispatch to system/global/local? Currently only supports local.
function gitpath() {
local git_dir output_path
if [[ -z "$GIT_DIR" ]]; then
read -r -d '' git_dir < <(git rev-parse --show-toplevel)
git_dir="${git_dir}/.git"
else
git_dir="$GIT_DIR"
@gwerbin
gwerbin / NHST.md
Created Aug 27, 2020
NHST draft writeup
View NHST.md

Null Hypothesis Significance Testing (NHST) is a procedure in which we try to learn something about the data by forming an hypothesis and then ruling out (or "rejecting) that hypothesis. Conceptually, NHST is similar to "deductive reasoning" in philosophy, or "differential diagnosis" in medicine: we can arrive on a single unambiguous conclusion only by ruling out all other possibilities. Therefore we can "prove" that the alternative hypothesis is true by ruling out the only other possibility, the null hypothesis.

In order to perform NHST, have to specify a null hypothesis, typically denoted H0, and an alternative hypothesis, typically denoted HA. H0 and HA must be mutually exclusive for NHST to make sense: if H0 is true then HA must be false, and if HA is true then H0 must be false.

NHST has two possible outcomes: we reject the null hypothesis in favor of the alternative hypothesis, or we fail to reject the null hypothesis. Failing to reject the null hypothesis does not mean that we reject