Skip to content

Instantly share code, notes, and snippets.

View x-magic's full-sized avatar
🙂
Smiling

Bill Haofei Gong x-magic

🙂
Smiling
View GitHub Profile
@x-magic
x-magic / proxmox_pushover_webhook.md
Created February 23, 2025 15:09
Setup Pushover notification for Proxmox via webhook

To setup Pushover.net notification in Proxmox VE, go to:
Datacenter -> Notifications -> Notification Targets -> Add -> Webhook

Set up the following fields:

  • Endpoint Name: pushover (or whatever you want, note the character limitation)
  • Method/URL: POST, https://api.pushover.net/1/messages.json
  • Headers: Add one set of key-value pairs:
    • Content-Type -> application/json
  • Body:: See pushover_proxmox-notification-webhook.json file below
  • Secrets: Add two sets of key-value pairs:
@x-magic
x-magic / macos_perapp_fullscreen_menubar.sh
Created December 15, 2024 08:57
Change the full-screen menu bar visibility on a per-app-basis on macOS
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Change the full-screen menu bar visibility on a per-app-basis on macOS"
echo "Usage: $0 APP_NAME [show|hide|revert]"
echo -e "\nPlease provide the name of the application to continue."
exit 1
else
# Get the app ID first
APP_ID=$(osascript -e "id of app \"$1\"" 2> /dev/null)
@x-magic
x-magic / nologo_rp2040_usb_16mb.h
Last active June 19, 2024 03:04
Pico SDK board definition for 无名科技 Nologo RP2040 USB 4MB/16MB
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
* Copyright (c) 2024 Bill Gong <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
//------------------------------------------------------------------------------------------
// Board definition for the NoLogo RP2040 USB 16MB
@x-magic
x-magic / alive.php
Created May 18, 2024 16:40
A simple call-home alive check script based on server-side PHP and client-side curl/cron
<?php
/**
* A simple call-home alive check script based on server-side PHP and client-side curl/cron
*/
error_reporting(0);
ini_set('display_errors', 0);
date_default_timezone_set('Australia/Melbourne');
header('Content-Type: text/plain');
# Originally from: https://github.com/bbcontrol/ha-snippets/blob/main/blueprints/single_button_dim_switch.yaml
blueprint:
name: Single Button Dim Switch
description: >-
Switch a light on/off by pressing a button.
Dim it up/down (depending on the current state) by holding the same button.
domain: automation
input:
button:
name: Push button
@x-magic
x-magic / 01-fan_control_cron.sh
Last active July 2, 2024 10:07
UDM-SE: Adjust fan speed based on harddrive temperature
#!/bin/bash
# Create the HDD temperature script
cat > /tmp/zz-hddtemp.sh <<- "EOF"
#!/bin/bash
# PWM1 (HDD) related Variables
PWM1TEMP=$(/usr/sbin/hddtemp /dev/sdb | awk -F ": " '{print $3}' | grep -Po '\d+')
PWM1TEMPMAX=55
PWM1TEMPMIN=40
@x-magic
x-magic / aria2-rpc-block.php
Last active January 20, 2024 09:58
Ban certain bittorrent clients on Aria2 with fail2ban
<?php
/*
* To block certain client when downloading and seeding with Aria2
*
* This will be triggered by CRON and write logs to a log file, where
* fail2ban will pick up and block the client
*
* Also probably run on PHP 8.x? I tested on PHP 8.2
*
* Remember to setup logrotate otherwise there will be too many logs!
@x-magic
x-magic / uckg2p_ssdlife.sh
Created January 6, 2024 07:07
Script to show SSD lifespan information on a UniFi Cloud Key Gen2 Plus (over SSH)
#!/bin/bash
# Set up the target drive path and the number of LBA (I know this can be read from SMART...)
TARGETDRIVE="/dev/sda"
LBAS="7814037168"
# In case a different drive shall be selected
#read -rep $'Which drive to check? [/dev/sda]\n' USERTARGETDRIVE
#if [[ $USERTARGETDRIVE ]]; then
# TARGETDRIVE=$USERTARGETDRIVE
@x-magic
x-magic / 00-create_local_dns_conf.sh
Created December 29, 2023 02:34
UDM-SE: Boot script to add custom DNS records in dnsmasq
#!/bin/sh
# We'll plug the overriding configurations into /run/dnsmasq.conf.d/
cat > /run/dnsmasq.conf.d/local_custom_dns.conf <<- 'EOF'
# Add an A record to a specific server (i.e. override)
address=/double-click.net/127.0.0.1
# Or a SRV record, if needed
srv-host=_ldap._tcp.example.com,ldapserver.example.com,389
# You can even add MX records as you wish
mx-host=maildomain.com,servermachine.com,50
@x-magic
x-magic / mariadb_tzdata.md
Last active October 8, 2023 12:54 — forked from brianburridge/gist:11298396
How to load MySQL/MariaDB time zone tables from macOS tzdata files

The easiest way to load the MySQL Time Zone tables from your macOS tzdata is via this command:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Once the file is imported, you'll need to restart MySQL or MariaDB:

# Determine if you have MySQL or MariaDB
brew list