Skip to content

Instantly share code, notes, and snippets.

View sepastian's full-sized avatar
💭
\_ . |‾‾‾| o-`o

Sebastian Gassner sepastian

💭
\_ . |‾‾‾| o-`o
View GitHub Profile
@sepastian
sepastian / quote_strings.sh
Created April 16, 2025 07:04
Quote a list of strings
# Given a comma-separated list of strings,
# quote each string separately in double-quotes
# for exampe, for using the list of strings in Python.
#
# Use sed to replace word boundaries (\b) with a quote character (").
head -1 some_csv_file.csv | sed -e 's|\b|"|g'
# head -1 topic_to_policy_llm_CORRECTED.csv
# topic_id,match,policy_field_flo,policy_field_llm,topic,source,policy_id_llm
@sepastian
sepastian / append_pdfs.sh
Created March 19, 2025 20:12
Append PDF files one by one
# Find PDFs, for example in sorted order,
# using https://gist.github.com/sepastian/5a39eb7aff7adcf2ba2460ca0738664a
find -type f -name '*pdf' | \
while read f
do
# Append file 2 ... N
if [ -f all.pdf ]; then
~/go/bin/pdfcpu merge -m append all.pdf "${f}"
continue
fi
@sepastian
sepastian / sort_by_german_month_names.sh
Last active November 30, 2024 09:41
Sort by German month names
# Use the `sort` command to sort by German month names.
#
# E.g. sort files containing month names in ther path.
# make sure desired locale is installed
$ localectl list-locales
C.UTF-8
en_US.UTF-8
# install missing locales, if required
@sepastian
sepastian / debian_laptop_networking_setup.md
Created November 7, 2024 07:50
Debian laptop networking setup

This guide describes how to setup networking under Debian Linux on a laptop. While there are many options to choose from, Debian 12 (bookworm) uses NetworkManager and wpa_supplicant as a default. This guide installs systemd-networkd and iwd, with the goal of controlling networking form the command line, using modern components.

The official Debian documentation lists various options and serves as a starting point.

NetworkManager → systemd-networkd

Replacing NetworkManager with systemd-networkd has been done following the official Debian docs and a great guide by Fernanto Cejas.

@sepastian
sepastian / .bashrc_venv
Last active November 7, 2024 10:00
Activate and deactivate venv automatically when changing directories in Bash.
# Activate Python venv when changing into directory containing .venv/bin/activate;
# deactivate Python venv when leaving directory containing .venv/bin/activate.
#
# Handle edge case, where presend and new directory contain .venv/bin/activate,
# i.e. switching from one venv into the next.
#
# This works for Bash only, place at the end of ~/.bashrc.
#
# Based on https://unix.stackexchange.com/a/170282
cd() {
@sepastian
sepastian / jq_select_by_missing_attribute.sh
Created September 17, 2024 06:30
jq: select objects missing a specific attribute
#!/bin/bash
set -euo pipefail
# Select all objects which do not contain an attribute named 'message'.
#
# Background: a log file contains messages from an application and
# numerous messages from Mongo db; the messages from Mongo contain
# an attribute called 'message', the application logs contain 'msg'
# instead. Filter the application logs only by selecting all objects
@sepastian
sepastian / dvgrab_ffmpeg.sh
Created March 3, 2024 17:20
Camcorder to digital video
# Grab video from a camcorder using dvgrap,
# convert to h.265 encoded video using ffmpeg.
#
# https://trac.ffmpeg.org/wiki/Encode/H.265
# https://regx.dgswa.com/html/content/dvgrab-ffmpeg-capture-compression
dvgrab --format dv1 --rewind - \
| ffmpeg -f dv -i - \
-vf yadif \
-c:v libx265 -crf 26 \
@sepastian
sepastian / DEPRECATED_pip_install_in_coderpad.py
Last active October 25, 2023 10:13
(DEPRECATED) Install any pip package in Coderpad
# DEPRECATED:
# In addition to running Python code, the coderpad console allows
# to pip install packages as well:
#
# >>> pip install sortedcontainers
#
# Using the code below is not required.
# It will be kept here for reference, as it shows how to access
# the Coderpad environment.
@sepastian
sepastian / main.cpp
Last active September 29, 2023 13:28
Multiple STL containers referencing same object in C++
#include <set>
#include <iostream>
#include <vector>
/*
* How to order a set<vector<A>::iterator>.
*/
struct A
{
@sepastian
sepastian / meson_ninja.sh
Created September 29, 2023 07:33
Building C++ with Meson and Ninja
# https://germandiagogomez.medium.com/getting-started-with-meson-build-system-and-c-83270f444bee
# Create project directory.
mkdir new_project
cd new_project
# Create source file.
echo "int main() {};" >> main.cpp
# Init meson, setup meson.