Skip to content

Instantly share code, notes, and snippets.

@hleroy
hleroy / get_wifi_info.sh
Created December 5, 2023 08:30
Display WiFi status monitor script using Bash
#!/bin/bash
# The name of the wireless interface (e.g., wlp2s0). You may need to change this.
INTERFACE="wlp2s0"
# URL to check for internet connectivity
CHECK_URL="http://www.google.com"
# Function to check internet connectivity
check_internet() {
@hleroy
hleroy / nginx-syslog-geodata.json
Created January 29, 2022 11:31
This content pack supports the NGINX syslog feature and adds geo data based on MaxMind GeoLite2 Database.
{
"v": "1",
"id": "16d81e2a-796f-4c01-8906-13baf066dd1e",
"rev": 2,
"name": "Nginx-syslog-geodata",
"summary": "This content pack supports the NGINX syslog feature and adds geo data based on MaxMind GeoLite2 Database.",
"description": "This content pack includes:\n- a syslog UDP input listening on port 12501\n- an extractor to extract the JSON data from the syslog message\n- a pipeline rule to extract fields from `json_message`\n- a pipeline rule to lookup GeoIP data based on remote_addr",
"vendor": "Hervé Le Roy",
"url": "",
"parameters": [],
@hleroy
hleroy / cd_reminder.sh
Created January 2, 2022 19:24
Display reminders when cd-ing into directories containing a .cd-reminder file
# cd_reminder
# - Add bash excerpt below to your .bashrc or .bash_aliases
# - Restart your terminal or run `source .bashrc`
# - Add a file named `.cd-reminder` into a directory
# - `cd` into this directory: the content of `.cd-reminder` will be printed out
# Slightly modified version from https://unix.stackexchange.com/questions/18532/show-message-when-cd-into-specific-directory
# to allow printing ANSI colors
cd_reminder() {
builtin cd "$@" && { [ ! -f .cd-reminder ] || echo -ne $(cat .cd-reminder | sed 's/$/\\n/' | sed 's/ /\\a /g'); }
@hleroy
hleroy / case_insensitive_charfield.py
Created August 15, 2021 13:20
How to use Django 3.2 CreateCollation and db_collation to implement a case-insensitive Charfield with Postgres > 12
# According to Django documentation, it’s preferable to use non-deterministic collations
# instead of the citext extension for Postgres > 12.
# Example migation to create the case insensitive collation
class Migration(migrations.Migration):
operations = [
CreateCollation(
'case_insensitive',
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
check_mtu.py -- Check link MTU by sending UDP packets with increasing payload size
positional arguments:
host host to send packet to. If omitted, defaults to
www.google.com
optional arguments:
@hleroy
hleroy / compressVideoTo720p.desktop
Last active March 28, 2020 14:23
A KDE service menu to compress *.MOV files (e.g. taken from Canon 5d Mark II) to MP4 720p. Copy this script to one of the directory listed by `kf5-config --path services`
[Desktop Action compressVideo]
Exec=konsole --noclose -e HandBrakeCLI -i "%u" -t 1 --angle 1 -c 1 -o "`FILE="%u"; echo ${FILE%%.*}"_720p.MP4"`" -f m4v -O --decomb -w 1280 --loose-anamorphic --modulus 2 -e x264 -q 19 --vfr -a 1 -E faac -6 dpl2 -R 48 -B 128 -D 0 --gain 0 --audio-fallback ffac3 --x264-preset=placebo --x264-profile=high --x264-tune="film" --h264-level="4.1" --verbose=1
Icon=/home/hleroy/Images/Divers/Icones/handbrake-icon.png
Name=Conversion en MP4 720p
[Desktop Entry]
Actions=compressVideo;
MimeType=
ServiceTypes=
Type=Service
@hleroy
hleroy / keepRawForRatedPhotos.sh
Created May 13, 2018 21:03
This script will delete all Canon RAW (CR2) files in a folder when the corresponding JPG is unrated. The purpose is to keep only Raw files for photos which are worth it (assuming you have gone through the effort of rating the JPG). I'm using this script with Digikam in my photo workflow.
#!/bin/bash
#
# This script will delete all Canon RAW (CR2) files in a folder when the corresponding JPG is unrated.
# The purpose is to keep only Raw files for photos which are worth it
# (assuming you have gone through the effort of rating the JPG)
#
# It requires a filename as argument. It is meant to be called through a "context menu"
# (right-click) on a CR2 file.
#
# Example .desktop file for KDE (to be placed in ~/.local/share/applications/myRawCleaner.desktop)