Skip to content

Instantly share code, notes, and snippets.

@dervn
dervn / ip.php
Created June 28, 2012 04:00
ip抽取实验脚本
<?php
/***************************************************************************
*
* Copyright (c) 2012 Baidu.com, Inc. All Rights Reserved
*
**************************************************************************/
/**
* @file ip.php
* @author dn(com@baidu.com)
@dervn
dervn / get_remote_img.py
Created February 25, 2012 04:05
python下载网络上的图片示例
import urllib
import urllib2
import os
picurl="http://images.51cto.com/files/uploadimg/20100630/104906665.jpg"
save_path="d:\\"
imgData = urllib2.urlopen(picurl).read()
# 给定图片存放名称
fileName = save_path + "\\ddd.jpg"
# 文件名是否存在
@dervn
dervn / tb1.py
Created February 23, 2012 10:05
script to get content from xxx.com
#!/usr/bin/env python
# encoding: utf-8
"""
tb1.py
Created by dn on 2011-07-24.
Copyright (c) 2011 shubz. All rights reserved.
"""
import os
import sys
import re
@dervn
dervn / gist:1697568
Created January 29, 2012 06:36
文字竖排
x = u'床前明月光 疑是地上霜 举头望明月 低头思故乡'
print '\n'.join(' '.join(x) for x in zip(*map(list, x.split(' ')))) #这个写法还有点问题,有空再来研究
---
低举疑床
头头是前
思望地明
故明上月
乡月霜光
@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
{
@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
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 / 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
@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 / 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());