Skip to content

Instantly share code, notes, and snippets.

View ornithos's full-sized avatar

Alex Bird ornithos

View GitHub Profile
@ornithos
ornithos / tail_pod_logs.sh
Created July 20, 2023 16:17
Tail the pods of a Replicaset via kubectl
#!/bin/bash
# With some help from ChatGPT, although it was only somewhat correct/helpful
rs_name="..." # name of replicaset
namespace="..." # namespace to find pod/rs within
# Function to tail logs for each pod
tail_logs() {
local pod="$1"
echo "Tailing logs for pod: $pod"
@ornithos
ornithos / sklearn_serializer.py
Created June 30, 2023 09:31
Serialization / Saving sklearn object to disk without using pickle (using numpy)
class SklearnSerializer:
"""
Sklearn recommends we use joblib's dump/load commands, but this uses pickle and pickle
is a PITA. Numpy's serialization is compact and reliable and performs well across
different platforms and versions of Python and joblib. This serializer extracts all
the components of each sklearn object that are fitted (assuming sklearn's convention
of fitted attributes ending in underscore), and saves them in a numpy .npz file.
"""
def __init__(self):
pass
@ornithos
ornithos / SE_chunk_xml_into_json.py
Last active June 16, 2022 13:14
Parsing / chunking a large XML file from StackExchange into multiple JSON files
"""
Chunk a large XML file consisting of M elements of tag `row` into N JSON blobs
which can be read directly into memory
"""
import math
import subprocess
from datetime import datetime
from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict
@ornithos
ornithos / variational_mtpd_rework.ipynb
Last active December 12, 2021 15:29
An implementation of the variational MTPD model.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ornithos
ornithos / covid_exposure_note.ipynb
Created July 7, 2020 15:07
How COPD affects the risk of covid
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ornithos
ornithos / xia_mocap_data_debug.ipynb
Last active May 4, 2019 12:32
Fewshot Mocap Data (Mason et al. 18) Representation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# call Chain(Dense(2, 400, NNlib.relu), Dense(400, 784, NNlib.σ))
# 100x with random input, where the matmul/add is called "preactiv"
# for layers 1 and 2, and the nonlinearities are timed separately.
# As always if using sigmoidal transformations, these account for
# much of the forward and backward time pass despite being element-
# wise operations.
#=
────────────────────────────────────────────────────────────────────
Time Allocations
@ornithos
ornithos / simplelr-flux.jl
Last active December 12, 2021 15:24
A (very) simple multivariate linear regression with Julia / Flux
using Statistics
using Formatting
using Flux.Tracker
using Flux.Tracker: update!
# Define simple linear model
W = param(rand(2, 5))
b = param(rand(2, 1))