Skip to content

Instantly share code, notes, and snippets.

@k1ic
k1ic / php
Created November 3, 2016 09:42
log id generate
sprintf("%u%04u", substr(sprintf("%.0f", microtime(true) * 1000000), 5), rand(0, 9999))
@k1ic
k1ic / php
Created November 3, 2016 06:36
sort
private function _sort($arr = array(), $sort_filed = '', $sort_direction = self::HOT_LIST_SORT_ASC) {
$sort = array(
'direction' => $sort_direction, //排序顺序标志,SORT_DESC:降序,SORT_ASC:升序
'field' => $sort_filed, //排序字段
);
$arr_sort = array();
foreach ($arr as $uniqid => $row) {
foreach ($row as $k => $v) {
$arr_sort[$k][$uniqid] = $v;
@k1ic
k1ic / php
Created March 2, 2016 03:01
rety_func
function _retry($function, $params, $max = 3) {
$this->_retry++;
if ($this->_retry >= $max) {
$this->_retry = 0;
Hades_Tool_Log::logRun("p:{$this->_processNumber}|retry_max|function:" . json_encode($function) . "|params:" . json_encode($params), false, __FUNCTION__, $this->_className, Hades_Tool_Log::TYPE_EVE);
return false;
}
usleep(20000);
@k1ic
k1ic / vimrc
Created February 25, 2016 08:27
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 语法高亮
"set syntax=on
syntax enable
" 去掉输入错误的提示声音
set noeb
@k1ic
k1ic / 12factor.md
Created September 30, 2015 06:11 — forked from harmy/12factor.md
12factor

中文翻译:梁山 英文原文:Adam Wiggins

简介

如今,软件通常会作为一种服务来交付,它们被称为网络应用程序,或“软件即服务”(SaaS)。“十二要素应用程序”(12-Factor App)为构建如下的SaaS应用提供了方法论:

  • 使用标准化流程自动配置,从而使新的开发者花费最少的学习成本加入这个项目;
  • 和操作系统之间尽可能的划清界限,在各个系统中提供最大的可移植性
  • 适合部署在现代的云计算平台,从而在服务器和系统管理方面节省资源;
@k1ic
k1ic / gist:56daf627ed43718f69bf
Created September 20, 2015 11:09
php array_walk vs foreach
<?php
$arr0 = array(
'aa' => array(
'aa_1' => array('value' => 1, 'name' => 'aa1'),
'aa_2' => array('value' => 2, 'name' => 'aa2'),
'aa_3' => array('value' => 3, 'name' => 'aa3'),
),
'ab' => array(
'ab_1' => array('value' => 4, 'name' => 'ab1'),
),
@k1ic
k1ic / isWeiboDomain
Created June 1, 2015 10:25
判断是否为weibo.com域名下的链接
/* 判断是否为weibo.com域名下的链接
* @return bool
*/
public static function isWeiboDomain($url)
{
if (empty($url)) return false;
return preg_match('/^https?:\/\/([^\.]+\.){0,5}weibo\.com(\/.*)?$/i', trim($url)) > 0;
}
@k1ic
k1ic / reTry
Last active September 8, 2015 08:28
reTry function
/**
* 重试
* @param string $class [必选]
* @param string $method [必选]
* @param array $param [可选]
* @param int $retries[可选]
* @return array
*/
public static function reTry($class, $method, $param = array(), $retries = 2)
{
@k1ic
k1ic / isDomainInListOrIsSubDomain
Created April 8, 2015 07:01
check is domain in host list or is subDomain
/**
* 判断url中的域名是域名列表中的某项或某项的子域名
* @param string $url [必选]
* @return bool
*/
public static function isDomainInListOrIsSubDomain($url = '')
{
$host = parse_url($url, PHP_URL_HOST);
$blackList = array('a.com', 'b.cn', 'c.com.cn');
return in_array($host, $blackList) || self::isSubDomain($host, $blackList);
@k1ic
k1ic / simple_curl
Last active August 29, 2015 14:16
a simple demo of curl
function simple_curl($url = '') {
if (!empty($url)) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_NOSIGNAL, 1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$version = curl_version();
if ($version["version"] < "7.16.2") {
curl_setopt($ch,CURLOPT_TIMEOUT,1);