Skip to content

Instantly share code, notes, and snippets.

@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
}
}
@Anye
Anye / remove_avatar.php
Created April 7, 2015 19:23
模糊化微信聊天记录截图
<?php
/**
* 模糊化微信聊天记录截图
*
* 给聊天记录上方联系人昵称、右边头像、右边头像模糊化(for Jonns)
*
* @create 2015年4月8日00:00:00
*
* @author AnyeGates <me@gatesanye.com>
*/
@Anye
Anye / func define
Created August 25, 2014 07:33
php get function defination
function get_func_define($function_name)
{
$reflFunc = new ReflectionFunction($function_name);
return array(
'filename'=>$reflFunc->getFileName(),
'line'=> $reflFunc->getStartLine(),
'obj'=>$reflFunc
);
}
@Anye
Anye / php-fpm.sh
Created August 10, 2014 12:06
php-fpm 启动脚本
#! /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
@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 ) );
}
}