Skip to content

Instantly share code, notes, and snippets.

View frafra's full-sized avatar

Francesco Frassinelli frafra

View GitHub Profile
@frafra
frafra / look_for_value.sql
Created October 10, 2022 16:27
Look if any column contains such a value
create function pg_temp.look_for_value(value text) returns
table(table_fullname text, column_name text)
language plpgsql as $$
declare
r record;
found bool;
begin
for r in select * from information_schema.columns
loop
table_fullname = format('%I.%I.%I', r.table_catalog, r.table_schema, r.table_name);
@frafra
frafra / v4l2loopback_on_fedora_34.md
Last active August 28, 2022 16:33 — forked from kevineduardo/v4l2loopback_on_fedora_34.md
How to install (and compile) the latest v4l2loopback kernel module on Fedora Workstation 34

How to install (and compile) the latest v4l2loopback kernel module on Fedora Workstation 34

Execute the commands below

sudo dnf install git kernel-devel kernel-headers dkms v4l-utils
git clone https://github.com/umlaeute/v4l2loopback.git
cd v4l2loopback
make
v=$(./currentversion.sh)
@frafra
frafra / remove-files-from-git.md
Last active July 4, 2022 13:42
Remove files from git history

Did you forgot to add some rules into your .gitignore and committed some files by mistake? Here is how to fix that. Be aware that this procedure is going to overwrite the entire history of the project and your collaborators will have to clone the repository again.

Fix .gitignore files and commit

Fix your .gitignore files. You can have more than one, by placing them into different folders (useful for projects using different programming languages). Use https://gitignore.io to generate good defaults.

Remove ignored files and commit

@frafra
frafra / add-mitmproxy-cert.sh
Last active March 31, 2022 10:34
mitmproxy snippets and examples
#!/bin/bash -xeu
path="/usr/local/share/ca-certificates/mitmproxy"
mkdir -p "$path"
curl -x mitmproxy:8080 mitm.it/cert/pem > "$path/mitmproxy.crt"
# System
update-ca-certificates
# Java
#!/bin/bash
#
# Build a container with the required command and run it
set -euo pipefail
docker_like() {
if command -v podman &> /dev/null
then
podman "$@"
@frafra
frafra / find-dupes-dir.sh
Last active March 14, 2022 08:45
Find identical files and folders (comparing file names, paths and sizes)
#!/bin/bash
#
# Example:
# $ ./find-dupes-dir.sh $HOME/Documents/*/
set -Eeuo pipefail
declare -A dirs
for dir in "$@"
do
@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 / share-connection.sh
Last active April 13, 2021 13:32
Wifi connection over ethernet (Fedora setup)
export in_dev="eno1"
export out_dev="wlp0s20u7"
nmcli dev set ${in_dev} managed no
cat << EOF > /etc/dnsmasq.conf
# Only listen to routers' LAN NIC. Doing so opens up tcp/udp port 53 to
# localhost and udp port 67 to world:
interface=${in_dev}
# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with
@frafra
frafra / mbox2html.py
Last active February 17, 2021 16:34
Mailbox to HTML conversion using Python 3 + Jinja2 in less than 100 lines (including GPLv3 license)
#!/usr/bin/env python3
#
# Copyright (C) 2016 - Francesco Frassinelli
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,