Skip to content

Instantly share code, notes, and snippets.

View frafra's full-sized avatar

Francesco Frassinelli frafra

View GitHub Profile
@frafra
frafra / example-cleanup.sh
Created November 14, 2021 23:32
Run a service in a specific time range using systemd
#!/bin/bash
for unit in test_python_stop.service test_python_{start,stop}.timer
do
systemctl --user stop $unit
systemctl --user disable $unit
done
systemctl --user stop test_python.service
rm -f \
~/.config/systemd/user/test_python.service \
@frafra
frafra / scan-network.sh
Last active May 28, 2021 23:05
Scan local network and show hostname, IP, MAC address, brand
#!/bin/sh
if (( $# != 1 )); then
>&2 echo "Usage: $0 NETWORK_INTERFACE"
exit 1
fi
sudo arp-scan -gx --localnet -I $1 |
awk '{
l=""
@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 / pg-join-generator.sql
Created January 27, 2021 18:32
Generate SQL join queries based on foreign keys
SELECT 'SELECT * FROM ' || src_table || ' JOIN ' || dst_table || ' ON (' ||
string_agg(src_table || '.' || src_column || ' = ' || dst_table || '.' || dst_column, ' AND ') || ')'
FROM (SELECT quote_ident(kcu.table_schema) || '.' || quote_ident(kcu.table_name) AS src_table,
quote_ident(rcu.table_schema) || '.' || quote_ident(rcu.table_name) AS dst_table,
quote_ident(kcu.column_name) AS src_column,
quote_ident(rcu.column_name) AS dst_column
FROM information_schema.referential_constraints rc
LEFT JOIN information_schema.key_column_usage kcu
USING (constraint_catalog, constraint_schema, constraint_name)
LEFT JOIN information_schema.key_column_usage rcu -- referenced columns
@frafra
frafra / bs-bashpatch.sh
Last active December 6, 2020 23:56
Trying to run BluOS-Controller on Linux
# replaced by: https://github.com/frafra/bs-bashpatch
@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
@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 / pyproject.toml
Created May 11, 2020 16:29
poetry-cookiecutter-bug
[tool.poetry]
name = "{{ cookiecutter.project_name }}"
version = "0.1.0"
description = ""
authors = ["Francesco Frassinelli <francesco.frassinelli@nina.no>"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
@frafra
frafra / consigli-per-animali.md
Created April 20, 2020 14:03
Divertirsi con le parole

Testo rilasciato sotto licenza Creative Commons Attribution 4.0, scritto da Francesco Frassinelli fraph24@gmail.com.

Consigli per animali a cui manca solo la parola

È di vitale importanza che le capre amanti del canto restino sopra le panche, anche se hanno una fame da lupi, per non finire a far compagnia alle gatte morte. I cani che abbaiano non facciano troppo i galli ed abbassino la cresta: se si scoprisse che non mordete finireste per fare la figura dei polli. Per le signore di una certa età è meglio fare le galline che le oche: almeno il brodo sarà buono. Se si è pesci meglio stare stretti come sardine che passare per dei tonni. È auspicabile che i molluschi non facciano gli asini con le volpi, evitando di dare le perle ai porci. I vermi lenti come lumache cerchino riparo sotto terra: una gallina potrebbe metterci il becco. I lupi solitari che non sono delle aquile potranno comuque fare la parte del leone se saranno testardi come dei muli, ma attenzione ai gufi porta sfortuna e alle sanguisughe opp

@frafra
frafra / example-extract-table-from-wikipedia.sh
Created February 26, 2020 13:02
Extract a table from Wikipedia (example)
#!/bin/bash -x
set -e
title="List_of_most-viewed_YouTube_channels"
host="en.wikipedia.org"
tmp="$title.$(date +'%Y%m%d').html"
cleanup() { rm -f "$tmp"; }
trap cleanup 0
curl -L "$host/api/rest_v1/page/mobile-sections/$title" |