This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>], ...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 --" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Небольшая шпаргалка по библиотечке respx. Все это есть в документации https://lundberg.github.io/respx/guide/, | |
но местами написано очень коротко и не очевидно. | |
Зависимости: python > 3.10, httpx, respx, pytest-asyncio | |
""" | |
from typing import Any | |
import httpx | |
import pytest |
OlderNewer