Skip to content

Instantly share code, notes, and snippets.

View theharveyz's full-sized avatar
🕶️
NOOP

HarveyZ theharveyz

🕶️
NOOP
View GitHub Profile
@theharveyz
theharveyz / ES6-package-index.js
Last active September 1, 2016 10:18
ES6模拟package功能,导入一个文件夹下的所有module
import fs from 'fs';
import path from 'path';
const modules = {};
fs
.readdirSync(__dirname)
.filter((file) => {
const fileArray = file.split('.');
// 排除[隐藏文件]、[非js文件]、[index.js本身]
@theharveyz
theharveyz / clone.js
Last active March 8, 2017 18:39
clone一个对象
export const clone = (origin) => {
//Object.create 创建一个指定原型的对象,可选若干参数
return Object.assgin(Object.create(Object.getPrototypeOf(origin)), origin);
}
@theharveyz
theharveyz / http-status-message.php
Last active February 21, 2017 06:49
HTTP 状态码对应短语
return [
// INFORMATIONAL CODES
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
// SUCCESS CODES
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
@theharveyz
theharveyz / logrotate.conf
Last active March 6, 2017 18:48 — forked from simsicon/logrotate.conf
Helpful logrotate configuration
/var/log/app.log {
weekly
missingok
su root root # 切换到某个用户\组
create 0664 root utmp # 指定日志用户以及 模式
rotate 52
compress
delaycompress
notifempty
copytruncate
@theharveyz
theharveyz / syslog.php
Created December 5, 2016 17:55
php生成一个system log 日志
<?php
// open syslog, include the process ID and also send
// the log to standard error, and use a user defined
// logging mechanism
openlog("myScriptLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);
$access = date("Y/m/d H:i:s");
syslog(LOG_WARNING, "Unauthorized client: $access");
closelog();
@theharveyz
theharveyz / node_cluster_http_server.js
Last active December 6, 2016 07:24
使用cluster模块实现负载均衡,和多进程监听同一端口
import http from 'http';
import cluster from 'cluster';
import os from 'os';
const port = 3001;
// cpu核数
const numCpus = os.cpus().length;
console.log(`The num of cpu: ` + numCpus);
// 实现Load balancer
@theharveyz
theharveyz / php-stream-and-stream-filter-demo.php
Created December 13, 2016 17:56
php stream流操作相关知识点
<?php
/**
* stream解释: 将数据从开始位置传送到目的位置, 可以是大流量文件传输
* 1. stream的过程:
* 开始通信
* 读取数据
* 写入数据
* 结束通信
* ## 可以说stream是这一过程的抽象
*
# -*- coding: utf-8 -*-
class A(object):
def foo(self):
print 'hello A'
@classmethod
def demo(cls):
s = cls()
s.foo()
@theharveyz
theharveyz / decorator_test.py
Last active December 22, 2016 19:17
python decorator装饰器测试: 装饰器在代码加载时就会执行! 最简单的装饰器就是将函数直接返回(dummyDecorator)
# -*- coding: utf-8 -*-
def dummy_decorator(injection):
print 'dummy'
return injection
def test_decorator(injection):
print 'foooo'
def wrapper(params):
print 'barrrr'
@theharveyz
theharveyz / py.h.sublime-snippet
Created February 17, 2017 06:16
Sublime Text snippets
<snippet>
<content><![CDATA[
# -*- coding: utf-8 -*-
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>py.h</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>