Skip to content

Instantly share code, notes, and snippets.

@k1ic
k1ic / get_file_type.php
Created January 30, 2015 04:12
获取文件类型(通过读取文件前两个字节判断文件类型)
/**
* 获取文件类型(通过读取文件前两个字节判断文件类型)
* @param string $path 文件绝对路径
* @return string 文件扩展名
*/
public static function get_file_type ( $path = '' ) {
$res = '';
if ( file_exists($path) && is_readable($path) ) {
$fh = fopen($path, 'rb');
$bin = fread($fh, 2); //只读前两个字节
@k1ic
k1ic / is_file_upload_succ.php
Created January 30, 2015 05:43
判断文件上传是否成功
if (!empty($_FILES)) {
switch ($_FILES['voice']['error']) {
case UPLOAD_ERR_OK: //上传成功
if (!in_array(Tool_PublicPlatform::get_file_type($_FILES['voice']['tmp_name']), self::$_audioType)) {
$res = Comm_I18n::text('ajax.publicplatform.illegal_file_type');
} elseif ($_FILES['voice']['size'] > self::MAX_AUDIO_FILE_SIZE) {
$res = Comm_I18n::text('ajax.publicplatform.more_than_max') . '1M...';
} elseif ($_FILES['voice']['size'] == 0) {
$res = Comm_I18n::text('ajax.publicplatform.file_size_0M');
} else {
@k1ic
k1ic / query_string_to_array.php
Created January 30, 2015 06:01
将query_string转为数组
/**
* 将查询字符串解析为数组
* @param string
* @return array
*/
private static function _parseQueryString($query = '')
{
$res = array();
$pieces = explode('&', trim($query));
foreach ($pieces as $piece) // $piece likes 'serial=123'
@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);
@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 / 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 / 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 / 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 / 12factor.md
Created September 30, 2015 06:11 — forked from harmy/12factor.md
12factor

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

简介

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

  • 使用标准化流程自动配置,从而使新的开发者花费最少的学习成本加入这个项目;
  • 和操作系统之间尽可能的划清界限,在各个系统中提供最大的可移植性
  • 适合部署在现代的云计算平台,从而在服务器和系统管理方面节省资源;
@k1ic
k1ic / vimrc
Created February 25, 2016 08:27
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 语法高亮
"set syntax=on
syntax enable
" 去掉输入错误的提示声音
set noeb