Skip to content

Instantly share code, notes, and snippets.

View frafra's full-sized avatar

Francesco Frassinelli frafra

View GitHub Profile
@frafra
frafra / .gitlab-ci.yml
Created November 6, 2020 15:46
Build containers with GitLab CI without root nor daemons by using buildkit
build-container:
stage: build
image:
name: moby/buildkit:rootless
entrypoint: [ "sh", "-c" ]
variables:
BUILDKITD_FLAGS: --oci-worker-no-process-sandbox
before_script:
- |
mkdir ~/.docker

systemd containers

Assumptions

This how-to uses mybox as container name, mkosi in order to create containers (it works for multiple distributions and has more features compared to dnf --installroot), and crudini for configurations file (you can use your preferred text editor instead).

How to create a container with mkosi

# mkosi --cache /var/cache/mkosi -d fedora -t directory -o /var/lib/machines/mybox
@frafra
frafra / .pre-commit-config.yaml
Last active November 30, 2023 03:36
Good defaults for a Python project: Poetry + pre-commit + black + flakehell + isort
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- repo: local
hooks:
@frafra
frafra / cheap-vps.md
Last active November 28, 2023 09:24
cheap-vps

VPS cheaper than 5 €/month

Famous/big companies

Linode

Current status (October 2020): better avoid

Starting from 5 $/month.

@frafra
frafra / default.vcl
Created November 16, 2023 21:04
Allow GDAL vsicurl to fetch streamed replies and caching
vcl 4.1;
import dynamic;
backend default none;
sub vcl_init {
new d = dynamic.director(port = "80");
}
sub vcl_recv {
@frafra
frafra / zotero.js
Created August 21, 2023 12:22
zotero cookbook
// Add incremental Call Number
let items = Zotero.getActiveZoteroPane().getSelectedItems();
let callNumberLength = items.length.toString().length;
for (i=0; i<items.length; i++) {
let item = items[i];
if (!items[i].isRegularItem()) continue;
item.setField("callNumber", (i+1).toString().padStart(callNumberLength, "0"));
await item.saveTx();
}
@frafra
frafra / kroki.js
Last active April 25, 2023 14:12
Render with mermaid and kroki, with support for mdbook
// <script type="module">
var server = "https://kroki.io";
var libraries = [
"bytefield",
"c4plantuml",
"d2",
"ditaa",
"erd",
"graphviz",
"dot",
@frafra
frafra / fix.md
Last active April 20, 2023 20:25
USB C headphones sound distorsion fix for Linux

Affected devices

  • Bowers & Wilkins PX7 19b5:0025 B & W Group
  • Dali IO-6 0a12:0001 Cambridge Silicon Radio

Fix

The best way to fix that is to use PipeWire, since it allows to set rules for a specific device only, instead of having to change the sampling rate of the whole audio system.

PipeWire

@frafra
frafra / 05-batman
Last active February 10, 2023 08:44
NetworkManager integration with batman-adv
#!/bin/sh
#
# /etc/NetworkManager/dispatcher.d/05-batman
ESSID="Igloo mesh"
IFACE="wlp2s0"
ADDR="01:23:45:67:89:AB"
function current {
nmcli -t -f GENERAL.CONNECTION d show $IFACE | cut -d\: -f2
@frafra
frafra / functions.sh
Created February 8, 2023 08:14
debug tricks
function read_strace_file() {
strace --trace=file "$@" |&
sed --quiet 's;.*"\(/[^"]*\)".*;\1;p' |
sort --unique |
fzf --scheme=path |
xargs --no-run-if-empty less
}
export read_strace_file