Skip to content

Instantly share code, notes, and snippets.

@erasin
erasin / webtest.go
Created August 26, 2013 09:36
golang 构建简单的服务器,和静态文件
package main
import (
"io"
"log"
"net/http"
"os"
)
func Hello(w http.ResponseWriter, r *http.Request) {
@erasin
erasin / verify.go
Created August 26, 2013 09:39
字段验证实例 by build web application with golang
package verify
import (
"regexp"
)
// 验证年龄是为数字
func Is_age(s string) bool {
if m, _ := regexp.MatchString("^[0-9]+$", s); !m {
return false
@erasin
erasin / gosublime.md
Last active December 21, 2015 18:39
让sublime支持项目本身的pkg库提示

项目支持,让sublime支持项目本身的pkg库提示,有两种基本的实现

一种为设定 gosublime 插件的 Setting - user 配置

{
  //"env": { "GOPATH": "$HOME/golang:$GS_GOPATH" }
  // 留空即可
  "env":{}
}
@erasin
erasin / php_execution_time.txt
Created August 27, 2013 08:40
php 超时设置
一、在php.ini里面设置 max_execution_time = 1800;
二、通过PHP的ini_set 函数设置 ini_set("max_execution_time", "1800");
三、通过set_time_limit 函数设置 set_time_limit(1800) ;
@erasin
erasin / php_zip_upload.php
Created August 27, 2013 08:52
php 打包上传
<?php
// 打包
$zipfile = 'zipByPhp.zip';
$zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
if($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE){
exit('create zip file error');
}
$files = array('queryimg.php', 'multicurl.php');
@erasin
erasin / php_iconv_array.php
Last active December 21, 2015 19:08
一些表单验证需要返回json数据,php的json_encode函数只支持utf-8编码,无奈只得iconv了,需要达到的效果是GBK数组转换成utf-8数组传给 son_encode函数。
<?php
//func 1. 将数组序列化后用iconv函数转换编码,之后再反序列化
unserialize(iconv('gbk','utf-8',serialize($array))); // 貌似经常报错
//func 2. 用构建数组原型的序列化方法,借助var_export函数,最终函数如下:
function array_iconv($in_charset,$out_charset,$arr){
return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));
}
@erasin
erasin / microtime_float.php
Created August 27, 2013 10:21
php 毫秒级别
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
echo microtime_float();
@erasin
erasin / gowalker_time.go
Last active December 22, 2015 19:19
time 示例
import_path = time
[Time_Format]
// 当前时间
fmt.Printf("%v", time.Now().Format("2006-01-02 15:04:05"))
@erasin
erasin / clentTimeout.go
Created September 18, 2013 02:52
为http.client.get 添加timeout
var timeout = time.Duration(2 * time.Second)
func dialTimeout(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, timeout)
}
func main() {
transport := http.Transport{
Dial: dialTimeout,
}
" hSATAC's vimrc
" Ash Wu (aka. cAt) <hsatac@gmail.com>
" Fork me on GITHUB https://github.com/hSATAC/vimrc
" read https://github.com/hSATAC/vimrc/blob/master/README.md for more info
" cd ~; mkdir -p ~/.vim/bundle/; cd ~/.vim/bundle/; git clone https://github.com/gmarik/vundle.git; cd ~/.vim/;
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()