Skip to content

Instantly share code, notes, and snippets.

View yookoala's full-sized avatar

Koala Yeung yookoala

  • Pixel Action Studio
  • Hong Kong
  • 12:18 (UTC +08:00)
View GitHub Profile
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 / 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);
@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 / example.php
Last active June 16, 2019 15:25 — forked from hklcf/Screenshot via Google PageSpeed API
Screenshot via Google PageSpeed API
<?php
include_once 'getGooglePageSpeedScreenshot.php';
echo getGooglePageSpeedScreenshot($_GET['url']);
// Output: <img src="..." border="1" style="width: 80px; height: 80px" />
echo getGooglePageSpeedScreenshot($_GET['url'], [
'class' => 'thumbnail',
'style' => ['width: 80px;', 'height: 80px;']
@yookoala
yookoala / tick5.spec
Last active April 16, 2020 09:53
SPEC for tick5 with systemd unit.
# Some metadata required by an RPM package
Name: tick5
Summary: Print a message every 5s
Version: 0.1
Release: 1
License: MIT
%description
tick5 is a simple useless script that echos a message every 5 seconds.
@yookoala
yookoala / tick5.spec
Last active April 16, 2020 10:01
SPEC file refactored with macro
# Variables that might be modified by maintainer easily.
%define name tick5
%define version 0.1
%define release 1
%define systemdinstalldir /etc/systemd/system
%define message come on, James
# Some metadata required by an RPM package
Name: %name
Summary: Print a message every 5s
@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 / 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 / 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>
@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