Skip to content

Instantly share code, notes, and snippets.

View inhere's full-sized avatar
😃
working, learning ...

Inhere inhere

😃
working, learning ...
View GitHub Profile
@inhere
inhere / websocket-nginx.conf
Created April 28, 2018 05:32
Nginx configuration for websocket server
upstream io_nodes {
ip_hash;
server 127.0.0.1:6001;
server 127.0.0.1:6002;
server 127.0.0.1:6003;
server 127.0.0.1:6004;
}
server {
listen 3000;
@inhere
inhere / compare_speed.php
Last active April 26, 2018 15:03
比较两个不同的php语句或者函数的执行速度
<?php
function compare_speed(callable $sample1, callable $sample2, int $times = 1000, array $args = [])
{
if ($times < 1000) {
$times = 1000;
}
$start1 = microtime(1);
@inhere
inhere / method1.js
Last active April 17, 2018 09:01
js 时间转换到日期
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
@inhere
inhere / swoole-nginx.conf
Created March 7, 2018 04:00
swoole 应用的nginx配置参考
server {
listen 80;
server_name www.site.dev site.dev;
root /webroot/static;
index index.html index.htm;
error_log logs/site.dev.error.log;
access_log logs/site.dev.access.log;
##### 第一个必选规则: 匹配首页
@inhere
inhere / php-project.Makefile
Last active July 6, 2019 03:11
Makefile ref for php project
# link https://github.com/humbug/box/blob/master/Makefile
#SHELL = /bin/sh
.DEFAULT_GOAL := help
# 每行命令之前必须有一个tab键。如果想用其他键,可以用内置变量.RECIPEPREFIX 声明
# mac 下这条声明 没起作用 !!
.RECIPEPREFIX = >
.PHONY: all usage help clean
# 需要注意的是,每行命令在一个单独的shell中执行。这些Shell之间没有继承关系。
# - 解决办法是将两行命令写在一行,中间用分号分隔。
@inhere
inhere / composer.scripts.json
Created January 23, 2018 01:32
the scripts config for composer
"scripts": {
"analyze": [
"@cs:check",
"@phpstan",
"@composer validate --strict"
],
"phpstan": [
"wget -nc https://github.com/phpstan/phpstan/releases/download/0.9.1/phpstan.phar",
"chmod a+x phpstan.phar",
"./phpstan.phar analyse src tests --level=2 -c phpstan.neon --no-interaction --no-progress"
@inhere
inhere / example
Last active January 11, 2018 03:57
简单快速给文档生成TOC(使用jQuery, 自动生成锚点,可添加 anchorIcon)
<style>
[data-anchor-icon]::after {
content: attr(data-anchor-icon);
}
</style>
<div id="content-toc-box">
<div class="title"><i class="fa fa-list"></i> 内容结构</div>
<div id="content-toc"></div>
</div>
@inhere
inhere / send_request_by_fetch.js
Created January 11, 2018 03:50
通过新的 fetch 方法发送 ajax 请求
const baseUrl = 'xx.com/'
export default async(url = '', data = {}, type = 'GET', method = 'fetch') => {
type = type.toUpperCase();
url = baseUrl + url;
if (type == 'GET') {
let dataStr = ''; //数据拼接字符串
Object.keys(data).forEach(key => {
dataStr += key + '=' + data[key] + '&';
@inhere
inhere / raw_js_ajax.js
Created January 11, 2018 03:49
原生js发送ajax
// @from http://www.cnblogs.com/kazetotori/p/6037940.html
// ajax函数的默认参数
var ajaxOptions = {
url: '#',
method: 'GET',
async: true,
timeout: 0,
data: null,
dataType: 'text',
headers: {},
@inhere
inhere / js_extra_util.js
Last active January 11, 2018 03:47
常用的js函数,工具类封装 收集
const extra = {}
// 密码检测密码强度
extra.checkStrength = function (sValue) {
let modes = 0
if (sValue.length < 1) return modes
// 正则表达式验证符合要求的