Skip to content

Instantly share code, notes, and snippets.

@hungyiwu
hungyiwu / dask_note.py
Created July 29, 2020 16:20
Reminder for myself on configuring local dask.distributed cluster and URL of corresponding documentations
# setup local cluster for dask
#
# API documentation
# * dask.distributed.worker
# https://distributed.dask.org/en/latest/worker.html#distributed.worker.Worker
# * dask.distributed.LocalCluster
# https://distributed.dask.org/en/latest/api.html#distributed.LocalCluster
# * dask.distributed.Client
# https://distributed.dask.org/en/latest/api.html#distributed.Client
@hungyiwu
hungyiwu / timer_class.py
Created July 15, 2020 02:38 — forked from DahlitzFlorian/timer_class.py
Article: How To Create Your Own Timing Context Manager
from time import time
class Timer(object):
def __init__(self, description):
self.description = description
def __enter__(self):
self.start = time()
def __exit__(self, type, value, traceback):
self.end = time()
@hungyiwu
hungyiwu / install_SimpleElastix.sh
Last active February 25, 2021 20:49
Install SimpleElastix with Python3 on the O2 server at Harvard Medical School
#!/bin/bash
#SBATCH --job-name=installSE
#SBATCH -c 4 # Number of cores
#SBATCH -t 0-03 # Runtime in D-HH:MM, minimum of 10 minutes
#SBATCH -p short # Partition to submit to, whichever is faster
#SBATCH --mem-per-cpu=4G # Memory (see also --mem)
#SBATCH -o joboutput.out # job output
#SBATCH -e joberrors.err # job error log
# load modules
@hungyiwu
hungyiwu / slurm_gettimeout.sh
Created June 23, 2020 13:59
Handy one-line command to get SLURM job array task IDs timed out for re-run
#!/bin/bash
# Use case:
# You ran a job array in SLURM by something like `sbatch --array=1-300 run.sh`
# ...checked the error logs by `tail -n 1 *.err` and saw many got timed-out
# ...would like to re-run tasks with higher time quota but first need to know their task IDs
# ...instead of jotting down the IDs by scanning the terminal with your eyes,
# or writting yet-another Python script to parse the error logs,
# you can use this one-line command
sacct -j [JOB-ID] -s to --brief\
@hungyiwu
hungyiwu / .tmux.conf
Last active July 13, 2023 02:57
configs
# ~/.tmux.conf
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi V send -X select-line
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi 'Home' send -X start-of-line
bind-key -T copy-mode-vi 'End' send -X end-of-line
setw -g history-limit 1000000
@hungyiwu
hungyiwu / slurmjob.sh
Last active May 4, 2020 18:24
SLURM job submission scripts
#!/bin/bash
#SBATCH --job-name=newjob
#SBATCH -n 1 # Number of cores
#SBATCH -N 1 # Ensure that all cores are on one machine
#SBATCH -t 0-01:00 # Runtime in D-HH:MM, minimum of 10 minutes
#SBATCH -p shared,general # Partition to submit to, whichever is faster
#SBATCH --mem-per-cpu=4G # Memory (see also --mem)
#SBATCH -o joboutput_%j.out # File to which STDOUT will be written, %j inserts jobid
#SBATCH -e joberrors_%j.err # File to which STDERR will be written, %j inserts jobid
#SBATCH --mail-type=ALL # Type of email notification- BEGIN,END,FAIL,ALL