Skip to content

Instantly share code, notes, and snippets.

View x-magic's full-sized avatar
😀
Happy

Bill Haofei Gong x-magic

😀
Happy
View GitHub Profile
@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 <b@billgong.com>
*
* 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
@x-magic
x-magic / mailtodisk.php
Last active September 16, 2023 23:09
A script to imitate sendmail (to capture mails to be saved locally) for PHP using PHP
<?php
// To use this script, set
// sendmail_path = "/path/to/php /path/to/mailtodisk.php"
// in php.ini
// Set the mail redirect folder path
const MAILTODISK_ROOT = "/opt/mailtodisk/";
// Generate a date/time-based random file name
do {
@x-magic
x-magic / ikea_open_close_remote.yaml
Last active February 15, 2024 18:20 — forked from r3mcos3/ikea_open_close_remote.yaml
Home Assistant Blueprint For ZHA IKEA Open/Close Remote
blueprint:
name: IKEA Open/Close Remote
description: 'Control your roller blind with an IKEA 2 button square remote which comes with "Fytur" or " Kadrilj" roller blinds.'
domain: automation
input:
remote:
name: Remote
description: IKEA remote to use
selector:
device: