Skip to content

Instantly share code, notes, and snippets.

View maciejzj's full-sized avatar
🙃

Maciej Ziaja maciejzj

🙃
View GitHub Profile
@maciejzj
maciejzj / fabrik_robot.py
Created November 27, 2024 09:28
FARBIK algorithm-based reverse kinematics 2D implementation in pure Python with PyGame display
#!/usr/bin/env python3
# FARBIK algorithm-based reverse kinematics 2D implementation in pure Python with PyGame display
# Setup:
# pip install pygame
# Usage:
# python -m fabrik_robot.py
import math
import sys
@maciejzj
maciejzj / change_commit_author.sh
Last active November 27, 2024 09:30
Change git commit author's name and email
git filter-branch --env-filter '
WRONG_EMAIL="<WRONG_EMAIL>"
NEW_NAME="<NEW_NAME>"
NEW_EMAIL="<NEW_EMAIL>"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
@maciejzj
maciejzj / split_to_patches.py
Last active November 27, 2024 09:29
Split image into patches with scikit-image (Applicable to C, H, W images as-is. Can be modified to wokrk with H, W, C ones)
from skimage.util import view_as_blocks
def split_to_patches(
img: np.ndarray, patch_size: int, ch_axis: int | None = None
) -> np.ndarray:
"""Split image into rectangular patches.
:param img: Array image 2D grayscale of 3D color
:param patch_size: Size of a rectangular patch.
:param ch_axis: Index of channel axis of the image, if None will treat image as 2D grayscale.
@maciejzj
maciejzj / register_img.py
Last active November 27, 2024 09:31
Register images using phase cross correlation
from scipy import ndimage
from skimage import registration
def register(reference_img: np.ndarray, moving_img: np.ndarray, scale: int = 100) -> np.ndarray:
shift, error, phasediff = registration.phase_cross_correlation(reference_img, moving_img, upsample_factor=scale)
shifted = ndimage.shift(moving_img, shift)
return shifted
@maciejzj
maciejzj / compiler.python.vim
Created March 28, 2023 08:50 — forked from SuryaThiru/compiler.python.vim
Simple compiler for vim to fill python traceback in the quickfix window. Copy the file to `.vim/compiler/python.vim`.
" https://vi.stackexchange.com/questions/5110/quickfix-support-for-python-tracebacks
if exists("current_compiler")
finish
endif
let current_compiler = "python"
let s:cpo_save = &cpo
set cpo&vim
@maciejzj
maciejzj / required_packages.tex
Last active November 27, 2024 09:32
LaTex subfigures
\usepackage{caption}
\usepackage{subcaption}
@maciejzj
maciejzj / downsample.py
Last active November 27, 2024 09:32
Downsample image with arbitrary channel dimension
def downsample(img: np.ndarray, ratio: int, ch_axis: int = 0, start_pos: int = 0) -> np.ndarray:
"""Downsample an image by taking every n-th pixel in spatial dimensions.
:param img: 2D (grayscale) or 3D (color) image.
:param ratio: Downsampling ratio; the output image will be ratio-times
smaller.
:param ch_axis: Channel axis of the image, if image is 2D grayscale this
paramter will be ignored.
:returns: Downsampled image.
"""
@maciejzj
maciejzj / pyproject.toml
Created March 24, 2023 11:02
My starter configuration for Python tooling
[tool.black]
line-length = 100
skip-string-normalization = true
[tool.isort]
profile = "black"
[[tool.mypy.overrides]]
module = [
"untyped_module"

Differential equations

Numerically

		% diffEq1 dy=y
y0=1;  	% start point
		% func in form of: dy/dt = f(x,y) 
		% then the range of solution
		% start point
		% extra options
solution=ode45(@diffEq1,[0 10],y0)
@maciejzj
maciejzj / fstab
Created December 1, 2020 18:59
Linux mdadm config
# /dev/md0
UUID=edb6179d-dccd-4975-a61f-06750a20dab1 /mnt/md0 ext4 defaults 0 0
# /dev/md1
UUID=3b396d88-ac44-4a91-9f7f-9ea9e0c5acfa /mnt/md1 ext4 defaults 0 0