Skip to content

Instantly share code, notes, and snippets.

View valosekj's full-sized avatar

Jan Valosek valosekj

View GitHub Profile
@valosekj
valosekj / convert_heif_to_jpg.md
Last active January 17, 2021 17:35
Convert photos from HEIF to JPEG #blog

Convert photos from HEIF to JPEG

I use on my iPhone HEIF (High Efficiency Image File Format) format for storing my photos.

This format is widely supported throughout Apple ecosystem but sometimes I need to quickly convert photos from HEIF to JPG to be able to use these photos also elsewhere (Windows, some websites, etc.)

I use for this purpose convert command line tool from ImageMagick

Usage:

@valosekj
valosekj / useful_shell_commands.md
Last active October 17, 2021 11:25
Useful shell commands #blog

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 / run_matlab_from_python.md
Last active June 29, 2022 10:28
Run matlab function from python script #blog

Run matlab function from python script

I needed to run matlab script from python script. I wanted to pass several input arguments from pandas DataFrame, perform calculation in matlab and return multiple output arguments back to python.

Steps (MacOS):

  1. Install matlab engine API for python:

In your terminal, go to directory where matlab is install and run installation python script, e.g.:

@valosekj
valosekj / ssh_configuration.md
Last active September 27, 2022 06:45
Configuration of `ssh` connection #blog

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

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 / change_itk_direction.py
Last active February 25, 2023 20:32
Fix ITK direction for nnU-Net
# 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
#
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 / run_app_from_terminal.md
Last active May 11, 2023 15:15
Run arbitrary application from terminal on MacOS #blog

Run arbitrary application from terminal on MacOS

Sometimes, it is convenient to have possibility to start/run any application (like your internet browser or text editor) directly from your terminal. Most of these applications however do not create shortcut for easy run from terminal during their installation. Below is short manual how to create this shortcut manually.

Steps

  1. Open terminal (cmd + space --> type terminal)

  2. Navigate to a directory where you have your code/scripts. For example ~/code or /usr/local/bin:

@valosekj
valosekj / run_python_from_shell.md
Last active June 20, 2023 15:14
Run python script from shell #blog

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 / template_script_sct_run_batch.md
Created July 18, 2023 19:36
Template script for `sct_run_batch`

Template script for sct_run_batch

This gist contains a template script that can be run across multiple subjects using the sct_run_batch wrapper script.

The template bash script below can be run from you command line using the following command:

sct_run_batch -script example_script.sh -path-data <DATA> -path-output <DATA>_202X-XX-XX -jobs 16