Skip to content

Instantly share code, notes, and snippets.

View romech's full-sized avatar

Roman Aleksandrov romech

  • Amsterdam
View GitHub Profile
romech /
Last active November 11, 2023 16:25
Measure code execution time within a block using a Python context manager
from time import perf_counter
class catchtime:
def __enter__(self):
self._time_start = perf_counter()
return self
def __exit__(self, type, value, traceback):
self.elapsed = perf_counter() - self._time_start
romech /
Created June 28, 2021 09:49
Concatenate videos from current directory, sorted by time ascending
ls -tr1 | while read line; do echo file \'$line\'; done | ffmpeg -protocol_whitelist file,pipe -f concat -i - -c copy ../output.mp4
romech /
Created March 3, 2021 09:42
Check that ngrok is running. If not, try to restart. Return tunnel urls.
resp=$(curl -sS || echo 0)
if [[ $resp == "0" ]]; then
echo "Restarting service" >&2
pkill ngrok
screen -dmS ngrok /home/human/ngrok start --all
sleep 90
resp=$(curl -sS
romech /
Last active May 31, 2020 09:43 — forked from shaypal5/
Pretty print a confusion matrix with seaborn
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.metrics import confusion_matrix
def print_confusion_matrix(y_true, y_pred, class_names, normalize=True, figsize = (10,7), fontsize=14):
"""Prints a confusion matrix, as returned by sklearn.metrics.confusion_matrix, as a heatmap.
romech / Dockerfile
Last active May 3, 2020 17:29
Spark + Zeppelin with Docker Compose
FROM apache/zeppelin:0.8.1
RUN wget \
&& tar -xzf spark-2.4.5-bin-hadoop2.7.tgz \
&& mv spark-2.4.5-bin-hadoop2.7 /opt/spark
ENV SPARK_HOME=/opt/spark
romech /
Last active March 27, 2024 21:24
Levit's algorithm (also "Pape-Levit's") for finding the shortest paths from one `start` node to all another, Python 3 implementation.
Levit's algorithm for finding the shortest path from one `start` node to all another.
Written according to this article:
Doesn't work with negative cycles.
See example at the end.
from collections import defaultdict, OrderedDict
from itertools import chain
from math import inf