Skip to content

Instantly share code, notes, and snippets.

@raspi
raspi / setup_namespace_network.sh
Created Aug 14, 2022
Setup Linux namespace network with virtual bridge
View setup_namespace_network.sh
#!/bin/bash
# (C) Pekka Järvinen 2022
# Name for bridge which virtual namespaces will use to communicate with each other
BRIDGENAME="gamebr0"
# Prefix for network
NETPREFIX="192.168.255."
# Starting IP (NETPREFIX + this)
let STARTIP=10
View Cakez TD demo Linux Steam.md

Cakez TD demo on Linux Steam

Download from https://cakez77.itch.io/cakeztd

First unzip the demo .zip with Ark.

After unzipping you'll have broken filenames in single directory:

% LANG=C ls
@raspi
raspi / ffprobe_json.py
Created Dec 9, 2021
Get JSON from FFProbe
View ffprobe_json.py
import json
import subprocess
from pathlib import Path
def ffprobe(path: Path):
cmd = [
"ffprobe",
"-v", "error",
"-select_streams", "v",
"-show_entries", "format=filename:stream=height",
@raspi
raspi / censor.sh
Created Mar 27, 2021
Censor MAC address, IPv4 address from some output
View censor.sh
# mac:
echo "..." | perl -pe 's@[\da-f:]{17}@xx:xx:xx:xx:xx:xx@ig'
# IPv4
echo "..." | perl -pe 's@[\d\.]{7,15}@X.X.X.X@ig'
@raspi
raspi / list-kernel-modules.py
Created Mar 26, 2021
List all loadable kernel modules
View list-kernel-modules.py
import json
import subprocess
import sys
from pathlib import Path
skipped_keys = [
'sig_id',
'signer',
'sig_key',
'sig_hashalgo',
@raspi
raspi / ffmpeg-crop.sh
Last active Mar 24, 2021
Crop video with FFMPEG
View ffmpeg-crop.sh
#!/bin/bash
# Crop a part of a video with FFMPEG
if [[ $# -eq 0 ]] ; then
echo "Usage:"
echo " $0 <filename> <left> <right> <top> <bottom>"
echo ""
echo "Example:"
echo " $0 myvid.mp4 700 600 200 400"
View get_machine_endianness.go
var nativeEndian binary.ByteOrder
func init() {
buf := [2]byte{}
*(*uint16)(unsafe.Pointer(&buf[0])) = uint16(0xABCD)
switch buf {
case [2]byte{0xCD, 0xAB}:
nativeEndian = binary.LittleEndian
case [2]byte{0xAB, 0xCD}:
@raspi
raspi / mac_list_vendors.sh
Created Mar 16, 2021
Get vendors from `/proc/net/arp` with systemd's OUI vendor database
View mac_list_vendors.sh
#!/bin/bash
# Get vendors from /proc/net/arp with systemd's OUI vendor database
set -eu
set -o pipefail
OUIDB=/usr/lib/udev/hwdb.d/20-OUI.hwdb
while IFS=$' ' read -r ipaddr htype flags mac mask iface;
do
@raspi
raspi / imagemagick_identify_json.sh
Last active Mar 13, 2021
Output JSON from ImageMagick magick identify command
View imagemagick_identify_json.sh
#!/bin/bash -e
# Output JSON from ImageMagick magick identify command
if [[ $# -eq 0 ]] ; then
echo "Usage:"
echo " $0 <filename>"
echo ""
exit 0
fi
View pdf.sh
#!/bin/bash
find . -maxdepth 1 -type f -iname "*.pdf" -exec gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true -dColorImageResolution=150 -dNOPAUSE -dBATCH -sOutputFile={}.new.pdf {} \;