Skip to content

Instantly share code, notes, and snippets.

View gsdefender's full-sized avatar
💭
I may be slow to respond.

Emanuele Cipolla gsdefender

💭
I may be slow to respond.
View GitHub Profile
@gsdefender
gsdefender / restore-proxmox-vm.sh
Last active July 6, 2023 20:00
Restore Proxmox VM backup to another server
#!/bin/bash
# usage: ./restore-proxmox-vm backup.zst local:111 newlocal
tempdir=$(mktemp -d -u) # do not create directory or vma extract will fail
if [ -f "$1" ]; then zstd -d "$1"; fi
vma extract "$(basename $1 .zst)" "$tempdir"
vmid=$(($(ls -1 /etc/pve/qemu-server/*.conf | tr '\n' '\0' | xargs -0 -n 1 basename | sed -e 's:\.conf::g' | sort -n | tail -1)+1))
mv "$tempdir/qemu-server.conf" /etc/pve/qemu-server/$vmid.conf
newdisk="$3:$vmid"
sed -i -e "s:$2:$newdisk:g" /etc/pve/qemu-server/$vmid.conf
mkdir -p "$3/images/$vmid"
@gsdefender
gsdefender / get-latest-moodle.sh
Last active April 23, 2023 14:22
Download and install latest Moodle
#!/bin/bash
# replace with latest moodle directory and filename from moodle.org
DIRECTORY="stable401"
FILENAME="moodle-4.1.1.tgz"
URL="https://download.moodle.org/download.php/direct/$DIRECTORY/$FILENAME"
pushd
rm -f moodle-latest.tgz
wget "$URL" -O moodle-latest.tgz
@gsdefender
gsdefender / unbound-adhosts.sh
Created February 15, 2021 00:39
Unbound 8 blocked hosts downloader
#!/bin/ksh
#
# Using blacklist from pi-hole project https://github.com/pi-hole/
# to enable AD blocking in unbound(8)
#
# src: https://www.tumfatig.net/20190405/blocking-ads-using-unbound8-on-openbsd/
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# Available blocklists - comment line to disable blocklist
_disconad="https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt"
@gsdefender
gsdefender / kodi.service
Created February 10, 2021 00:13
Kodi systemd service
[Unit]
Description = Kodi Media Center
# if you don't need the MySQL DB backend, this should be sufficient
After = systemd-user-sessions.service network.target sound.target
# if you need the MySQL DB backend, use this block instead of the previous
# After = systemd-user-sessions.service network.target sound.target mysql.service
# Wants = mysql.service
@gsdefender
gsdefender / better-rc-local.service
Created February 10, 2021 00:11
rc.local for systemd-based distro
# Put this file in /etc/systemd/system
[Unit]
Description=A better rc.local-service
[Service]
Type=idle
ExecStart=/etc/rc.local.better
[Install]
WantedBy=network.target
//WooCommerce Email Customizations
add_filter( 'woocommerce_email_recipient_customer_note', array( $this, 'fka_parent_email_recipient_filter_function' ), 10, 2);
add_filter( 'woocommerce_email_recipient_customer_completed_order', array( $this, 'fka_parent_email_recipient_filter_function' ), 10, 2);
add_filter( 'woocommerce_email_recipient_customer_invoice', array( $this, 'fka_parent_email_recipient_filter_function' ), 10, 2);
add_filter( 'woocommerce_email_recipient_customer_processing_order', array( $this, 'fka_parent_email_recipient_filter_function' ), 10, 2);
/**
* $recipient could be comma separated to send to additional people
* EX. $recipient .= ', $additonal_recipient';
*/
Search for : (.*(\n|$)){2}
alt+R - to toggle regular expression search
alt+ENTER - to select all results
@gsdefender
gsdefender / blocklist2dnsmasq.py
Last active August 25, 2020 10:58
Create dnsmasq blocklist configuration file out of a hosts file
#!/usr/bin/env python
# For blocklists see https://github.com/blocklistproject/lists/wiki/
import sys
with open(sys.argv[1], 'r') as blocklist_hosts_file, open(sys.argv[2], 'w+') as blocklist_dnsmasq_file:
for line in blocklist_hosts_file:
if not line.startswith('#'):
line = line.strip()
@gsdefender
gsdefender / QCacheGrind-install.sh
Last active November 4, 2018 21:31 — forked from RichVRed/install.sh
Install QCacheGrind on Ubuntu
#!/bin/bash
# Build against Qt 4
sudo apt-get install qt4-default
# Build against Qt 5
#sudo apt-get install qt5-default
wget http://kcachegrind.sourceforge.net/kcachegrind-0.7.4.tar.gz
tar xvf kcachegrind-0.7.4.tar.gz
cd kcachegrind-0.7.4
# If building against Qt 5, uncomment lines 12-16:
@gsdefender
gsdefender / compress_pdf
Created June 22, 2017 17:37
A way to reduce the size of PDF sizes
#!/usr/bin/env bash
# $3 must be one of: screen, ebook, printer, prepress, from lower to higher quality
# h/t: https://www.techwalla.com/articles/reduce-pdf-file-size-linux
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/$3" -sOutputFile="$2" "$1"