410的OpenID讨论

Saturday, November 4th, 2006 11:01pm

Dynamic DNS-DIY

Sunday, April 2nd, 2006 01:18pm

宿舍的宽带好,写了一个简单的python脚本,自动更新域名解析到动态的IP地址,这样我就可以随时访问宿舍里的机器了。
http://swanpan.com/phpsysinfo/

#!/usr/bin/env python

import cookielib
import urllib
import urllib2
import time
import sys

def ddd_checkip():
        response = urllib2.urlopen("http://www.dragonsoft.net/checkip.php")
        return response.read()

def ddd_hello(opener):
        return opener.open("http://www.dns-diy.com/skin.aspx?skin=api")

def ddd_login(opener, username, password):
        request = urllib2.Request("https://www.dns-diy.com/api/login.aspx")
        params = urllib.urlencode({"username":username, 'password':password})
        request.add_data(params)
        return opener.open(request)

def ddd_logout(opener):
        request = urllib2.Request("http://www.dns-diy.com/api/logout.aspx?immediately=yes&invalidate=yes")
        return opener.open(request)

def ddd_update_rr(opener, id, name, type, data, aux, ttl):
        request = urllib2.Request("http://www.dns-diy.com/api/zone_rr_update.aspx")
        params = urllib.urlencode({"id":id, "rr_name":name, "rr_type":type, "rr_data":data, "rr_aux":aux, "rr_ttl":ttl})
        request.add_data(params)
        return opener.open(request)

#
#
#

DEBUG = 5
SLEEP_SECONDS = 600

USERNAME = "swanpan.com"
PASSWORD = "secure"
RR_ID    = "secure"
RR_NAME  = ""
RR_TYPE  = "A"
RR_DATA  = "127.0.0.1"
RR_AUX   = "0"
RR_TTL   = "5"

def ddd_process():
        if (DEBUG > 0):
                print "[%(time)s] updating %(host)s.%(zone)s (%(ip)s) ..." % \
                        {"time":time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), \
                        "host":RR_NAME, "zone":USERNAME, "ip":RR_DATA}

        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))

        response = ddd_hello(opener)
        if (DEBUG > 5):
                print "HELLO"
                print response.read()

        response = ddd_login(opener, USERNAME, PASSWORD)
        if (DEBUG > 5):
                print "LOGIN"
                print response.read()

        response = ddd_update_rr(opener, RR_ID, RR_NAME, RR_TYPE, RR_DATA, RR_AUX, RR_TTL)
        if (DEBUG > 5):
                print "UPDATE"
                print response.read()

        response = ddd_logout(opener)
        if (DEBUG > 5):
                print "LOGOUT"
                print response.read()

        if (DEBUG > 0):
                print "[%(time)s] Finished!" % \
                        {"time":time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}

while True:
        try:
                ip = ddd_checkip()
                if (RR_DATA != ip):
                        RR_DATA = ip
                        ddd_process()
        except:
                if (DEBUG > 4):
                        print "Unexpected error:", sys.exc_info()[0]

        time.sleep(SLEEP_SECONDS)

Technorati Tags:



爱因斯坦写汉字

Saturday, February 25th, 2006 08:43pm

这个爱因斯坦在黑板上写字的站点蛮好玩的,可惜他写不出中文来。正好周末,我来教教他好了。然后就也做了这么个玩具

Einstein

Technorati Tags:



[SOLVED] Re: 一个数学问题

Wednesday, February 8th, 2006 07:19pm

Subject: [SOLVED] Re: 一个数学问题
From: Zhang Erning (zhangern@china-channel.com)
Date: 8/8/2005 3:18 PM
To: tech@35.cn

hi,

多谢各位的回复。

是的,这个其实就是破解RSA的问题。只是当RSA的key很大的时候,破解需要的时
间是不可接受的。
我这个问题,A,B是常量,而且算是很小的。(可能提问的时候提示不够)

根据RSA的算法的说明
当 x^B mod A = c 时,应该有
x = c^r mod B

问题就是算出r

r*B mod ((p-1)(q-1)) = 1
其中p,q是两个质数,p*q == A

问题就成了找p,q的,这也就是RSA里最直接的破解思路。因为A足够小。
A=179399505810976971998364784462504058921

通过Quadratic Sieve http://mathworld.wolfram.com/QuadraticSieve.html

p=9939430972488238699
q=18049273274048008379

B=65537
然后 modular inverse 算出
r=89126272330128007543578052027888001981

不停的google后,终于解决了。

[其实我是想写一个软件的序列号生成器,搞定了]

Zhang Erning

>>
>> Hi,
>>
>> 有个数学问题,有数学比较好的帮我看看,或者问问,谢谢。
>>
>> 对下面的方程,A,B是常量, 给定一个c,求x。其中A,B,c,x都是正整数
>> x^B mod A = c
>> (x^B表示x的B次方,mod是模。)
>>
>> A, B, c, x 都是个很大的整数,其中常亮
>> A=179399505810976971998364784462504058921
>> B=65537
>>
>> 其中一个解的例子是
>>
>> c=316442568644203243198389073 时
>> x=162056862300807702758723198119182049115
>>
>> 这个c是通过x算出来的,我想知道,给定c能否算出x
>>
>> 另外,c是有特征的,c为12个bytes的integer。其中前10个bytes固定的。
>> 比如 c = 0x 31 05 00 00 00 00 00 00 00 00 xx xx
>> 对于给定的c,就后面两个bytes不同。
>>
>> 这个问题目前也可能没有好办法。就是不能在可接受的O()里通过c逆算出x。
>>
>> Zhang Erning



RewriteModule for ASP.NET 2.0

Monday, December 12th, 2005 10:26pm

mod_rewrite is one of the most useful module for Apache.

But what to do if I’m on a Windows IIS server? I only googled a few commercial ISAPI modules (ISAPI ReWrite, IIS Rewrite). This is the most painful on Windows platform.

OK. Since I only need a few feature of the rewrite currently. I decided to do it myself. An early version is available from CVS repository - anoncvs without password.

Yeah. The RewriteCond feature haven’t been implemented. Sorry It’s only one afternoon work and I’m still a newbie on ASP.NET platform.

Here’s the sample configuration

<configuration>
    <configsections>
        <section 
            name="rewriteSection"
            type="Dragonsoft.RewriteConfigurationSection, Dragonsoft.RewriteModule" />
    </configsections>

    <system .web>
        <httpmodules>
            <add name="rewrite" type="Dragonsoft.RewriteModule" />
        </httpmodules>
    </system>       
    
    <rewritesection>
        <![CDATA[
        RewriteRule ^~/news/([^/]+)/([^/]+)\.html$ ~/news.aspx?id=$1&name=$2 [L]
        RewriteRule \fake\(.*).html$ \real\$1.aspx [NC,L]
        ]]>
    </rewritesection>
</configuration>

–update: URL Rewrite Filter for IIS is open source. I haven’t tested it.

Technorati Tags: , , ,



Two Problems from MS

Thursday, September 22nd, 2005 05:41pm

昨天做了一下MS的两个题目。一个SQL的,一个C/C++的。
C++的问题比较容易,很快搞定后,赶紧下载SQL Server Personal Editon,做SQL题目。以前也没写过Stored Procuedure,又赶紧看manual,现学现卖了。

两个题目,我的解答是这样的

C++

Node* Revert(Node* head, Node* offset)
{
    Node* node = head;
    Node* next;
    Node* prior = (offset == 0 ? 0 : offset->next);

    while (node)
    {
        next = node->next;
        node->next = prior;
        if (node == offset) break;
        prior = node;
        node = next;
    }

    return node;
}

SQL

CREATE PROCEDURE DeletePost @post_id INT AS
  DECLARE @cid INT
  DECLARE @pid INT
  DECLARE @tid INT
  SELECT @pid = @post_id
  SELECT @tid = TopicID FROM tbl_Posts
    WHERE PostID = @post_id

  WHILE (SELECT COUNT(PostID) FROM tbl_Posts
           WHERE PostID <> @post_id AND ParentID = @post_id) > 0
  BEGIN
    SELECT TOP 1 @cid = PostID FROM tbl_Posts
      WHERE PostID <> @post_id AND ParentID = @pid
    IF (@cid = @pid)
    BEGIN
      -- print @cid
      DELETE FROM tbl_Posts WHERE PostID = @cid
      SELECT @pid = @post_id
    END
    ELSE
    BEGIN
      SELECT @pid = @cid
    END
  END
  DELETE FROM tbl_Posts WHERE PostID = @post_id
GO

加上昨天用C#写的小工具,据说MS对我还算满意,接下来要准备phone screen了



Flickr Backup

Wednesday, September 21st, 2005 10:48am

FlickrBackup

中国电信访问Flickr真是慢得不行了!我在网通的机器上装了一个代理,然后将家里的机器都设置成访问Flickr都透明的通过网通的代理,速度才快多了。不明白为什么电信到很多国外的网站这么慢。因此我还当心说不定那天网通到Flickr也慢了,或者整个Flickr像flickr blog一样直接被GFW给block掉。这样就决定要把我在Flickr上的照片都给备份一下。

上个月辞掉工作,在家休息。在MS工作的朋友王庆胜想让我去他们公司看看,说是目前MSN部门正急着找程序员,主要是C#的。MS的待遇不错,对目前无业、又需要按揭房款、又要养家糊口的我还是有一定吸引力的。可我没用Windows好常时间了,更没写过C#程序。那么这个备份工具就用C#写写看吧。

花了一个通宵,FlickrBackup出来了,目前可以下载备份Flickr.com的照片,包括各种大小的。这里还有很多Features我想做,但还来不及实现。第一次用C#,第一次在.NET下写代码,感觉还不错。C#加上.NET的类库,真的是快速开发啊,有点当年Delphi的刚觉。Visual Studio .NET已经不错了,当然它写C#的时候比起用Intellij IEDA写Java代码还有段距离。估计加上ReSharper会好很多。

下载:Flickr-0.1.1.zip (95KB) 包括源代码和可执行文件。zip包里面还包括了FlickrNet-1.4.1,原来的包里有一点小错误,我修改了一下。



Flickr Uploader

Sunday, July 24th, 2005 04:12am

总觉得在浏览网页的时候看到好的图片能够直接上传到flickr比较方便。找了一通,没发现有什么好工具,就决定自己弄一个试试。

我用的是linux+firefox,写了个Greasemonkey的user script flickr-uploader.user.js。这个比直接做成extension要简单多了。

使用方法是这样的

  • 在浏览器里看到喜欢的图片,将鼠标移动到图片上,停一小会儿,图片上会出现一个按钮”flickr-uploader
    flickr-uploader-1
  • 点击那个”flickr-uploader“按钮,打开一个新的发送页面。如果你已经登录过flickr,图片就开始发送到你的flickr帐号下;还没有登录的,新页面会redirect到flickr的登录页面。发送过程可能比久,耐心等等。或者继续看网页,留这这个发送页面慢慢干活。
    flickr-uploader-2
  • 发送成功后,发送页面会显示一个链接”Continue edit your new image additions“,点这个链接转到原来filckr上传照片成功后的修改页面,可以在此修改title, description, tags之类的。
    flickr-uploader-3
  • 最后去flickr的页面看看图片是否正确显示
    flickr-uploader-4

这个script目前的做法是将要发到flickr的图片的url通知我的一个webapp,然后那个webapp用flickr api来upload图片。这个方法不理想,应该直接用浏览器upload图片更好,这应该连api都再不需要了。有时间我再改改,至少现在能用了。

这是我第一次写Greasemonkey的script,写完了Yining才介绍我看Dive Into Greasemonkey,看完后再来完善这个uploader吧。

Flickr Uploader



继续昨天的测试

Thursday, July 7th, 2005 08:18pm

今天测试了一下非HTTP方式的东西,用的是Ice for Java。拿Ice和HTTP的比较当然不合理,我就用拿Ice和本地调用比较一下吧。10,000次太少,所以测试的循环加到了100,000次。本地调用的速度应该就是我这机器上的极限速度了吧。

循环100,000次的测试

IceJ --->> Total time: 29533 ms, Avg time: 0.29533ms
Local -->> Total time:  9008 ms, Avg time: 0.09008ms

Technorati Tags: , , , ,



几种基于HTTP协议的RPC性能比较

Thursday, July 7th, 2005 12:25am

今天写个程序测试了一下Axis(SOAP), Hessian(Binary), Burlap(XML-RPC), REST的性能。

服务端的是一个简单的加密、解密方法,各种协议使用同一个实现的代码
客户端是独立的java程序,分别用各种协议对服务端的方法进行调用。每一种协议循环调用n次,然后取平均值。

循环1,000次的测试
第一次

Axis --------------->> Total time: 11123 ms, Avg time: 11.123 ms
Burlap ------------->> Total time:   866 ms, Avg time:  0.866 ms
Hessian ------------>> Total time:   581 ms, Avg time:  0.581 ms
REST --------------->> Total time:   929 ms, Avg time:  0.929 ms
AxisUsingWSDL2Java ->> Total time: 11998 ms, Avg time: 11.998 ms

第二次

Axis --------------->> Total time: 11256 ms, Avg time: 11.256 ms
Burlap ------------->> Total time:   816 ms, Avg time:  0.816 ms
Hessian ------------>> Total time:   582 ms, Avg time:  0.582 ms
REST --------------->> Total time:   919 ms, Avg time:  0.919 ms
AxisUsingWSDL2Java ->> Total time: 11908 ms, Avg time: 11.908 ms

循环10,000次的测试
第一次

Axis --------------->> Total time:  88013 ms, Avg time:  8.8013 ms
Burlap ------------->> Total time:   5789 ms, Avg time:  0.5789 ms
Hessian ------------>> Total time:   5162 ms, Avg time:  0.5162 ms
REST --------------->> Total time:   8316 ms, Avg time:  0.8316 ms
AxisUsingWSDL2Java ->> Total time: 112801 ms, Avg time: 11.2801 ms

第二次

Axis --------------->> Total time:  87359 ms, Avg time:  8.7359 ms
Burlap ------------->> Total time:   5784 ms, Avg time:  0.5784 ms
Hessian ------------>> Total time:   5084 ms, Avg time:  0.5084 ms
REST --------------->> Total time:   7983 ms, Avg time:  0.7983 ms
AxisUsingWSDL2Java ->> Total time: 113234 ms, Avg time: 11.3234 ms

测试结果
Hessian最快,Burlap第二,REST第三,Axis最慢。前3种要比Axis快了10倍或者更多。

上面的测试,服务端用的是Resin-3.0.13,出于好奇,我又用Tomcat-5.5.9测试了一把,结果是Resin确实比Tomcat快些。
Tomcat-5.5.9 循环10,000次的测试

Axis --------------->> Total time: 122551 ms, Avg time: 12.2551ms
Burlap ------------->> Total time:   6401 ms, Avg time:  0.6401ms
Hessian ------------>> Total time:   5745 ms, Avg time:  0.5745ms
REST --------------->> Total time:   8090 ms, Avg time:  0.809ms
AxisUsingWSDL2Java ->> Total time: 156908 ms, Avg time: 15.6908ms

Technorati Tags: , , , ,



Google
 
Web erning.net