Skip to content

Instantly share code, notes, and snippets.

View yookoala's full-sized avatar

Koala Yeung yookoala

  • Pixel Action Studio
  • Hong Kong
  • 14:50 (UTC +08:00)
View GitHub Profile
@yookoala
yookoala / README.md
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.

Method

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
yookoala / endpoint.php
Created May 31, 2023 10:26
A simple PHP API endpoint to process both JSON and POST formdata
<?php
$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
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
<?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
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
#
[Unit]
Description=Battery check. If higher than 80% or lower than 40%, notify desktop user
Wants=battery-level-check.timer
[Service]
Type=simple
@yookoala
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
yookoala / gameSave.php
Last active January 13, 2022 03:22
A simple Monogatari remote storage implementation
<?php
namespace Monogatari\RemoteStorage;
/**
* Throw this if a key is not found in a StorageInterface.
*/
class StorageKeyNotFound extends \Exception
{
/**
@yookoala
yookoala / 90-mac-superdrive.rules
Last active April 10, 2024 20:54
udev rules to use Apple SuperDrive on Linux
#
# Apple SuperDrive initialization rule
#
# See: https://gist.github.com/yookoala/818c1ff057e3d965980b7fd3bf8f77a6
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
yookoala / sendmail.php
Created October 28, 2021 03:10
A small script to be used as sendmail for debugging mailing functions in php.
<?php
/**
* @file
*
* Mock Sendmail
*
* A small script to be used as sendmail for debugging mailing functions in php.
*
* Usage:
@yookoala
yookoala / ABOUT_MULTIPART_UPLOAD.md
Last active December 9, 2020 15:48
An example to emulate an HTML form POST request with file uploads

Multipart Upload with PHP

About

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

Setup

@yookoala
yookoala / github-release.sh
Last active October 13, 2020 10:25
A script to create / append tagged release with any file as assets
#!/bin/bash
BASENAME=$(basename $0)
BASEPATH=$(dirname $(realpath $0))
# Print usage message
function usage {
cat <<EOF
usage: $BASENAME -k <GITHUB_API_TOKEN> -r <GITHUB_REPO_SLUG> -t <TAG> <DIST_PATH> <LABEL>