Skip to content

Instantly share code, notes, and snippets.

@rindeal
rindeal / gsettings-array.py
Last active April 24, 2024 08:28
GSettings array manipulation made easy from CLI
#!/usr/bin/env python3
# SPDX-FileCopyrightText: ANNO DOMINI 2024 Jan Chren (rindeal) <dev.rindeal(a)gmail.com>
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
import sys
assert sys.version_info >= (3, 11)
import argparse
@rindeal
rindeal / xkb-list-layouts-variants.sh
Last active April 24, 2024 06:21
POSIX shell functions and CLI utility to print/list all XKB layouts and their variants including "exotic" ones. Much improved replacement for "localectl"'s "list-x11-keymap-layouts" and "list-x11-keymap-variants" commands.
#!/bin/sh
# SPDX-FileCopyrightText: ANNO DOMINI 2024 Jan Chren (rindeal) <dev.rindeal(a)gmail.com>
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
# NOTE: Developed for xkbcli 1.5.0, might not work with later versions
xkb_list_layouts()
{
xkbcli list --load-exotic | \
@rindeal
rindeal / LinDiophantineEqSolver.c
Last active April 19, 2024 11:36
Linear Diophantine Equation Solver, includes calculations of coefficients of Bézout's identity and extended Euclidean algorithm for greatest common divisor.
int64_t
GCD(int64_t const a, int64_t const b)
{
register int64_t rt, r0 = a, r1 = b; // remainder
while (r1 != 0){
// classic Euclidean algorithm
rt = r1;
r1 = r0 % r1;
r0 = rt;
@rindeal
rindeal / Linux file IO monitoring.sh
Last active April 19, 2024 10:35
Linux file IO monitoring sysdig read/write/open files
#!/bin/sh
sudo sysdig -p '%proc.name|%evt.arg.fd.name' \
'evt.dir=> and ( fd.type=file or fd.type=directory ) and fd.name!=""' | \
awk -F\| '
BEGIN{
OFS="|"
}
$2!~/^<f>\/(dev|proc|run|sys).*/ {
print $1,substr($2,4);
@rindeal
rindeal / print_process_call_stack.sh
Last active April 19, 2024 10:10
Print process call stack. Pure BASH function.
#!/bin/bash
# based on https://stackoverflow.com/a/1438241/2566213
# pure BASH solution
print_process_call_stack() {
local -a trace=()
local -- cmdline
local -i pid=$$ ppid
#!/usr/bin/env python3.6
##
# Copyright 2018 Jan Chren (rindeal)
# Distributed under the terms of the GNU General Public License v3
##
class _FilesAndDirsGen:
_root_tmpdir: tempfile.TemporaryDirectory
_defs: typing.Union[dict, set]
@rindeal
rindeal / fetch_tar.py
Last active April 19, 2024 09:01
Python 3 function to extract/unpack TAR archive file directly from web URL in one continous stream.
# SPDX-FileCopyrightText: 2018 Jan Chren (rindeal)
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
import pathlib
import urllib
import shutil
import tarfile
def fetch_tar(url: str, dest_dir: pathlib.Path, clean_dest: bool = False, strip_components: int = 0):
if clean_dest and dest_dir.exists():
@rindeal
rindeal / hash-multi-n-print-markdown-table.sh
Last active March 17, 2024 01:30
Generate multiple hashes for a file and print them as a markdown table
#!/bin/sh
# requires `pee` command from `moreutils` suite
SUMS=(
md5sum
sha1sum
sha256sum
)
FILE="${1}"
printf '<details>\n'
@rindeal
rindeal / cpuid-dump.c
Last active November 11, 2023 16:32
CPUID dumper
#if !defined(__GNUC__) || ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800)
# error "This program requires GNU C compiler v4.8+!"
#endif
#include <stdio.h>
#include <stdbool.h>
#define PRINT_TEST_CPU_SUPPORT_RESULT(inst) printf("\t%-7s: %d\n", inst, __builtin_cpu_supports(inst)?1:0)
#define PRINT_TEST_CPU_TYPE_RESULT(inst) printf("\t%-12s: %d\n", inst, __builtin_cpu_is(inst)?1:0)
@rindeal
rindeal / uncrustify-c-cpp.cfg
Last active May 20, 2022 05:11
Uncrustify C/C++ config
# -------------------------------------------------------------------------------------------------#
# #
# _ _ _ _ __ ___ _____ _ _ __ _ #
# | | | |_ _ __ _ _ _ _ __| |_(_)/ _|_ _ / __| / / __|| |_ _| |_ __ ___ _ _ / _(_)__ _ #
# | |_| | ' \/ _| '_| || (_-< _| | _| || | | (__ / / (_|_ _|_ _| / _/ _ \ ' \| _| / _` | #
# \___/|_||_\__|_| \_,_/__/\__|_|_| \_, | \___/_/ \___||_| |_| \__\___/_||_|_| |_\__, | #
# |__/ |___/ #
# #
# -------------------------------------------------------------------------------------------------#
# #