Skip to content

Instantly share code, notes, and snippets.

@ntrrgc
ntrrgc / get-terminal-background-color.py
Created May 2, 2024 15:33
OSC 10 & 11: Query terminal foreground and background colors
#!/usr/bin/env python3
import os, termios, collections, re
TermAttr = collections.namedtuple("TermAttr",
["iflag", "oflag", "cflag", "lflag", "ispeed", "ospeed", "cc"])
old = TermAttr._make(termios.tcgetattr(0))
new = old._replace(
lflag=old.lflag & ~(termios.ECHO | termios.ICANON)
)
@ntrrgc
ntrrgc / mp4parser.py
Last active December 1, 2022 14:07 — forked from mildsunrise/mp4parser.py
🕵️‍♀️ MP4 parser / dissector for the command line
#!/usr/bin/env python3
'''
Code by Alba Mendez, manually copied and pasted, had 8 revisions when copied.
https://gist.github.com/mildsunrise/ffd74730504e4dc44f47fc7528e7bf59
Portable* ISO Base Media File Format dissector / parser.
Usage: ./mp4parser.py <file name>
(*) Needs Python 3.8+
@ntrrgc
ntrrgc / register_path.sh
Created October 14, 2022 17:03
Function to add paths to env vars such as PATH or LD_LIBRARY_PATH without cluttering them
register_path() {
# Usage:
# register_path <env_var_name> <provided_path> [after]
#
# Registers a path in a PATH-like environment variable.
# The provided_path is prepended unless the "after"
# argument is provided, in which case it's appended.
#
# Example:
# register_path LD_LIBRARY_PATH /an/important/path
@ntrrgc
ntrrgc / plot-wpt-compat.py
Created June 10, 2021 13:18
Plots the number of WPT tests passing for a given feature and a set of browsers over time
#!/usr/bin/python3
# Instructions:
# 1. Checkout: https://github.com/Ecosystem-Infra/wpt-results-analysis.git
# 2. cd compat-2021
# 3. Edit main.js like this:
# const CATEGORIES = [
# + 'media-source',
# + 'media',
# ];
# ...
@ntrrgc
ntrrgc / backup-nas.sh
Last active April 6, 2020 20:09
My backup script for synology NAS, with safety checks for archival
#!/bin/bash
set -eu
found_not_mounted=0
function check_not_empty() {
local path="$1"
if [ ! -d "$path" ]; then
found_not_mounted=1
echo "ERROR: $path does not exist!"
elif [ ! "$(ls -A "$path")" ]; then
@ntrrgc
ntrrgc / traceback-add-offsets.py
Created July 25, 2018 17:54
Add library offsets to otherwise useless WebKit crash tracebacks (requires saving /proc/{pid}/maps somewhere before the crash)
import os
import re
from collections import namedtuple
path_maps = os.path.expanduser("~/tmp/rpi-crash-maps")
path_stack = os.path.expanduser("~/tmp/rpi-crash-stack")
MapsLine = namedtuple("MapsLine", ["start", "end", "file"])
@ntrrgc
ntrrgc / page-watcher.cpp
Created June 30, 2018 15:52
Proof of concept for page-based watchpoints
#define __USE_POSIX199309
#include <cassert>
#include <signal.h>
#include <mutex>
#include <functional>
#include <sys/ptrace.h>
#include <malloc.h>
#include <sys/mman.h>
#include <unistd.h>
#include <set>
@ntrrgc
ntrrgc / webkit-remote-build.sh
Created September 15, 2017 18:36
WebKit remote build with delta downloads
#!/bin/bash
set -eu
BUILD_HOST=homura.local
BUILD_ARGS=(--gtk --debug)
REMOTE_BUILD_DIR=WebKitBuild/Debug
LOCAL_BUILD_DIR=WebKitBuild/Debug
# Files big enough to deserve xdelta transfer
# Generate with the following command:
@ntrrgc
ntrrgc / gen-edit-lists.py
Last active August 30, 2022 23:59
Generate crazy MP4 edit lists to be added to media files for testing.
#!/usr/bin/python3
#
# Generate crazy MP4 edit lists to be added to media files for testing.
#
# 1. Modify the timescales below with the actual values from the MP4 file.
#
# 2. Run the following commands to patch the file with Bento:
#
# # Remove previously existing edit list (optional, only if there is some)
# mp4edit --remove moov/trak/edts original.mp4 patched1.mp4
@ntrrgc
ntrrgc / graceful-libvirtd-shutdown.service
Created August 20, 2017 17:04
Gracefully shutdown libvirtd VMs on shutdown. Start and enable the provided systemd service for it to work.
[Unit]
Description=Wait for VMs to shutdown gracefully
After=libvirtd.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/home/ntrrgc/dotfiles/bin/vm-shutdown
[Install]