Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from itertools import chain
intervals_a=[(0, 3), (5, 8), (11, 12), (14, 15)]
intervals_b=[(1, 2), (4, 6), (7, 9), (10, 13), (14, 15)]
def intersect_intervals(intervals_a, intervals_b):
# Create events like
# [[<point_a_0>, <open_a>, <miss_b>], [<point_a_1>, <close_a>, <miss_b>], ...]
# and [[<point_b_0>, <miss_a>, <open_b>], [<point_b_1>, <miss_a>, <close_b>], ...]
@EtsuNDmA
EtsuNDmA / gist:ba352596ab58ea84b3a8534f5cce043c
Created February 16, 2018 05:52 — forked from johanmeiring/gist:3002458
"git lg" alias for pretty git log
# From http://garmoncheg.blogspot.com/2012/06/pretty-git-log.html
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
@EtsuNDmA
EtsuNDmA / frechet.py
Created November 16, 2018 14:49 — forked from MaxBareiss/frechet.py
Fréchet Distance in Python
# Euclidean distance.
def euc_dist(pt1,pt2):
return math.sqrt((pt2[0]-pt1[0])*(pt2[0]-pt1[0])+(pt2[1]-pt1[1])*(pt2[1]-pt1[1]))
def _c(ca,i,j,P,Q):
if ca[i,j] > -1:
return ca[i,j]
elif i == 0 and j == 0:
ca[i,j] = euc_dist(P[0],Q[0])
elif i > 0 and j == 0:
@EtsuNDmA
EtsuNDmA / django_jupyter_settings.py
Last active November 30, 2018 11:51
Settings for Django kernel in Jupyter and JupyterLab
# Using Jupyter with Django
# Requires django_extensions
# For all settings see jupyter --help-all
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
try:
import jupyterlab
notebook_default_url = '/lab' # Using JupyterLab
except ImportError:
notebook_default_url = '/tree' # Using Jupyter
@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 / 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):
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 / 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)"
@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 / 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