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 / fork_sync.md
Last active December 8, 2023 12:56
Синхронизация форка репозитория с исходным репозиторием

Привет, дорогой друг!

Если ты здесь, то видимо ты обучаешься на курсе Data Mining in Action. Должно быть ты уже заметили, что материалы курса выкладываются в этом репозитории. Сейчас я расскажу тебе один из способов, как всегда иметь под рукой его свежую версию.

Если какие-то шаги уже выполнены, просто пропусти их.

  1. Чтобы получить себе копию репозитория курса, нужно сделать fork исходного репозитория repo_fork

  2. Теперь клонируем репозиторий к себе на компьютер, выполнив в консоли команду:

@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 / django_jupyter.md
Last active September 13, 2024 17:23
Two ways to integrate Django with Jupyter (JupyterLab)

⚠️ This gist was the first time written in 2018. It was tested with django==2.2.x. It's likely to be relevant for the newer versions of django and jupyter, but I did't check that.

2023-03-15: checked it for python == 3.11, django == 4.1.7, jupyterlab = 3.6.1, django-extensions == 3.2.1, jupyter-server <= 2.0.0

Django_jupyter

Using Django project in Jupyter or JupyterLab

Method 1 (using shell_plus)

@EtsuNDmA
EtsuNDmA / django_jupyter_ru.md
Last active July 18, 2024 16:15
Интеграция Django с Jupyter (JupyterLab)

Django_jupyter

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

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

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

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

    pip install django-extensions
@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