Skip to content

Instantly share code, notes, and snippets.

@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 / pihole-change-queries-number.bash
Last active February 3, 2024 04:10
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 / 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]
@mapi68
mapi68 / from_mac_address_to_ipv6.bash
Last active November 14, 2023 05:18
This Bash script prompts the user to input a MAC address and then converts it into an IPv6 address using a custom function
#!/bin/bash
tput clear
echo
echo "********************* Hello $USER! *********************"
echo
echo "Please paste MAC address that you want to convert into IPv6:"
read A
ipv6() {
IFS=':'; set $1; unset IFS
@mapi68
mapi68 / dns_to_ip.bash
Last active November 14, 2023 05:19
This Bash script prompts the user to input a DNS name, and then uses the dig command to retrieve and display the corresponding IP address
#!/bin/bash
tput clear
echo
echo "********************* Hello $USER! *********************"
echo
echo "Please paste DNS name that you want to convert into IP:"
read A
echo
echo "IP of $A is: `dig $A | awk '/^;; ANSWER SECTION:$/ { getline ; print $5 }'`"
@mapi68
mapi68 / wget_download_all.bash
Last active November 14, 2023 05:11
This Bash script utilizes the wget command to recursively download the contents of a specified folder while excluding unnecessary files
#!/bin/bash
tput clear
echo
echo "********************* Hello $USER! *********************"
echo
echo "Please paste link of folder that you want to download:"
read A
echo
wget -m -np -c --no-check-certificate -R "index.html*" $A
@mapi68
mapi68 / from_png_to_multiple_ico.py
Last active March 11, 2024 07:10
This Python script utilizes the Python Imaging Library (PIL) to create a multi-size icon file (icon.ico) from a source image (icon.png).
from PIL import Image
# Define dimensions for various icon images
sizes = [(16, 16), (32, 32), (48, 48), (256, 256)]
try:
# Open the source image (replace 'icon.png' with the path to your image file)
source_image = Image.open("icon.png")
# Check if the source image size is at least 256x256