Skip to content

Instantly share code, notes, and snippets.

View valosekj's full-sized avatar

Jan Valosek valosekj

View GitHub Profile
@valosekj
valosekj / accelarate_pytorch_mps.md
Last active July 14, 2024 02:26
Accelerate PyTorch using `MPS` on Apple silicon

Accelerate PyTorch using MPS on Apple silicon

  1. Download Xcode from the App Store
  2. Opan a new Terminal tab and run sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
  3. Accept the Xcode licence by running: sudo xcodebuild -license
  4. Try running /usr/bin/xcodebuild -version to ensure Xcode is correctly installed and configured
  5. Create a new conda env and install pytorch-nightly:
conda create -n nanogpt python=3.10
@valosekj
valosekj / load_python_colormap_to_fsleyes.md
Last active July 3, 2024 18:33
Load a Python colormap to FSLeyes
@valosekj
valosekj / custom_FSLeyes_scene.png
Last active July 10, 2024 14:59
Set up a custom scene using the FSLeyes API via a custom Python script
custom_FSLeyes_scene.png
@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
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
# 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

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 / virtual_enviroments.md
Last active November 11, 2023 19:24
How to create and use virtual environments (venv and conda)

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 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: