Skip to content

Instantly share code, notes, and snippets.

View yookoala's full-sized avatar

Koala Yeung yookoala

  • Pixel Action Studio
  • Hong Kong
  • 05:51 (UTC +08:00)
View GitHub Profile
yookoala /
Last active March 28, 2024 05:43
Testing concurrent write to golang net.Conn on unix socket

Concurrent Writing of net.Conn over socket

These files are for testing golang's concurrent writing to the same connection (net.Conn), specifically through a unix socket. To see if concurrent use of net.Conn would lead to contemination of data beting sent.


The file client.go will is program to send multiple data stream of repeated characters to the unix socket "./echo.sock". The number of streams is declared by the arguments of the client.go

yookoala / endpoint.php
Created May 31, 2023 10:26
A simple PHP API endpoint to process both JSON and POST formdata
$method = $_SERVER['REQUEST_METHOD'] ?? null;
if ($method === 'POST') {
$content_type = preg_match('/^(.+?); (.+?)$/', $_SERVER['HTTP_CONTENT_TYPE'] ?? '', $matches)
? $matches[1]
: ($_SERVER['HTTP_CONTENT_TYPE'] ?? null);
// Parse input data by content type
$input = file_get_contents('php://input');
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
* 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
# 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
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
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 May 9, 2024 13:45
udev rules to use Apple SuperDrive on Linux
# 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.
* @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