Skip to content

Instantly share code, notes, and snippets.

@EpicWink
EpicWink / main.ts
Created October 11, 2023 06:18
Subclass field declaration
import { Expose, Type, plainToClass } from 'class-transformer';
import { Equals, IsString } from 'class-validator';
import 'reflect-metadata';
abstract class FooBar {
@IsString()
@Expose()
type: string;
}
@EpicWink
EpicWink / parse-suncorp-statement.py
Last active June 7, 2023 09:54
Parse Suncorp bank statement and output transactions as CSV
"""Parse Suncorp bank statement text and output transactions as CSV.
Download e-statements, copy transactions into text file, pass this
file as stdin, send stdout to new CSV file.
```shell
cat statement.txt | python parse-suncorp-statement.py > transactions.csv
```
Set `ADDITIONAL_IGNORED_LINES` to exceptional extra lines to be
@EpicWink
EpicWink / testq.py
Created March 28, 2023 08:35
Python queue shutdown test
"""Testing Python queue shutdown.
See https://github.com/python/cpython/issues/96471
"""
import time
import queue
import threading
import traceback
import asyncio.queues
@EpicWink
EpicWink / increment-example.py
Last active December 6, 2022 07:02
Python increment function
import ctypes
_bases = (ctypes.Structure,)
PyLongPointer = ctypes.POINTER(
type("PyLong", _bases, dict(_fields_=[
("ob_base", type("PyVarObject", _bases, dict(_fields_=[
("ob_base", type("PyObject", _bases, dict(_fields_=[
("ob_refcnt", ctypes.c_ssize_t),
("ob_type", ctypes.c_void_p),
]))),
@EpicWink
EpicWink / conf.py
Last active April 11, 2021 04:22
Fixes TypeError when using Sphinx 3.4 with autodocsumm (add to your conf.py)
import autodocsumm
def make_get_doc(original):
def get_doc(*args, **kwargs):
r = original(*args, **kwargs)
return r or []
return get_doc
@EpicWink
EpicWink / _dataclass_patch.py
Last active October 4, 2022 12:02
Support non-defaulted after defaulted fields in dataclasses
"""Patch ``dataclasses`` to support optional after required fields.
Fields used in ``__init__`` without defaults are currently not allowed
after fields with defaults, due to the specification in PEP 557. This
patch allows these fields, but makes them required keyword-only
parameters to ``__init__``.
To apply this patch, simply import this module before defining any
dataclasses.
"""
@EpicWink
EpicWink / mask-bounds-timing.py
Created June 11, 2020 02:41
Timing for different methods of getting bounding rectangle around mask
import time
import numpy as np
# Setup
mask = np.zeros((4000, 5000), dtype=np.bool8)
for j in range(-50, 50):
for k in range(-50, 50):
if np.sqrt(j**2 + k**2) < 50:
mask[1000 + j, 2000 + k] = True
image = np.random.randint(0, 256, (4000, 5000, 3), dtype=np.uint8)
@EpicWink
EpicWink / _docker_patch.py
Last active February 12, 2020 21:40
Patch Docker for Python with device-requests, from https://github.com/docker/docker-py/pull/2471
# Licensed under the Apache License, Version 2.0
# License included at https://github.com/docker/docker-py/blob/master/LICENSE
"""Patch Docker for Python with device-requests."""
from docker.types import base as docker_types_base
from docker.models import containers as docker_models_containers
from docker.types import containers as docker_types_containers
from docker.utils import utils as docker_utils