Skip to content

Instantly share code, notes, and snippets.

View yookoala's full-sized avatar

Koala Yeung yookoala

  • Pixel Action Studio
  • Hong Kong
  • 22:55 (UTC +08:00)
View GitHub Profile
@yookoala
yookoala / swap.php
Created August 13, 2020 07:53
The simplest syntax to do swaping in PHP
<?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
yookoala / tick.spec
Last active April 17, 2020 03:10
SPEC for a general useless ticking service with systemd unit and overridable rpm macros
# 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
@yookoala
yookoala / highlevel_func.sh
Last active June 4, 2022 00:49
A set of functional-ish highlevel functions implemented in bash.
#!/bin/bash
# A collection of high-level-ish functions for
# bash pipeline operations.
# breakdown the output of ls or find into one
# item per line in STDOUT for pipeline.
#
# Usage:
# ls . | breakdown
@yookoala
yookoala / map.sh
Last active May 22, 2019 04:59
A snippet for more functional style bash scripts
#!/bin/bash
# map the data output from CLI tools like ls or find
# to execute action on each result.
#
# Example Usages:
# map <FUNCNAME or CLI COMMAND> "$(find ./some-folder -mindepth 1)"
# or
# find ./some-folder -mindepth 1 | map <FUNCNAME or CLI COMMAND>
#
@yookoala
yookoala / dump.php
Created May 21, 2019 10:44
A very efficient way to get mysql dump from remote PHP server.
<?php
// Note: Some authentication logics should be here!
// Setup enviroment
header('Content-Disposition: attachment; filename="backup.sql"');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('max_execution_time', 0); // disable execution time limit
error_reporting(E_ALL);
func merge(cs ...<-chan int) <-chan int {
out := make(chan int)
var cases []reflect.SelectCase
for _, c := range chans {
cases = append(cases, reflect.SelectCase{
Dir: reflect.SelectRecv,
Chan: reflect.ValueOf(c),
})
}
@yookoala
yookoala / composer.json
Last active November 17, 2018 01:45
HTMLPurifier add support to details and summary
{
"name": "yookoala/htmlpurifier-example",
"authors": [
{
"name": "Koala Yeung",
"email": "koalay at gmail dot com"
}
],
"require": {
"ezyang/htmlpurifier": "^4.10"
@yookoala
yookoala / Makefile
Last active November 9, 2018 16:54
PHP Translaion String Extraction with xgettext
all: messages.po
clean:
rm -f messages.po
.PHONY: all clean
messages.po:
xgettext \
--language=PHP \
@yookoala
yookoala / index.php
Created September 26, 2018 08:20
FormData javascript API test
<?php
/**
* A very simple test of FormData API with a very simple
* PHP backend.
*
* Usage:
*
* 1. Save this file to a folder.
* 2. Open your terminal and cd to this folder.
@yookoala
yookoala / http_parse_response_header.php
Created August 29, 2018 04:51
Parse the side effect variable $http_response_header of file_get_contents().
<?php
/**
* http_parse_response_header()
* Parse $http_response_header produced by file_get_contents().
*
* @param array $header
* Supposed $http_response_header or array alike.
* @param array
* Assoc array of the parsed version.