Author Archives: zyanlu - Page 2

php中操作大整数…

我又out了.

今天本来打算改写一个python版的tinyurl函数(出处忘了..原作者见谅…),2^32 base62编码以后需要占6个字符,考虑到42亿不是很够,于是改成了2^64占11个字符.

import hashlib
def baseN(num,b):
    return ((num == 0) and  "0" ) or ( baseN(num // b, b).lstrip("0") + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_"[num % b])
def hash(url):
    m = hashlib.md5(url)
    s = m.hexdigest()
    num = long(s[:16],16)^long(s[16:32],16)
    return baseN(num,62)
if __name__ =="__main__":
    print hash("http://www.baidu.com/")

发现php里整型只有signed int32,木有long. 搜了一把(google “php long” 第一条结果是 php Integer, FML),官方文档说:

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that’s 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

搞不了,心想那php总得有bigint吧,一查果然有个叫GMP的东东,遂搞之:

function urlhash($url){
	$md5 = md5($url);
	$hmd5 = gmp_init(substr($md5, 0,16),16);
	$lmd5 = gmp_init(substr($md5, 16,32),16);
	return gmp_strval(gmp_xor($hmd5,$lmd5),62);
}
echo urlhash("http://www.baidu.com/");

搞定。以上俩代码均输出:

FFyeAlQajro

屁H屁还真简单啊,啥都有现成的… 挺好,舒心。

无题

咸阳机场都盖T3了

西宝高速也扩建了,路上俩事故,其中一个大货侧翻,横在路中间。

机场大巴涨到60块,汽车站也重建了。

小区老楼基本全都推倒重盖了。

没有一样东西像停留在记忆里的,就像回到了一个陌生的城市。

一段javascript

(function(){
    var aaa = bbb = 1;
})();
console.log(aaa);
console.log(bbb);

猜猜输出是什么?

Read more »

[Dev Tip] MAC修改hosts

在 /private/etc/hosts  .. .. ..

iOS4.1 + iPhone 3G 越狱指南..

这…折腾了3个小时才弄好.. 太尴尬了.

greenposion是越不掉的.. 会卡在waiting for DFU ..

最后用redsnow + ios4.1固件 搞定 , 不过照样坑爹

如果你用win7,请使用管理员身份并且选XP兼容模式运行redsnow,否则会卡在uploading ramdisk.

终于,,开vpn上cydia… 而且据我目测pptp被盾了,要用l2tp连.

墙内的穷人还是不要玩iPhone了,太辛苦. 华为Android神马的也挺好的…

忘了备份了..短信通讯录全丢,还好有google contacts保存了一些..

每个用iPhone 2代的人上辈子都是折翼的天使…

[Dev tip]

1. NSUrl 系列函数不能GET不受信的ssl站点, 必须用CFNetwork这一层的函数去搞.

2. 基于webview的app, html引用本地资源要用相对路径(因为是file://协议)

3. CFNetwork的connection timeout貌似不能设?必须从socket这一层设??

4. 不花99$想闹一个ipa是极其繁琐的.

Disable WebView Telephone Number Detect

recently i ran into a problem , the meta tag

<meta name="format-detection" content="telephone=no">

does NOT work in mainscreen shotcut , or UIWebView. As a result, the numbers in my webapp became clickable.you have to add some obj-c code the disable this feature.

/**
 Called when the webview finishes loading.
 This stops the activity view and closes the imageview
*/
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
theWebView.dataDetectorTypes = UIDataDetectorTypeNone;
return [ super webViewDidFinishLoad:theWebView ];
}

I didn’t find any solution in mainscreen shotcut.
Read more »

mac server mini

装了个iRAPP,还不错

第一个专利

我震了

传送门:http://www.ilib2.com/A-%E7%94%B3%E8%AF%B7%E5%8F%B7~CN200910020971.1.html

clone ssh session

SecureCRT has a very good feature — clone session.

we can also enjoy that feature on other platforms.

chmod 600 ~/.ssh/config

vim  ~/.ssh/config

add the following:

Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p

then ssh to your server. in my case , it’s a dynamic rsa password auth server.

login once, and the next time you open the same session,it would connect immediately.

more info: http://www.linuxjournal.com/content/speed-multiple-ssh-connections-same-server

http://www.linuxjournal.com/content/speed-multiple-ssh-connections-same-server