Skip to content

Instantly share code, notes, and snippets.

@Anye
Anye / keydown submit.js
Created Nov 19, 2013
keydown to submit form
View keydown submit.js
document.onkeydown = function(e) {
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if (code == 13){
// do something
}
}
@Anye
Anye / .vimrc
Last active Dec 30, 2015
my vim config
View .vimrc
" ----------------- 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 / PHPView.php
Created Dec 18, 2013
simplie php template engine
View PHPView.php
<?php
/**
* 简单PHP模板引擎
*
* @author Anye
*
*/
class PHPView
{
protected $data = array();
@Anye
Anye / gist:22055ddd55494d48d504
Created Jul 23, 2014
json_encode 显示中文
View gist:22055ddd55494d48d504
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 / json.php
Created Jul 25, 2014
json encode 兼容中文
View json.php
function JSON($data)
{
arrayRecursive($data, 'urlencode', true);
$json = json_encode($data);
return urldecode($json);
}
@Anye
Anye / Flexihash.php
Last active Aug 29, 2015
PHP 实现一致性哈希
View Flexihash.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 / xhprof.php
Created Aug 6, 2014
使用 xhprof
View xhprof.php
<?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 / php extension.md
Last active Aug 29, 2015
添加 php 扩展出错
View php extension.md

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

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

@Anye
Anye / tengine
Created Aug 10, 2014
tengine 启动脚本
View 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-fpm.sh
Created Aug 10, 2014
php-fpm 启动脚本
View php-fpm.sh
#! /bin/sh
#
# chkconfig: - 84 16
# description: PHP FastCGI Process Manager
# processname: php-fpm
# config: /etc/php-fpm.conf
# config: /etc/sysconfig/php-fpm
# pidfile: /var/run/php-fpm/php-fpm.pid
#
### BEGIN INIT INFO
You can’t perform that action at this time.