This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
#! /usr/bin/env | |
import httplib | |
import re | |
import sys | |
pn = 0 | |
MAX = 10000 | |
certainty = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// html email code transformation | |
// See http://www.awflasher.com/jsmail | |
function HtmlEncode( s ) | |
{ | |
var result = ""; | |
for (var j = 0; j < s.length; j++ ) { | |
// Encode 25% of characters | |
if (Math.random() < 0.25 | |
|| s.charAt(j) == ':' | |
|| s.charAt(j) == '@' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Following concat function concatenate javascript arrays | |
// It consider three more factor then normal Array.prototype.concat: | |
// 1. eliminate common element | |
// 2. escape null and undefined | |
// 3. deal with element being an array | |
var arr1 = ['a']; | |
var arr2 = ['b', 'c']; | |
var arr3 = ['c', ['d'], 'e', undefined, null]; | |
// return object classname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// encode(decode) html text into html entity | |
var decodeHtmlEntity = function(str) { | |
return str.replace(/&#(\d+);/g, function(match, dec) { | |
return String.fromCharCode(dec); | |
}); | |
}; | |
var encodeHtmlEntity = function(str) { | |
var buf = []; | |
for (var i=str.length-1;i>=0;i--) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} dec Decimal number need to be converted | |
* @return {string} String representation of hexadecimal | |
*/ | |
var dec2hex = function(dec) { | |
var buf = [], | |
map = '0123456789ABCDEF'; | |
while (parseInt(dec / 16, 10) !== 0) { | |
buf.unshift(map[dec % 16]); | |
dec = parseInt(dec / 16, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dec1 = 5234542352345; | |
var bin1 = dec1.toString(2); | |
// chop into 32 bit | |
var bin2 = bin1.slice(bin1.length-32); | |
var dec2 = parseInt(bin2, 2); | |
var dec3 = dec2 >> 0; | |
var bin3 = dec3.toString(2); | |
console.log(dec1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// escape don't: * @ – _ + . / | |
// encodeURI don't: ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) # | |
// encodeURIComponent don't: - _ . ! ~ * ' ( ) | |
/* | |
// 部分转义 | |
// text -> unicode | |
unicode = escape(text); | |
// unicode -> text | |
text = unescape(unicode); | |
// text -> utf8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handler negtive number into binary. | |
// The code following is really meanless for number itself is depend on it's | |
// length. For instance, in bit operation, number will be treated as 32 bit. | |
// @see http://stackoverflow.com/questions/4338315/javascript-inverting-a-binary-value-of-a-number | |
function dec2Bin(dec) | |
{ | |
if(dec > 0) { | |
return dec.toString(2); | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using regular expression to validate email address. | |
* Exactly email address format refer to http://en.wikipedia.org/wiki/Email_address. | |
* @author zhongchiyu@gmail.com | |
*/ | |
var validateEmail = (function() { | |
// ATTENSION: escape is really mess because you have to escape in string and | |
// in regular expression. | |
var normal = "0-9a-zA-Z\\!#\\$%&'\\*\\+\\-\\/\\=\\?\\^_`\\{\\|\\}~"; | |
// mix contain normal character and special character |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clone only simple object | |
// handle Array, Date and RegExp | |
// resolve circular reference | |
var clone = (function(){ | |
// classify object | |
var classof = function(o){ | |
if (o === null) { return "null"; } | |
if (o === undefined) { return "undefined"; } | |
// I suppose Object.prototype.toString use obj.constructor.name | |
// to generate string |
OlderNewer