Skip to content

Instantly share code, notes, and snippets.

View compare_nii_images_using_checksum.py
import os
import glob
import hashlib
import argparse
def compute_checksum(file_path):
with open(file_path, 'rb') as f:
file_bytes = f.read()
return hashlib.md5(file_bytes).hexdigest()
@valosekj
valosekj / change_itk_direction.py
Last active February 25, 2023 20:32
Fix ITK direction for nnU-Net
View change_itk_direction.py
# Set ITK direction from image1 to image2
#
# Usage:
# python change_itk_orientation.py <image1> <image2>
# Example:
# python change_itk_orientation.py sub-001_T1w.nii.gz sub-001_T1w_seg.nii.gz
#
# Jan Valosek
#
@valosekj
valosekj / ssh_configuration.md
Last active September 27, 2022 06:45
Configuration of `ssh` connection #blog
View ssh_configuration.md

Configuration of ssh connection

Unix and MacOS

Let's say we want to configure an ssh connection between machine alpha and beta.

  1. Go to your home folder at machine alpha:
$ cd ~
@valosekj
valosekj / git_collaboration.md
Last active November 7, 2022 14:54
Simple workflow of collaboration in small team using git and GitHub
View git_collaboration.md

Simple workflow of collaboration in small team using git and GitHub

This gist describes example of simple workflow on repository whose changes are tracked by git and GitHub

1) Clone (download repository from GitHub to your computer)

# Go to directory where repository will be cloned (downloaded)
cd ~/Documents
# Clone repository from GitHub
@valosekj
valosekj / virtual_enviroments.md
Last active November 3, 2022 22:43
How to create and use virtual environments (venv and conda)
View virtual_enviroments.md

How to create and use virtual environments (venv and conda)

venv and conda are environment manager tools allowing to create virtual environments. Virtual environment separates the dependencies (Python packages) for different projects. This mean that each project can have its own dependencies. Usage of virtual environments allows you to avoid installing Python packages globally (to the system Python) which could break system tools or other projects.

venv environment

  1. Create venv

MacOS or Linux (without or with site-packages)

@valosekj
valosekj / run_python_from_shell.md
Last active November 28, 2021 15:52
Run python script from shell #blog
View run_python_from_shell.md

Run python script from shell (bash, zsh)

Sometimes, I need to call/run python script with arguments from shell. I use bash or zsh as my shell and following workaround works great for me.

Using shell wrapper

  1. Some example python script which I need to run from bash:

my_python_script.py:

@valosekj
valosekj / matplotlib_tips.md
Last active March 8, 2023 00:06
Tips and hacks for plotting in python
View matplotlib_tips.md

Tips and hacks for plotting in python

This gist containts several useful tips, tricks and hacks for plotting of figures, plots and charts using python (matplotlib and seaborn packages).

Fix warning about matplotlib backend in PyCharm

import matplotlib
matplotlib.use('TkAgg')
@valosekj
valosekj / basic_shell_commands.md
Last active February 16, 2023 13:06
Basic shell commands
View basic_shell_commands.md

Basic shell commands

A few basic shell (bash, zsh, ...) commands for UNIX (Linux, MacOS) CLI (command-line interface)

1. File and directory manipulation commands

cd - change directory:

# change directory to /home/username/Downloads:
@valosekj
valosekj / useful_shell_commands.md
Last active October 17, 2021 11:25
Useful shell commands #blog
View useful_shell_commands.md

Useful shell commands

This gist contains several useful shell commands which I use frequently during my work.

$0 - Get current shell

$ echo $0
zsh
@valosekj
valosekj / string_manipulation.md
Last active April 10, 2023 13:37
Useful string manipulation examples for bash and zsh #blog
View string_manipulation.md

Useful string manipulation examples for bash and zsh

I need very often to modify filenames or replace/delete their parts across huge number of files. I was using sed command for these purposes but recently I have found out that all these tasks can be easily done directly in bash (or zsh) because both of them support so called string manipulation operations.

String manipulations

Define some example string:

$ file=some_file_name.txt