Skip to content

Instantly share code, notes, and snippets.

View jfcherng's full-sized avatar
🦀
Yes, that should work.

Jack Cherng jfcherng

🦀
Yes, that should work.
View GitHub Profile
@jfcherng
jfcherng / recursive_glob.php
Last active August 29, 2015 14:25
Recursive glob() for PHP 5.
function recuresive_glob ($dir, $regex) {
$dirIt = new RecursiveDirectoryIterator($dir);
$itIt = new RecursiveIteratorIterator($dirIt);
$files = new RegexIterator($itIt, $regex, RegexIterator::GET_MATCH);
$fileList = array();
foreach ($files as $file) {
$fileList[] = $file[0];
}
return $fileList;
}
@jfcherng
jfcherng / trap_1.php
Last active October 12, 2017 07:27
PHP Reference Trap
<?php
$foo = [];
$foo['love'] = 1;
$bar = &$foo['love']; // no harm, huh?
$tipi = $foo;
$tipi['love'] = 2;
@jfcherng
jfcherng / LunarCalendar.php
Last active January 11, 2024 09:27
PHP 農曆相關
<?php
class Lunar
{
const MIN_YEAR = 1891;
const MAX_YEAR = 2100;
const LUNAR_INFO = [
[0, 2, 9, 21936], [6, 1, 30, 9656], [0, 2, 17, 9584], [0, 2, 6, 21168], [5, 1, 26, 43344], [0, 2, 13, 59728],
[0, 2, 2, 27296], [3, 1, 22, 44368], [0, 2, 10, 43856], [8, 1, 30, 19304], [0, 2, 19, 19168], [0, 2, 8, 42352],
@jfcherng
jfcherng / git-auto-sign-commits.sh
Created July 25, 2018 11:37 — forked from mort3za/git-auto-sign-commits.sh
Auto sign your git commits
# generate a new pgp key: (better to use gpg2 instead of gpg)
gpg --gen-key
# maybe you need some random work in your OS to generate a key. so run this command: `find ./* /home/username -type d | xargs grep some_random_string > /dev/null`
# check current keys:
gpg --list-secret-keys --keyid-format LONG
# export private key in gpg:
gpg --export-secret-key -a "your_username"
<?php
declare(strict_types=1);
class IntEncoder
{
/**
* @var string all unreserved chars in URI
*
* @see https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_in_a_URI
@jfcherng
jfcherng / rsync.sh
Created June 4, 2019 19:21
rsync ssh example
#!/usr/bin/env bash
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:${PATH}
SERVER_IP="0.0.0.0"
SERVER_PORT="22"
SYNC_DIRS=(
# MySQL
"/usr/local/mysql/bin"
@jfcherng
jfcherng / gd-lib-test.php
Last active June 16, 2019 10:24
Check PHP GD library support
<?php
// Displays details of GD support on your server
echo '<div style="margin: 10px;">';
echo '<p style="color: #444444; font-size: 130%;">GD is ';
if (\function_exists('gd_info')) {
echo '<span style="color: #00AA00; font-weight: bold;">supported</span> by your server!</p>';
@jfcherng
jfcherng / Python3.7-Build.txt
Last active January 1, 2022 18:12 — forked from nesffer/Python3.5-Build.txt
Python 3.7 Build on Ubuntu 16.04
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 _ssl _tkinter
readline zlib _uuid
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
sudo apt install libbz2-dev libncurses5-dev libgdbm-dev liblzma-dev sqlite3 libsqlite3-dev openssl libssl-dev tcl8.6-dev tk8.6-dev libreadline-dev zlib1g-dev uuid-dev
@jfcherng
jfcherng / ChtStroke.php
Last active December 15, 2020 08:26 — forked from blackbing/big5_stroke.tab
中文筆劃排序(只適用繁體中文) for PHP 7.2
<?php
/**
* Author: blackbing@gmail.com
* Desc: 為了解決中文筆劃排序的問題(只適用繁體中文)
* php 可以直接執行 cht_strokesort.
*/
final class ChtStroke
{
const BIG5_HB_MIN = 0x81; // 高位元組最小值
@jfcherng
jfcherng / regex-expand.py
Created August 5, 2019 05:14
Expand compacted regex expression
import functools
import os
import re
import sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
# https://github.com/asciimoo/exrex
import exrex