Skip to content

Instantly share code, notes, and snippets.

@xuecan
xuecan / install.sh
Created September 7, 2020 13:35 — forked from chuyik/install.sh
Bandwagon(搬瓦工) CentOS 7 安装 shadowsocks-libev 和 kcptun
######################
## shadowsocks-libev
######################
# install dependencies
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
# install shadowsocks-libev
cd /etc/yum.repos.d/
@xuecan
xuecan / process_watcher.py
Created July 7, 2018 13:06
监控子进程的 stdout 和 stderr,触发 callback,支持同时监控多个子进程
# Copyright (c) 2018 Xue Can <xuecan@gmail.com>
"""
## 监控子进程输出的管理器
这个模块提供了一个进程输出的监视器,它使用 Popen 启动子进程并持续监控输出。只要子进程
输出是以行为基础的文本输出,就可以使用这个模块提供的监视器监控。特别的,如果需要监控的
是日志文件等,实际上是转化为 `tail -F` 来监视进程的。
最初,这个模块就是为了配合 `tail -F` 使用而编写的,后续发展到能够处理任何只输出,不需要通过
@xuecan
xuecan / gulp-modify-typescript-import.js
Created February 14, 2017 04:28
TypeScript 的 import 语句要求模块名称是字符串字面量(不能是模板、变量等),这个 gulp 插件用于修改 import 语句中的模块名
/*!
Copyright (C) 2015-2017 Xue Can <xuecan@gmail.com> and contributors.
Licensed under the MIT license: http://opensource.org/licenses/mit-license
*/
// TypeScript 的 import 语句要求模块名称是字符串字面量(不能是模板、变量等)
// 有时候我们需要根据当前文件名做一些相对的导入(通常结合 requirejs 插件)
// 这个 gulp 插件用于替换 import 语句中如下形式的字符串:
//
// - @@filename@@: 替换为文件名
@xuecan
xuecan / requirejs-css-plugin.js
Created February 14, 2017 01:21
A simple requirejs plugin for stylesheets injection.
/*!
Copyright (C) 2015-2017 Xue Can <xuecan@gmail.com> and contributors.
Licensed under the MIT license: http://opensource.org/licenses/mit-license
*/
// requirejs-css.js - A simple requirejs plugin for stylesheets injection.
define({
load: function (name, req, onload, config) {
if (!config.isBuild) {
var link = document.createElement("link");
<?php
/**
* @copyright Copyright (c) 2016, 北京联宇益通科技发展有限公司
*/
namespace Netpas\Common\SessionHandler;
use SessionHandlerInterface;
use Netpas\Exception\Exception;
@xuecan
xuecan / error_exception_handler.php
Created May 30, 2016 13:46
PHP 5 ErrorException Handler
/**
* 错误处理器
*
* 将 `E_USER_ERROR`、 `E_WARNING`、 `E_USER_WARNING` 和 `E_RECOVERABLE_ERROR`
* 错误转成 `\ErrorException` 异常抛出。其它类型的错误信息保留使用默认的错误处理机制。
*
* @throws \ErrorException 对于需要转换的错误,抛出异常
* @return bool 对于无需转换的错误,总是返回 false
*/
function handleErrorException($errno, $errstr, $errfile = __FILE__, $errline = __LINE__)
@xuecan
xuecan / Singleton.php
Created May 30, 2016 13:44
PHP Singletons
<?php
/**
* @copyright Copyright (C) 2006-2016 Xue Can <xuecan@gmail.com> and contributors.
*/
namespace Singleton;
/**
* Singleton Design Pattern
*
@xuecan
xuecan / DragTransform
Last active February 24, 2016 14:39 — forked from fta2012/DragTransform
Slightly modified compiled coffeescript from this codepen: http://codepen.io/fta/pen/ifnqH. Paste into console on a page that has jQuery to load the two dependent libraries (jquery-ui and numericjs). Then call makeTransformable('#selector-name') to make that element WYSIWYG editable. Use inspector to get the CSS for the transforms.
var selector = '#highlights' // Replace this with the selector for the element you want to make transformable
jQuery.getScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', function() {
jQuery.getScript('//cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js', function() {
(function() {
var $, applyTransform, getTransform, makeTransformable;
$ = jQuery;
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (c) 2015 Netpas Tech-Development Co. Ltd.
import shlex
import ipaddress
DIFF = 10 # 毫秒
DEFAULT_NETMASK = ipaddress.IPv4Address('255.255.255.0')
import os
def walk(r='.'):
for cd,_,fns in os.walk(r):
for fn in fns:
yield os.path.join(cd,fn)
def check(fn,enc='utf8'):
try:
with open(fn,'r',encoding=enc) as f: