Skip to content

Instantly share code, notes, and snippets.

@mapi68
mapi68 / ripristina_storia_git_mantieni_file.bash
Created May 11, 2025 05:18
Questo script reimposta la cronologia Git di un repository mantenendo i file correnti, quindi forza l'invio della cronologia pulita al repository remoto.
#!/bin/bash
# Pulisci lo schermo all'inizio
clear
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
LIGHT_BLUE='\033[94m'
BOLD='\033[1m'
@mapi68
mapi68 / reset_git_history_keep_files.bash
Created May 11, 2025 05:15
This script resets the Git history of a repository while keeping the current files, then force-pushes the clean history to the remote.
#!/bin/bash
# Clear the screen at the beginning
clear
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
LIGHT_BLUE='\033[94m'
BOLD='\033[1m'
@mapi68
mapi68 / pihole-change-queries-number_v6.bash
Created March 13, 2025 08:06
This script lets you customize Pi-hole query display numbers interactively.
#!/bin/bash
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m' # Brighter blue
LIGHTBLUE='\033[1;36m' # Light blue/cyan
CYAN='\033[0;36m'
BOLD='\033[1m'
@mapi68
mapi68 / pihole-change-queries-number_v5.bash
Created March 13, 2025 08:05
This script lets you customize Pi-hole query display numbers interactively.
#!/bin/bash
A="/var/www/html/admin/scripts/pi-hole/js/index.js"
valori() {
echo
sed -i 's/topItems/topItems='$f'/' $A
sed -i 's/getQuerySources\&topClientsBlocked/getQuerySources='$t'\&topClientsBlocked='$b'/' $A
echo "Now queries number are:"
@mapi68
mapi68 / json2m3u2tv.py
Created October 31, 2024 06:05
Python script to convert IPTV playlists from input.json to M3U and Enigma2 userbouquet TV formats, preserving channel groups and handling URL encoding.
import json
import urllib.parse
from pathlib import Path
class PlaylistConverter:
def __init__(self, json_file: str, name: str):
self.data = json.load(open(json_file, 'r', encoding='utf-8'))
self.name = name
self.filename = name.lower().replace(' ', '_')
@mapi68
mapi68 / raspeberry_upgrade_bullseye_to_bookworm.bash
Last active April 11, 2024 18:58
This script performs a full system upgrade for Raspberry Pi, migrating from Debian Bullseye to Bookworm, installs NetworkManager, removes dhcpcd, upgrades kernel and firmware, cleans unnecessary packages, and optionally configures NetworkManager with static or DHCP IP.
#!/bin/bash
clear
echo && echo Update package lists and upgrade packages
sudo apt update
sudo apt dist-upgrade -y
echo && echo Install NetworkManager without recommended packages
sudo apt install --no-install-recommends network-manager -y
@mapi68
mapi68 / character_line_counter.py
Last active March 11, 2024 07:29
This Python script reads and analyzes the content of 'text.txt,' counting characters and lines. If the file doesn't exist, user input is used.
import os
# Specify the file name
file_name = "text.txt"
# Check if the file exists
if os.path.exists(file_name):
# Read the content of the file with explicit encoding (e.g., 'utf-8')
with open(file_name, "r", encoding="utf-8") as file:
content = file.read()
@mapi68
mapi68 / update_pip_packages.py
Last active May 6, 2024 10:27
This Python script uses pip and the Python Package Index (PyPI) to identify outdated packages. It also offers the option to update them and cleans the pip cache.
import subprocess
import requests
def get_outdated_packages():
try:
print("Searching for outdated packages...")
# Execute the 'pip list --outdated' command to get the list of packages to update
outdated_packages = (
subprocess.check_output(["pip", "list", "--outdated"])
.decode()
@mapi68
mapi68 / unix_time_conversion.py
Last active May 6, 2024 10:28
This Python script provides functions for converting between Unix time and human-readable date-time format.
import arrow
def show_current_time():
current_time = arrow.utcnow()
formatted_current_time = current_time.format("YYYY-MM-DD HH:mm:ss")
unix_time = int(current_time.timestamp())
print(f"Current Time: {formatted_current_time}")
print(f"Unix Time: {unix_time}")
def convert_unix_time(unix_time):
@mapi68
mapi68 / flac_tag_rename.py
Last active May 6, 2024 10:29
This Python script provides a simple command-line interface to manipulate metadata tags in FLAC audio files within a specified directory.
import os
from mutagen import File
class AudioFile:
def __init__(self, file_path):
self.audio = File(file_path, easy=True)
def get_title(self):
return self.audio.get("title", [None])[0]