Skip to content

Instantly share code, notes, and snippets.

@Anye
Anye / tengine
Created August 10, 2014 12:01
tengine 启动脚本
#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Tengine is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/tengine/conf/nginx.conf
# pidfile: /usr/local/tengine/logs/nginx.pid
@Anye
Anye / php extension.md
Last active August 29, 2015 14:05
添加 php 扩展出错

安装有些PHP扩展后,直接把它添加到 php.ini 可能会报错。

这时候新建一个 ini 文件在 /etc/php.d/ 下面,重启 php-fpm 就好了。

@Anye
Anye / xhprof.php
Created August 6, 2014 12:36
使用 xhprof
<?php
xhprof_enable(XHPROF_FLAGS_CPU+XHPROF_FLAGS_MEMORY);
register_shutdown_function(function() {
$xhprof_data = xhprof_disable();
include_once __DIR__ . '/xhprof/xhprof_lib/utils/xhprof_lib.php';
include_once __DIR__ . '/xhprof/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "ce");
});
@Anye
Anye / Flexihash.php
Last active August 29, 2015 14:04
PHP 实现一致性哈希
<?php
/**
* Flexihash - A simple consistent hashing implementation for PHP.
*
* The MIT License
*
* Copyright (c) 2008 Paul Annesley
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@Anye
Anye / json.php
Created July 25, 2014 01:43
json encode 兼容中文
function JSON($data)
{
arrayRecursive($data, 'urlencode', true);
$json = json_encode($data);
return urldecode($json);
}
@Anye
Anye / gist:22055ddd55494d48d504
Created July 23, 2014 08:29
json_encode 显示中文
function __json_encode( $obj )
{
if( defined( 'JSON_UNESCAPED_UNICODE' ) ){ // >= php 5.4
return json_encode( $obj, JSON_UNESCAPED_UNICODE );
} else {
return preg_replace( "/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", json_encode( $obj ) );
}
}
@Anye
Anye / PHPView.php
Created December 18, 2013 06:25
simplie php template engine
<?php
/**
* 简单PHP模板引擎
*
* @author Anye
*
*/
class PHPView
{
protected $data = array();
@Anye
Anye / .vimrc
Last active December 30, 2015 18:59
my vim config
" ----------------- Author: Anye
" Ctrl + H --光标移当前行行首
" Ctrl + J --光标移下一行行首
" Ctrl + K --光标移上一行行尾
" Ctrl + L --光标移当前行行尾
" Ctrl + C --编译 [支持C/C++、Java、Haskll]
" Ctrl + R --运行 [支持C/C++、Java、Haskell、Lua、Perl、Python、Ruby]
" Ctrl + ] --转到函数定义
@Anye
Anye / keydown submit.js
Created November 19, 2013 07:28
keydown to submit form
document.onkeydown = function(e) {
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13){
// do something
}
}