Skip to content

Instantly share code, notes, and snippets.

View frafra's full-sized avatar

Francesco Frassinelli frafra

View GitHub Profile
@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 / 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" |
@frafra
frafra / restore-mediawiki-dump.sh
Last active November 10, 2019 12:03
Restore MediaWiki dump (example)
#!/bin/bash -ex
# https://dumps.wikimedia.org/backup-index.html
dump="https://dumps.wikimedia.org/nowiktionary/20191101/nowiktionary-20191101-pages-articles-multistream.xml.bz2"
# https://www.mediawiki.org/wiki/Extension:Scribunto
scribunto="https://extdist.wmflabs.org/dist/extensions/Scribunto-REL1_33-8328acb.tar.gz"
pod="wiktionary"
mysql=$(podman volume create)
@frafra
frafra / stubby-onoff.sh
Last active October 22, 2019 20:25
Enable/Disable DNS-over-TLS on Fedora
#!/bin/bash
# mkdir -p $HOME/bin && cd $_ && wget https://gist.githubusercontent.com/frafra/a1ca3d5eff81e6c6aebd8fab12b00695/raw/stubby-onoff.sh -O stubby-onoff && chmod +x $_ && cd -
set -ex
[ $USER == "root" ] || exec sudo $0
pkgs="getdns-stubby crudini"
rpm -q $pkgs || dnf install -y $pkgs
conf=/etc/NetworkManager/NetworkManager.conf
@frafra
frafra / chromecast-and-linux.md
Last active September 22, 2019 11:16
Tricks to use Chromecast on GNU/Linux systems

No weird or unmaintained softwares or libraries are involved in this guide, just VLC, Avahi and youtube-dl.

VLC + Chromecast

VLC supports Chromecast since version 3.0.0 (2018-02-09). Just go to Playback -> Renderer.

vlc --sout "#chromecast" --sout-chromecast-ip=$IP --demux-filter=demux_chromecast "$input"
@frafra
frafra / ls-contributed-to.sh
Created January 21, 2019 14:03
Like `ls -1` but marks path modified by a specific author or a company
#!/bin/bash
#regex="@nina.no$"
regex="$1"
function check {
git log --format="%ae" "$1" | grep -q "$regex"
}
check '.' && echo " * ." || echo " ."
@frafra
frafra / poliadventures-17december.md
Last active November 16, 2018 08:08
Quests - December 2017 #PoliMappersAdventures

Quests - December 2017 #PoliMappersAdventures

  1. Learn something you didn't know about OpenStreetMap https://learnosm.org/
  2. Install StreetComplete (for Android) or Go Maps (for iOS) https://github.com/westnordost/StreetComplete#download or https://itunes.apple.com/app/id592990211
  3. Map a bench https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dbench
  4. Find a bench and add the backrest tag https://wiki.openstreetmap.org/wiki/Key:backrest
  5. Map a picnic table https://wiki.openstreetmap.org/wiki/Tag:leisure%3Dpicnic_table
  6. Find a bench or a picnic table and add the material tag https://wiki.openstreetmap.org/wiki/Key:material
  7. Map a trash bin (unsorted waste only) https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dwaste_basket
  8. Map a container for recycling of used goods https://wiki.openstreetmap.org/wiki/Tag:amenity%3Drecycling