Skip to content

Instantly share code, notes, and snippets.

@hubsgz
hubsgz / remaintime.php
Created June 9, 2015 05:51
计算剩余时间
/**
* 剩余时间
*/
public static function remaintime($targettime)
{
$nowtime = time();
$re = array('day'=>0, 'hour'=>0, 'minute'=>0, 'second'=>0);
if ($targettime < $nowtime) {
@hubsgz
hubsgz / isArray.js
Created June 27, 2014 07:39
判断一个对象是否是array类型
//判断一个对象是否是array类型
var isArray : function(v){
return toString.apply(v) === '[object Array]';
}
@hubsgz
hubsgz / RandStr
Created March 21, 2014 07:29
go 生成随机字符串
//生成随机字符串
func RandStr(strlen int) string {
rand.Seed(time.Now().Unix())
data := make([]byte, strlen)
var num int
for i := 0; i < strlen; i++ {
num = rand.Intn(57) + 65
for {
if num>90 && num<97 {
num = rand.Intn(57) + 65
@hubsgz
hubsgz / charcode.js
Created March 21, 2014 06:00
js ascii码和字符间的转换
// 把ascii码转换成字符
String.fromCharCode(65);
// 把字符转换成ascii码
'Z'.charCodeAt();
@hubsgz
hubsgz / md5.go
Created March 20, 2014 03:21
golang md5加密
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
)
func main() {
h := md5.New()
h.Write([]byte("123456")) // 需要加密的字符串为 123456
@hubsgz
hubsgz / exportToExcel.php
Created March 13, 2014 01:23
php 导出数据至excel
<?php
//php 导出数据至excel
class ExportExcel
{
/**
* 导出信息
*
* @return null
*/
@hubsgz
hubsgz / convert2timeago.php
Created March 11, 2014 02:24
转换时间戳为n天/小时/分/秒前
<?php
/**
* 转换时间戳为n天/小时/分/秒前
*
* @param unknown $timestamp 时间戳
*
* @return string
*/
function convert2timeago($timestamp)
{
@hubsgz
hubsgz / validate.js
Created March 5, 2014 02:19
js 手机号, 电话号码验证
//判断是否手机号
function isMobile(v) {
var reg = /^1[3|4|5|8][0-9]{9}$/; //手机号
return reg.test(v);
}
//判断是否电话号码
function isTel(v) {
var reg=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/; //电话号码
@hubsgz
hubsgz / jsonencode.php
Created February 27, 2014 06:18
中文不会被转换成 \uxxxx 形式 的 json_encode 代码
<?php
class JSON
{
/**
* 使用特定function对数组中所有元素做处理
*
* @param string &$array 要处理的字符串
* @param string $function 要执行的函数
* @param boolean $apply_to_keys_also 是否也应用到key上
*
@hubsgz
hubsgz / postjson.php
Created February 27, 2014 06:14
php post json数据 and php 模拟post 提交普通数据
<?php
/**
* post json数据
*
* @param str $url posturl
* @param str $data_string json字符串
*
* @return json_string
*/
function postjson($url, $data_string)