Skip to content

Instantly share code, notes, and snippets.

@thomasfaingnaert
thomasfaingnaert / cmake-git-version.md
Created April 6, 2022 09:00
Using git version in cmake

Using git version in cmake

include/version.h.in

#define VERSION_STRING "@VERSION_STRING@"

cmake/generate_version.cmake

@thomasfaingnaert
thomasfaingnaert / fancy-git-diff.py
Last active June 3, 2022 02:56
Fancy git-diff output with syntax highlighting
#!/usr/bin/env python3
# Inspired by: https://gist.github.com/oprypin/9668969
import argparse
import pygments
import pygments.formatters
import pygments.lexers
import re
import sys
@thomasfaingnaert
thomasfaingnaert / onedrive-linux.md
Created March 24, 2021 16:52
Configure OneDrive in Linux
# Change this to the name of your account
ACCOUNT_NAME=Personal

###

CONTAINER_NAME="$(echo "onedrive-${ACCOUNT_NAME}" | tr '[:upper:]' '[:lower:]')"
VOLUME_NAME="${CONTAINER_NAME}-conf"
ONEDRIVE_DATA_DIR="${HOME}/OneDrive${ACCOUNT_NAME}"
@thomasfaingnaert
thomasfaingnaert / run-in-docker.sh
Created February 7, 2021 14:40
Run command in Docker
function run_in_docker()
{
docker run --rm -i -u "$(id -u):$(id -g)" $DOCKER_IMAGE bash -s
}
# Usage:
run_in_docker <<EOF || echo "Failed!"
set -e
echo "Do something in container..."
EOF
@thomasfaingnaert
thomasfaingnaert / visitor-tree-pretty-print.cpp
Last active February 10, 2021 15:08
Pretty print tree using Visitors
#include <cassert>
#include <cstdint>
#include <iostream>
#include <memory>
#include <sstream>
#include <utility>
#include <vector>
// Visited hierarchy
struct AstBase {
@thomasfaingnaert
thomasfaingnaert / vim-pairwise-diff.md
Last active February 2, 2021 13:11
Vim pairwise diff

Oneliner to diff a set of files pairwise in different tabs with Vim:

gvim -R -c 'for i in range(1, argc() - 1) | if i % 2 == 1 | rightbelow vertical diffsplit | next | diffthis | else | tabedit | next | endif | endfor' a b c d
@thomasfaingnaert
thomasfaingnaert / extract.md
Created February 23, 2020 16:53
Extract image from PDF for use in PowerPoint
  1. Open PDF in InkScape. Use Poppler/Cairo import.
  2. Ungroup all using CTRL + A and CTRL + SHIFT + G.
  3. Select what you want to keep and delete the rest using ! and DELETE.
  4. Autoresize the canvas using CTRL + SHIFT + R.
  5. Save as .EMF file.
@thomasfaingnaert
thomasfaingnaert / bash-control-lsp.sh
Last active July 5, 2019 10:30
Control LSP server from Bash
#!/usr/bin/env bash
send()
{
local length=${#1}
printf "Content-Length: $length\r\n" >pipe
printf '\r\n' >pipe
printf ${1//\\/\\\\} >pipe
}
@thomasfaingnaert
thomasfaingnaert / keep-named-pipe-open.sh
Last active July 5, 2019 09:54
Keep named pipe open
#!/usr/bin/env bash
mkfifo pipe # Created named pipe
program <pipe & # Start program
exec 3>pipe # Open file descriptor 3, writing to the named pipe
# Write to pipe using printf, echo, cat, ...
exec 3>&- # Close the named pipe (file descriptor 3)
@thomasfaingnaert
thomasfaingnaert / wrap-executable-wrap.md
Created July 5, 2019 09:19
Wrap executable and write stdout and stderr to file

Without timestamps:

#!/usr/bin/env bash

exec > >(tee -ai ~/app-stdout.log) 2> >(tee -ai ~/app-stderr.log >&2)
app $*

With timestamps (requires ts from moreutils):