Skip to content

Instantly share code, notes, and snippets.

"""
typed_mat_mixin.py provides a mixin `InitMixin` that tries
to generate a `.init` method to a typed Dataclass to automatically
deserialize .mat files exported from MATLAB to a Python Dataclass.
Supported types:
- strings
- int, float, np.uint8, and most np typedefs
- np.ndarray (1D and 2D tested)
- Type arrays as np.array[ndims, dtype]
@kwsp
kwsp / debug_gh_actions.md
Created July 11, 2024 08:12
Trick to debug VCPKG build errors in GitHub Actions
jobs:
  build:
    steps:
      - name: Export GitHub Actions cache environment variables
        uses: actions/github-script@v7
 with:
@kwsp
kwsp / setup_gpg_git.md
Created August 14, 2024 15:36
Setup GPG for git

Windows

I use git from scoop. Open git bash to access the gpg binary. If you install gpg from scoop it will not work as git doesn't know about it.

Import existing private key

gpg --import private.key
@kwsp
kwsp / bin_io.hpp
Last active September 9, 2024 17:05
#include <iostream>
#include <fstream>
#include <armadillo>
// T is the type of value stored in the binary file.
template <typename T>
auto load_bin(const fs::path &filename) -> arma::Mat<T> {
std::ifstream file(filename, std::ios::binary | std::ios::ate);
@kwsp
kwsp / CopyToTargetDir.cmake
Last active December 31, 2024 23:27
Copy resources from source dir to CMake multi-config build directory
function(copy_to_target_dir target resource)
add_custom_command(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_PROPERTY:${target},SOURCE_DIR>/${resource}"
"$<TARGET_FILE_DIR:${target}>/${resource}"
)
endfunction()
copy_to_target_dir(${EXE_NAME} shaders)
@kwsp
kwsp / to_nrrd.py
Created January 23, 2025 22:27
to_nrrd.py
"""
dependencies: numpy pillow pynrrd tqdm
"""
from PIL import Image
from pathlib import Path
from tqdm import tqdm
import nrrd
import numpy as np
@kwsp
kwsp / align_OCT.py
Last active February 19, 2025 22:33
"""
Convert exported, rect OCT images to aligned rect and radial, save as NRRD files.
1. Change the `input_folder` to point to the directory containing images.
2. Change the row range used for correlation by changing `rowStart` and `rowEnd` to make sure they only include the tubing and avoid any tissue in this window.
Install dependencies:
```
python3 -m pip install numpy matplotlib pillow pynrrd tqdm opencv-python
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from tqdm import tqdm
import cv2
import matplotlib.pyplot as plt
import numpy as np
def find_best_img_match(target_img: np.array, imgpaths: list[Path]):