Skip to content

Instantly share code, notes, and snippets.

@TheDiveO
TheDiveO / nsfdref.py
Created Jan 9, 2020
Demonstrates keeping namespaces alive by keeping an open fd for them, as well as how the discovery powers of "lsns" and "lsuserns" differ.
View nsfdref.py
# nsfdref.py
#
# Creates two network namespaces, referencing the first one by fd, and
# showing the output of "lsns" versus "lsuserns". "lsuserns" is able
# to discover the first network namespace from the fd which keeps the
# namespace alive.
#
# Requires these Python3 packages:
# - pip3 install unshare
# - pip3 install python-prctl
@TheDiveO
TheDiveO / inversehierarchy.sh
Last active Dec 23, 2019
Can child(!) PID namespaces be owned by parent(!) user namespaces?
View inversehierarchy.sh
#!/bin/bash
# Test the hypothesis that PID namespace hierarchy cannot "run on reverse" to
# the user namespace hierarchy. In particular, a PID child namespace cannot be
# owned by a parent user namespace. However, a PID namespace can be a child of a
# PID namespace owned by a parent user namespace.
echo "trying to create a child PID namespace which is owned by a parent user namespace..."
NSTEXTREPR='([[:alpha:]]+):\[([[:digit:]]+)\]'
SECTION="--------------------"
@TheDiveO
TheDiveO / runwithkp.sh
Created Jul 12, 2019
Starts local Kubernetes API proxy and creates a suitable context, runs application, then stops the proxy after the application has finished.
View runwithkp.sh
#!/bin/bash
CONTEXT="minikube"
PROXYCONTEXT="proxykube"
function cleanup {
kubectl config delete-context $PROXYCONTEXT 2>/dev/null
kubectl config delete-cluster $PROXYCONTEXT 2>/dev/null
}
@TheDiveO
TheDiveO / transcode-raw-screenrecording.sh
Created May 16, 2019
Correctly transcode in-device Android screen recordings (which were created by ffmpeg), so that they can be correctly edited and processed further during post. In particular, enforces a fixed framerate and the correct color coefficients.
View transcode-raw-screenrecording.sh
#!/bin/bash
# Correctly transcode in-device screen recordings from Android, so they
# do not cause all kinds of mishaps later down the editing and rendering
# pipeline. In particular, enforces a fixed framerate to avoid problems
# with widely varying dynamic frame rates, which can go from anywhere
# a frame every 10s of seconds to 100fps or so. Additionally, we
# enforce the correct color coefficients for the transcoding to avoid
# video tools to guesstimate completely nonsense transformation -- ffmpeg,
# I'm looking at you here.
shopt -s extglob
@TheDiveO
TheDiveO / registry.sh
Created Apr 6, 2019
Operate a host-local Docker container registry for kubeadm-dind clusters.
View registry.sh
#!/bin/bash
# TheDiveO
function log {
local OPTS=""
if [[ "$1" = "-n" ]]; then
shift; OPTS+="-n"
fi
MSG="$1"
shift
@TheDiveO
TheDiveO / tapclient.c
Last active Mar 22, 2019
TAP client supporting specifying TAP ifname and TAP client network namespace
View tapclient.c
/* modified from: https://github.com/a34729t/exp/blob/master/tunclient.c */
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/if.h>
#include <linux/if_tun.h>
@TheDiveO
TheDiveO / extract-frames
Last active Mar 23, 2018
Scans for extracted frame image PNG files and (re)extracts the frame directly from their corresponding video media files, using source resolution and orientation instead of project resolution and orientation. Frame image PNG files are searched in the current working directory, as well as all its sub directories.
View extract-frames
#!/bin/bash
#
# (Re-) Extract frame images directly from its corresponding video media
# file. The frame image filenames are expected to be in the format of
# videofilename-f000000.png, that is: the filename of the video media file,
# but without its extension, then followed by "-f" and a six digit frame
# number (base 10), and finally the ".png" suffix.
#
# Copyright 2018 TheDiveO
#