Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Ogaday / hash_paths.py
Last active August 11, 2023 09:43
Hash paths
#!/usr/bin/env python3
"""Utility to produce the hash of a collection of file and directory paths.
Usage::
./hash_paths.py --help
"""
import argparse
import hashlib
import io
@Ogaday
Ogaday / azure_token.py
Created February 24, 2023 09:40
Azure credential helper
"""
"""
from argparse import ArgumentParser
from artifacts_keyring import CredentialProvider # type: ignore
def get_artifact_token(organization: str, feed: str) -> str:
"""Get credentials for an azure artifacts feed."""
provider = CredentialProvider()
@Ogaday
Ogaday / weighted_mean.py
Created February 10, 2023 17:37
Weighted mean for Pandas dataframes
"""
Utilities for weighted means on DataFrames.
"""
from functools import partial
from typing import Callable
import pandas as pd
def weighted_mean(frame: pd.DataFrame, value_col: str, weight_col: str) -> float:
@Ogaday
Ogaday / reflection.py
Created February 9, 2023 08:52
Example of reflection in SQLAlchemy
"""An example of table reflection with SQLAlchemy.
Test with Python 3.10 & SQLAlchemy 2.0.
See: https://stackoverflow.com/a/75389730/4244912
"""
from sqlalchemy import Table, create_engine, text
from sqlalchemy.orm import DeclarativeBase, Session
# Create a SQLAlchemy engine connected to an in-memory SQLite3 DB:

Upgrading Into the Breach (GOG - for Linux)

I bought Into the Breach on Galaxy of Gaming for linux on release. In July 2022, Subset games released Into the Breach Advanced Edition, [(1)][1] a free expansion of the original. This article details how I upgraded and moved my save game files across to the latest version of the game.

Game save data is stored in files with the names in the foramt: profile_{Name}. [(2)][2]

The first version I installed was GOG v1.0.10 (2-28-2018). This version was run via wine [(3)][3], and installed to ~/.wine/dosdevices/c:/GOG Games/Into the Breach/. The save game files (eg. profile_Alpha) were saved in the top level of this directory.

I installed the latest version of Into the Breach from GOG as of Feb 2023: v. 1.2.86 (10-10-2022). The installer prompted for an install location, with a default of ~/GOG Games/Into the Breach. I chose the default location and let the intaller create a desktop file etc. On install, it was clearly quite different to the old version

@Ogaday
Ogaday / REGISTER.rst
Last active December 6, 2022 14:49
Function registry

Function Register

A Lightweigt function registry implementation.

Eg:

register = Register()

@register("hello")
@Ogaday
Ogaday / COMPOSE.rst
Last active December 6, 2022 15:24
Implemtation of function composition

Function Composition

A minimal compose implementation.

Given a list of functions, apply them squentially to an argument. This is equivalent to:

funcs = [h, ..., g]
compose(x, funcs) == g(...(h(x)))
@Ogaday
Ogaday / argmax.py
Last active December 1, 2022 19:20
Native Argmax
"""
A native implementation of argmax.
https://towardsdatascience.com/there-is-no-argmax-function-for-python-list-cd0659b05e49
Tests::
pytest --doctest-modules -vvv argmax.py
Linting::
@Ogaday
Ogaday / AOC.md
Last active December 6, 2022 15:25
Advent of Code - Getting Started

Advent of Code - Getting Started

Some pointers for getting started with the Advent of Code.

You can run the notebook interactively here:

Binder

@Ogaday
Ogaday / README.md
Last active January 13, 2022 12:59
Mocking HTTP requests in Click

Mocking HTTP Requests in Click

Simple MVP to test mocking of HTTP requests made in Click commands using the responses library.

In simple_post.py we have a Click command that makes a request to https://httpbin.org, a useful API for testing requests.

In test_simple_post.py we have a test suite which can be run by PyTest. In the first