Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Frassinelli frafra

View GitHub Profile
@frafra
frafra / add-mitmproxy-cert.sh
Last active Mar 31, 2022
mitmproxy snippets and examples
View add-mitmproxy-cert.sh
#!/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
@frafra
frafra / find-dupes-dir.sh
Last active Mar 14, 2022
Find identical files and folders (comparing file names, paths and sizes)
View find-dupes-dir.sh
#!/bin/bash
#
# Example:
# $ ./find-dupes-dir.sh $HOME/Documents/*/
set -Eeuo pipefail
declare -A dirs
for dir in "$@"
do
View run_in_container.sh
#!/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 / remove-files-from-git.md
Last active Jan 31, 2022
Remove files from git history
View remove-files-from-git.md

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 / example-cleanup.sh
Created Nov 14, 2021
Run a service in a specific time range using systemd
View example-cleanup.sh
#!/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 \
View docker-compose.yml
version: "3.4"
x-common-gss:
&default-common-gss
environment:
&default-common-env-gss
POSTGRES_USER: postgres
POSTGRES_PASSWORD: CHANGETHISPOSTGRESPASSWORD
deploy:
&default-common-deployment
replicas: 1
@frafra
frafra / scan-network.sh
Last active May 28, 2021
Scan local network and show hostname, IP, MAC address, brand
View scan-network.sh
#!/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 May 4, 2022
Good defaults for a Python project: Poetry + pre-commit + black + flakehell + isort
View .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
- repo: local
hooks:
@frafra
frafra / pg-join-generator.sql
Created Jan 27, 2021
Generate SQL join queries based on foreign keys
View pg-join-generator.sql
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 Dec 6, 2020
Trying to run BluOS-Controller on Linux
View bs-bashpatch.sh
# replaced by: https://github.com/frafra/bs-bashpatch