Skip to content

Instantly share code, notes, and snippets.

@dervn
dervn / gist:701450
Created November 16, 2010 05:03
计算PHP脚本运行时间
<?php
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
//例子
//开始
$time_start = getmicrotime();
@dervn
dervn / shorturl.php
Created October 29, 2010 05:33
tinyurl
public static function shorturl($input)
{
$base32 = array ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5' );
$hex = md5($input);
$hexLen = strlen($hex);
$subHexLen = $hexLen / 8;
$output = array();
for ($i = 0; $i < $subHexLen; $i++)
{
$subHex = substr ($hex, $i * 8, 8);
@dervn
dervn / id.py
Created October 29, 2010 05:31
身份证15 -> 18 转换算法
#!/usr/bin/env python
# coding=utf-8
def getNewId(oldid):
# 将输入的oldid参数拆分成元组
a=[]
for i in oldid:
a.append(int(i))
# 在第6和7位(从0开始计算)填入1和9,组成长度为17的元组
a.insert(6,1)
@dervn
dervn / gist:602370
Created September 29, 2010 06:36
使用imagick在动态GIF上打文字水印
<?PHP
/*使用imagick在动态GIF上打文字水印*/
$draw = new ImagickDraw();
$draw->setFont('simsun.ttc');
$draw->setFontSize( 12 );
$text = iconv('GB2312', 'UTF-8', '网易');
$image=new Imagick();
$animation = new Imagick();