Skip to content

Instantly share code, notes, and snippets.


Koala Yeung yookoala

  • Pixel Action Studio
  • Hong Kong
View GitHub Profile
yookoala / extract-head-and-body.php
Last active May 23, 2022 06:47
A short script to extract the head and body contents from an HTML file to reformat it
View extract-head-and-body.php
* Extract HTML children of a give tag name from a given document.
* @param \DOMDocument $doc The DOM document to extract from.
* @param string $tagName The tag name for extraction (e.g. 'head', 'body')
* @return \DOMDocument An DOMElement containing all child elements from the tag specified in $dom.
yookoala / battery-level-check.service
Last active April 7, 2022 07:48
Battery level checking service
View battery-level-check.service
# Save this file as: /etc/systemd/system/battery-level-check.service
Description=Battery check. If higher than 80% or lower than 40%, notify desktop user
yookoala / static-method-demo.js
Created February 17, 2022 07:44
A ES6 demonstration of how to call static method in non-static class method
View static-method-demo.js
class DummyParent {
static hello() {
console.log('dummy parent say hello')
class Dummy extends DummyParent {
static foo() {
console.log('dummy say foo')
yookoala / gameSave.php
Last active January 13, 2022 03:22
A simple Monogatari remote storage implementation
View gameSave.php
namespace Monogatari\RemoteStorage;
* Throw this if a key is not found in a StorageInterface.
class StorageKeyNotFound extends \Exception
yookoala / 90-mac-superdrive.rules
Last active March 28, 2023 03:46
udev rules to use Apple SuperDrive on Linux
View 90-mac-superdrive.rules
# Apple SuperDrive initialization rule
# See:
ACTION=="add", ATTRS{idProduct}=="1500", ATTRS{idVendor}=="05ac", DRIVERS=="usb", RUN+="/usr/bin/sg_raw %r/sr%n EA 00 00 00 00 00 01"
yookoala / sendmail.php
Created October 28, 2021 03:10
A small script to be used as sendmail for debugging mailing functions in php.
View sendmail.php
* @file
* Mock Sendmail
* A small script to be used as sendmail for debugging mailing functions in php.
* Usage:
yookoala /
Last active December 9, 2020 15:48
An example to emulate an HTML form POST request with file uploads

Multipart Upload with PHP


This is a simple example to do a "multipart/form-data" POST request in PHP without any fancy library.


yookoala /
Last active October 13, 2020 10:25
A script to create / append tagged release with any file as assets
BASENAME=$(basename $0)
BASEPATH=$(dirname $(realpath $0))
# Print usage message
function usage {
cat <<EOF
yookoala / swap.php
Created August 13, 2020 07:53
The simplest syntax to do swaping in PHP
View swap.php
* This works.
$a = 1; $b = 2;
echo "Before swap: {$a}, {$b}\n";
list($a, $b) = [$b, $a];
echo "After swap: {$a}, {$b}\n";
yookoala / tick.spec
Last active April 17, 2020 03:10
SPEC for a general useless ticking service with systemd unit and overridable rpm macros
View tick.spec
# Variables that can be override on build time.
%{!?sleep: %define sleep 5}
%{!?name: %define name tick%{sleep}}
%{!?version: %define version 0.0}
%{!?release: %define release 1}
%{!?systemdinstalldir: %define systemdinstalldir /etc/systemd/system}
%{!?message: %define message come on, James}
# Some metadata required by an RPM package
Name: %name