Skip to content

Instantly share code, notes, and snippets.

View zambonin's full-sized avatar

Gustavo Zambonin zambonin

View GitHub Profile
@zambonin
zambonin / compare-dirs-with-gsba-files.sh
Last active January 8, 2024 23:17
Compare two directories with GSBA files.
#!/usr/bin/env sh
#
# A POSIX-compliant shell script that compares the contents of GSBA files,
# created by the GameSave Manager [1] Windows application. Such files are
# essentially ZIP files with a GSM_INFO.xml metadata descriptor.
#
# The script accepts two directories as the arguments; the first is treated as
# containing "old" files, and the second, the "new" files. Only games in the
# second directory are compared with their counterparts.
#
@zambonin
zambonin / download-attachments-from-issues-gitlab.sh
Last active August 17, 2023 17:34
Downloads all attachments from all issues of a GitLab project.
#!/usr/bin/env sh
# shellcheck disable=SC2086
# A POSIX-compliant shell script that downloads all uploaded attachments from
# GitLab issue descriptions and comments for a single project, following the
# longstanding open issue [1]. It reads several environment variables to send
# the requests correctly via the GitLab API.
#
# * `GITLAB_INSTANCE`: the host of the target GitLab instance;
# * `PROJECT_ID`: the unique project ID for the instance;
@zambonin
zambonin / picross_line_solver.py
Created May 12, 2023 23:53
Shows all boxes that can be filled in a Picross puzzle given the input pattern(s).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from argparse import ArgumentParser, RawDescriptionHelpFormatter
def solve(size: int, line: list[int]) -> list[bool]:
solution = [False] * size
needed_to_fill = sum(line) + len(line) - 1
@zambonin
zambonin / git-merge-repos.sh
Last active June 18, 2022 19:51
Merge multiple local Git repositories.
#!/usr/bin/env bash
# A shell script that merges local Git repositories into a new repository. The
# script accepts multiple directories and/or glob patterns as arguments. Each
# local repository will be moved into a subdirectory, named by the user via
# stdin.
#
# Dependencies: bash 4+, git and git-filter-repo.
GIT_REPOS=( "$@" )
@zambonin
zambonin / Makefile
Created April 18, 2021 17:47
Use the keyboard scroll lock LED as a network activity indicator.
# A Makefile to turn the keyboard scroll lock LED into a network activity
# indicator LED through kernel instrumentation, as documented below.
#
# https://www.kernel.org/doc/html/latest/leds/index.html
# https://www.reddit.com/r/linux/comments/m2kkna/turn_your_keyboard_leds_into_network_indicators/gqjqmx0/
LEDTRIG_MODULE = /lib/modules/$$(uname -r)/kernel/drivers/leds/trigger/ledtrig-netdev.ko.xz
SCROLL_LOCK_LED = $(wildcard /sys/class/leds/input*::scrolllock)
NETWORK_INTERFACE = $(shell ip -br addr | awk '/UP/ { print $$1 }')
@zambonin
zambonin / bin-tree-chooser.sh
Last active February 11, 2021 03:08
Choose between 2^n choices with the help of a binary tree.
#!/usr/bin/env bash
# A shell script that helps a user to choose between 2^n possible choices by
# simulating a tournament through a perfect binary tree with randomly disposed
# nodes. It accepts input from /dev/stdin, i.e. through pipes or redirection.
#
# The power-of-2 input size restriction could be relaxed, but then choices
# would be probably less fair without repetitions of the classification process
# to make up for the generated tree prioritizing rightmost nodes.
@zambonin
zambonin / git-commit-heatmap.py
Last active February 3, 2021 12:58
Produces a heatmap of commit activity from Unix timestamps.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A Python 3.5+ script that prints a coloured heatmap of activity similar to
# the one shown in one's GitHub profile. It has some limitations such as not
# printing month and weekday names, because it is hard to predict where to put
# the month name. It should work in any terminal that supports 256 colors [1].
#
# The script accepts a list of Unix timestamps as piped or redirected
# input. For instance, to visualize the commit heatmap of a locally cloned
@zambonin
zambonin / git-estimate.sh
Last active November 18, 2020 05:01
Estimates how much time a project has taken according to the commit timeline.
#!/usr/bin/env sh
# shellcheck disable=SC2214
#
# A POSIX-compliant shell script that estimates the number of hours taken to
# create the contents of a Git repository. The heuristic is based on grouping
# bundles of commits according to a certain period limit, accumulating time
# differences between pairs of commits in each bundle, and compensating for its
# first commit with another parametrized quantity. Timestamps are taken from
# the author of the commit.
#
@zambonin
zambonin / git-size-history.sh
Created November 18, 2020 04:29
File size vs time as given by a Git repository. Inspired by http://phdcomics.com/comics/archive.php?comicid=1915.
#!/usr/bin/env bash
# shellcheck disable=SC2214
#
# A shell script that shows the size of a file in each commit that modifies it,
# alongside the timestamp taken from the author of the commit. This is useful
# to visualize the size evolution of a file.
#
# It accepts a single option to customize its behavior, described as
# follows. The last argument must be a valid file tracked by its respective
# repository, with the first file obtained from git-ls-files(1) as default.
@zambonin
zambonin / sendkeys.awk
Last active April 12, 2024 09:48
AWK script to send multiple `sendkey` commands to a QEMU virtual machine.
#!/usr/bin/env awk -f
#
# AWK script to send multiple `sendkey` commands to a QEMU virtual machine.
# It writes at a rate of roughly 40 keys per second, due to lower delays
# resulting in garbage output.
#
# It makes use of a TCP client created by an external utility, such as OpenBSD
# Netcat, to interact with QEMU's monitor and send a stream of `sendkey`
# commands. This is a practical way to transfer a small file or to script
# interactions with a terminal user interface.