Skip to content

Instantly share code, notes, and snippets.

@metaphore
metaphore / free_port.sh
Created July 28, 2025 20:23
Free network socket with the specified port by killing the occupied process(es).
#!/bin/bash
# Usage: free_port.sh <PORT> [PROTOCOL]
# PROTOCOL: tcp | udp | (anything lsof -i:PORT would accept, e.g. "rpc", "icmp", etc.)
# If PROTOCOL is omitted, all protocols on that port will be targeted.
if [ -z "$1" ]; then
echo "Usage: $0 <PORT> [PROTOCOL]"
exit 1
fi
@metaphore
metaphore / find_window_by_process.sh
Created July 26, 2025 12:13
Find a window corresponding to the process containing a substring in its name
#!/bin/bash
# Check for argument
if [ -z "$1" ]; then
echo "Usage: $0 <process-name-substring>" >&2
exit 1
fi
search_term="$1"
@metaphore
metaphore / unzip_wav_files.sh
Last active July 24, 2025 10:42
Unzip only wav files from all the archives in the current dir and report skipped files.
#!/bin/bash
BOLD="\e[1m"
RESET="\e[0m"
RED="\e[31m"
total_wav=0
for zipfile in *.zip; do
[ -e "$zipfile" ] || continue
@metaphore
metaphore / 70-synaptics.conf
Created June 23, 2025 22:29
ThinkPad X1 Extreme Gen2 touchpad config for PopOS!
# Place me to /etc/X11/xorg.conf.d/70-synaptics.conf
# for the best ThinkPad X1 Extreme Gen2 touchpad expreience (PopOS).
Section "InputClass"
Identifier "touchpad catchall"
Driver "synaptics"
MatchIsTouchpad "on"
# This option is recommend on all Linux systems using evdev, but cannot be
# enabled by default. See the following link for details:
# http://who-t.blogspot.com/2010/11/how-to-ignore-configuration-errors.html
@metaphore
metaphore / SecondOrderDynamics.java
Last active November 4, 2023 13:52
Second order dynamics 2D for Java. Inspired by https://youtu.be/KPoeNZZ6H4s
public class SecondOrderDynamics2D
{
// Dynamic constants.
private float k1, k2, k3;
// Previous dst.
private float pDstX, pDstY;
// State variables.
private float posX, posY;
private float accX, accY;
private float velX, velY;
@metaphore
metaphore / unity
Created January 9, 2023 15:42
Linux script to launch a Unity Editor (installed from Unity Hub) for the specific project.
#!/bin/bash
# Note that the shell option `nullglob` needs to be set. **It is not set by default.**
# It prevents an error in case the glob (or one of multiple globs) does not match any name.
shopt -s nullglob
PROJECT_DIR=$(realpath "$1")
if [ ! -d "$PROJECT_DIR" ]; then
echo "Project directory is not valid: $1" >&2 &&\
@metaphore
metaphore / images.thumbnailer
Last active June 4, 2025 21:17
Gnome | Better image thumbnails
[Thumbnailer Entry]
TryExec=/usr/bin/convert
Exec=/usr/bin/convert -colorspace sRGB %i'[0]' -background transparent -flatten -filter Point -thumbnail %sx%s -gravity center -extent %sx%s png32:%o
MimeType=image/png;image/bmp;image/x-bmp;image/x-MS-bmp;image/gif;image/x-icon;image/x-ico;image/x-win-bitmap;image/vnd.microsoft.icon;application/ico;image/ico;image/icon;text/ico;application/x-navi-animation;image/jpeg;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/tiff;image/x-xpixmap;image/x-xbitmap;image/x-tga;image/x-icns;image/jp2;image/jpeg2000;image/jpx;image/x-quicktime;image/qtif;image/vnd.adobe.photoshop;image/x-photoshop;image/x-psd;application/psd;application/x-psd;image/webp;
@metaphore
metaphore / aseprite-thumbnailer
Last active January 1, 2023 15:59
Gnome | Aseprite thumbnail generator
#!/usr/bin/sh
if [ $# -ge 2 -a $# -lt 4 ]; then
mkdir -p /tmp/Aseprite
filename="$(mktemp -d -p /tmp/Aseprite/).png"
if [ $# -eq 2 ]; then
aseprite -b --frame-range "0,0" $1 --trim --sheet $filename
elif [ $# -eq 3 ]; then
aseprite -b --frame-range "0,0" $1 --shrink-to "$3,$3" --trim --sheet $filename
@metaphore
metaphore / vid_remux_davinci.sh
Created November 2, 2022 17:52
Davinci Resolve Linux video transcode script.
#!/bin/bash
ABS_FILEPATH=$(realpath "$1")
ABS_DIR=$(dirname "$ABS_FILEPATH")
FILENAME=$(basename -- "$1")
EXTENSION="${FILENAME##*.}"
FILENAME="${FILENAME%.*}"
# echo "Filename is $FILENAME and the EXTENSION is $EXTENSION. Dir is $ABS_DIR"
@metaphore
metaphore / .tigrc
Last active July 10, 2022 17:32
My own tigrc with a few nifty perks.
bind status D !@?rm -r %(file)
bind status P !git push origin
bind status A !git add .
bind stage 1 stage-update-line
set blame-view = id:yes,color file-name:no author:abbreviated date:relative-compact line-number:yes,interval=1 text
set main-view = line-number:no,interval=5 id:no date:relative-compact author:abbreviated commit-title:yes,graph,refs,overflow=no
set tree-view = line-number:no,interval=5 mode author:abbreviated file-size date:relative-compact id:no file-name