Skip to content

Instantly share code, notes, and snippets.

import argparse
import logging
import os
import time
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
from datetime import timedelta
from functools import partial
from pathlib import Path
import pydicom
@EtsuNDmA
EtsuNDmA / anonymize_dicom.py
Created October 28, 2022 09:58
Simple script to anonymize dicoms in parallel
import argparse
import logging
import os
import time
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
from datetime import timedelta
from functools import partial
from pathlib import Path
import pydicom
# Based on https://gist.github.com/spicycode/1229612
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@EtsuNDmA
EtsuNDmA / test_respx_cheetsheet.py
Last active November 24, 2021 10:17
Небольшая шпаргалка по библиотечке respx
"""
Небольшая шпаргалка по библиотечке respx. Все это есть в документации https://lundberg.github.io/respx/guide/,
но местами написано очень коротко и не очевидно.
Зависимости: python > 3.10, httpx, respx, pytest-asyncio
"""
from typing import Any
import httpx
import pytest
@EtsuNDmA
EtsuNDmA / .gitconfig
Last active April 7, 2021 06:42
Aliases for git commands
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold cyan)<%an>%Creset' --abbrev-commit
ss = status -s
b = branch
ca = commit -a -m
last = log -1 HEAD
co = checkout
# fuzzy checkout by ticket number for branches like feature/cool-stuff-abc1234
fco = "!f() { git branch -a | egrep -m1 \"(feature|hotfix)/.*${1}\" | sed \"s/remotes\\/origin\\///\" | xargs git checkout; }; f"
amend = commit --amend --no-edit
@EtsuNDmA
EtsuNDmA / add_python_kernel.txt
Created April 23, 2020 06:50
Using Virtual Environments in Jupyter Notebook and Python
# https://janakiev.com/blog/jupyter-virtual-envs/
# https://ipython.readthedocs.io/en/stable/install/kernel_install.html
1. Activate your venv
2. pip install --user ipykernel
3. python -m ipykernel install --user --name=myenv --display-name "Python (myenv)"
conda install -y nodejs
pip install ipympl
pip install --upgrade jupyterlab
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install jupyter-matplotlib
jupyter nbextension enable --py widgetsnbextension
# then use magic %matplotlib widget
@EtsuNDmA
EtsuNDmA / find_package_dirs.py
Created July 31, 2019 06:30
Find all package directories in given paths
def find_package_dirs(paths):
"""Find all package directories in given paths"""
dirs = []
for importer, modname, ispkg in pkgutil.iter_modules(paths):
module_loader = importer.find_module(modname)
if ispkg:
yield module_loader.filename
# tmpdir is pytest fixture
def test_find_package_dirs(tmpdir):
@EtsuNDmA
EtsuNDmA / line_profiler_decorator.py
Created April 3, 2019 13:08
Decorator for line profiler
def profile(func):
import functools
@functools.wraps(func)
def inner(*args, **kwargs):
from line_profiler import LineProfiler
lp = LineProfiler()
lp_wrapper = lp(func)
result = lp_wrapper(*args, **kwargs)
lp.print_stats()
return result
@EtsuNDmA
EtsuNDmA / django_jupyter_ru.md
Last active February 25, 2022 00:52
Интеграция Django с Jupyter (JupyterLab)

Django_jupyter

Руководство по интеграции Django и Jupyter

Способ 1 (с использованием shell_plus)

Считаем, что django и jupyter уже установлены

  1. Установить django-extensions

    pip install django-extensions