Skip to content

Instantly share code, notes, and snippets.

@newiep
newiep / Dispatcher.php
Created March 7, 2019 01:30
PHP 简易的事件系统
class Dispatcher
{
protected $listen = [
MEvent_TopicActivity::class => [
MListener_AddChristmasHat::class, //带圣诞帽
MListener_SendChristmasNotification::class, //发私信
],
];
protected $listeners = [];
@newiep
newiep / shadowsocks-libev-debian.sh
Last active May 10, 2022 17:51
卸载: ./shadowsocks-libev-debian.sh uninstall
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#===================================================================#
# System Required: Debian or Ubuntu #
# Description: Install Shadowsocks-libev server for Debian/Ubuntu #
# Author: Teddysun <[email protected]> #
# Thanks: @madeye <https://github.com/madeye> #
# Intro: https://teddysun.com/358.html #
#===================================================================#
/**
* 构建堆
*
* @param [type] $arr [description]
* @param [type] $start [description]
* @param [type] $len [description]
*
* @return [type] [description]
*/
function heapAdjust(&$arr, $start, $len)
/**
* 快速排序: 空间复杂度 O(1),时间复杂度 O(nlogn) 的实现
*/
function quickSort(&$arr, $head, $tail) {
if ($head >= $tail) {
return ;
}
@newiep
newiep / curl.md
Created July 29, 2017 06:18 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@newiep
newiep / weather.sh
Created February 16, 2017 04:34 — forked from taylorotwell/weather.sh
Weather CLI
alias weather='curl -s wttr.in | sed -n "1,7p"'
days = (month === 2) ? (28 + isLeapYear) : 31 - (month - 1) % 7 % 2;
@newiep
newiep / get_client_ip.php
Created November 29, 2016 06:04
get request client ip
function get_client_ip()
{
$keys = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
@newiep
newiep / pre_commit
Created November 29, 2016 06:03
phplint for pre_commit
#!/usr/bin/env zsh
# output notice msg if phplint is unavailable on the system
if whence phplint>/dev/null ; then
# git rev-parse --show-toplevel 显示项目根目录
phplint $(git rev-parse --show-toplevel) --exclude=system --exclude=doc --no-cache
# 发生错误直接退出,不继续提交
[ $? -ne 0 ] && exit 1
@newiep
newiep / progress_bar.php
Created November 29, 2016 06:01
progress bar
//显示进度条
function show_progressbar($current, $total)
{
//计算需要回退的字符长度
$len = strlen($current) + strlen($total) + 1;
// 回退 $len 字符,覆盖上一次 echo 输出
echo "\033[{$len}D";
$current .= "/{$total}"; // 15/100 进度显示
echo str_pad($current, $len, ' ', STR_PAD_LEFT);