Skip to content

Instantly share code, notes, and snippets.

@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();
@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 / 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 / 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 / form_token.html
Created January 12, 2011 10:39
表单CSRF处理
echo "<input name='rft' type='hidden' value='".random_form_token()."' />";
if(random_form_token($_POST['rft'])){
//
}
else{
//
}
function random_form_token($value=NULL){
if($value == NULL){
$token = hash("sha256","tanzmal".microtime());
@dervn
dervn / unicode.py
Created March 8, 2011 01:35
unicode处理 errors='ignore'
#‘ignore’ (just leave the character out of the Unicode result)
#replace
unicode('\x80abc', errors='ignore')
text = "第二十集神兵天降 第七章 旦雅之危"
text.decode('gb2312',errors='ignore')
@dervn
dervn / re.py
Created March 8, 2011 02:08
Python中过滤HTML标签的函数
#用正则简单过滤html的<>标签
import re
str = "<img /><a>srcd</a>hello</br><br/>"
str = re.sub(r'</?\w+[^>]*>','',str)
print str
import re
youtube_url_pattern = re.compile(r'youtube.com/.*?v[/=](?P<video_id>[\w-]+)')
def get_video_id(url):
result = youtube_url_pattern.search(url)
if result:
return result.group('video_id')
@dervn
dervn / ril2ip.py
Created April 25, 2011 02:30 — forked from sdb/ril2ip.py
copy bookmarks from Read It Later to Instapaper
#! /usr/bin/env python
"""
Script to copy all bookmarks from Read It Later to Instapaper.
See also http://readitlaterlist.com/api/docs/#get
and http://www.instapaper.com/api/simple
"""
import urllib, urllib2, json
@dervn
dervn / SvnPeer.php
Created December 30, 2011 06:33
SVN操作类
<?php
/**
*
* This class for execute the external program of svn
*
* @auth Seven Yang <qineer@gmail.com>
*
*/
class SvnPeer
{