Skip to content

Instantly share code, notes, and snippets.

View blackhole077's full-sized avatar

Jeevan Rajagopal blackhole077

View GitHub Profile
@blackhole077
blackhole077 / get_start_end_times_from_dataframe_based_on_binary_condition.py
Created March 25, 2022 16:34
Find all contiguous chunks of time where some condition was either True or False. Given a Pandas DataFrame that has timestamp information (e.g., Unix Time in ms) and some column where the values are either True or False, this function will find the start and end times, along with what the value was for that slice of time, for all chunks present,…
import numpy as np
import pandas as pd
from typing import List, Tuple
def get_start_end_times_from_dataframe_based_on_binary_condition(pd_timestamp_series:pd.Series, pd_binary_condition_series:pd.Series)->List[Tuple[int]]:
"""Find all contiguous chunks of time where some condition was either True or False.
Given a Pandas DataFrame that has timestamp information (e.g., Unix Time in ms) and some column where the values are either True or False, this function
will find the start and end times, along with what the value was for that slice of time, for all chunks present, returning them as a list of tuples.
NOTE: While it could be argued that this would work for categorical conditions (i.e., non-binary conditions), I personally did not write this function
@blackhole077
blackhole077 / ffmpeg_multi_crossfade.py
Created October 30, 2020 16:41
A small Python Gist that allows for a list of videos (no audio) to be crossfaded automatically, provided they're all in the same folder.
from os.path import join
from subprocess import run, TimeoutExpired, CalledProcessError, check_output
from typing import List
def run_command(command_args: List[str]=None, timeout_duration: int=30) -> None:
"""
Run a command via subprocessing.
Attempts to run the command given, with a timeout_duration (default 30s).
If the command cannot finish executing, then it will return a TimeoutError.