Skip to content

Instantly share code, notes, and snippets.

View romech's full-sized avatar

Roman Aleksandrov romech

  • Amsterdam
View GitHub Profile
@romech
romech / catchtime_context_manager.py
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
romech / concat_videos.sh
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
romech / check_ngrok.sh
Created March 3, 2021 09:42
Check that ngrok is running. If not, try to restart. Return tunnel urls.
#!/bin/bash
resp=$(curl -sS http://127.0.0.1:4040/api/tunnels || 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 http://127.0.0.1:4040/api/tunnels)
fi
@romech
romech / confusion_matrix_pretty_print.py
Last active May 31, 2020 09:43 — forked from shaypal5/confusion_matrix_pretty_print.py
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
romech / Dockerfile
Last active May 3, 2020 17:29
Spark + Zeppelin with Docker Compose
FROM apache/zeppelin:0.8.1
RUN wget https://apache-mirror.rbc.ru/pub/apache/spark/spark-2.4.5/spark-2.4.5-bin-hadoop2.7.tgz \
&& 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
EXPOSE 8080
@romech
romech / levit.py
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: https://goo.gl/GoeKS5
Doesn't work with negative cycles.
See example at the end.
'''
from collections import defaultdict, OrderedDict
from itertools import chain
from math import inf