<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Caprices</title>
	<atom:link href="http://www.renxiaochen.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.renxiaochen.com</link>
	<description>whisper &#38; darkness</description>
	<lastBuildDate>Mon, 14 Sep 2009 09:42:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hello，百度空间</title>
		<link>http://www.renxiaochen.com/?p=427</link>
		<comments>http://www.renxiaochen.com/?p=427#comments</comments>
		<pubDate>Mon, 14 Sep 2009 09:42:22 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://renxiaochen.com/?p=427</guid>
		<description><![CDATA[今天去百度空间hi了一下。
之前一直都没有怎么用过百度空间，今天华丽丽的跑来试用，觉得做的还是很不错的。体验很流畅。夸张又浪费的功能很少。
只是空间一直没有形成规模，我想还是因为百度本身并不是一个有着强大好友关系的网站。
QQ的本身就是一张关系网，所以他家做QQ空间这种展示自我和好友交互的东西时，就能顺理成章的推广，是个很自然的过程。社交有个很重要的方向就是involve，这里面包括向别人展示和了解他人的信息，而QQ空间在已有的熟人圈建立了这一点，空间自然好推。然而百度的定位和使命一直以来就和好友关系相差甚远，贴吧也是个搜索之后的附加产物，其中的好友关系很薄弱。
好友关系薄弱有这样一个问题，你的空间是好用，是功能全，是速度快，可是我写了给谁看？我去看谁？就好像我现在注册了百度空间，又不愿意加陌生人，那么我去和谁互动的hi一下？事实告诉我们，写blog或者心情日志的自言自语，是很难坚持下去的，而且也创造不了更大的价值。所以，只有在粘固了一部分好友群体之后，才可谈推广的空间。所以百度空间体验这么好，却一直没有形成风气。
但是这里又出现一个问题，那就是，这个用户粘性的原始积累要怎么做的到？校内的原始积累是靠清华北大的fans对这种新颖形式的偏爱以及大量的线下推广，后者现在似乎已经不那么管用了。开心是的原始积累是先靠白领对小游戏的需求积累一定用户，再用白领对微妙浅层的好友交互需求来病毒式传播，吸引了大量的用户做到的。QQ是靠大量的已有用户积累，每人配一个，有人写就有人看，登录QQ访问又方便，这个太容易了。那么百度hi要怎么做？新颖？并不，空间的样子大家都见过，市场上有相当多同类产品可以做到。百度又没有原始的好友关系积累。那么，在校内、QQ、开心牢牢抓住用户分治天下的现今，要怎么完成原始积累？
百度的核心理念是搜索+社区，然而怎样从搜索牵引到社区，怎样在社区中建立牢不可破粘性巨大的好友关系，似乎又是一个华丽丽的难题。
]]></description>
			<content:encoded><![CDATA[<p>今天去百度空间hi了一下。</p>
<p>之前一直都没有怎么用过百度空间，今天华丽丽的跑来试用，觉得做的还是很不错的。体验很流畅。夸张又浪费的功能很少。</p>
<p>只是空间一直没有形成规模，我想还是因为百度本身并不是一个有着强大好友关系的网站。</p>
<p>QQ的本身就是一张关系网，所以他家做QQ空间这种展示自我和好友交互的东西时，就能顺理成章的推广，是个很自然的过程。社交有个很重要的方向就是involve，这里面包括向别人展示和了解他人的信息，而QQ空间在已有的熟人圈建立了这一点，空间自然好推。然而百度的定位和使命一直以来就和好友关系相差甚远，贴吧也是个搜索之后的附加产物，其中的好友关系很薄弱。</p>
<p>好友关系薄弱有这样一个问题，你的空间是好用，是功能全，是速度快，可是我写了给谁看？我去看谁？就好像我现在注册了百度空间，又不愿意加陌生人，那么我去和谁互动的hi一下？事实告诉我们，写blog或者心情日志的自言自语，是很难坚持下去的，而且也创造不了更大的价值。所以，只有在粘固了一部分好友群体之后，才可谈推广的空间。所以百度空间体验这么好，却一直没有形成风气。</p>
<p>但是这里又出现一个问题，那就是，这个用户粘性的原始积累要怎么做的到？校内的原始积累是靠清华北大的fans对这种新颖形式的偏爱以及大量的线下推广，后者现在似乎已经不那么管用了。开心是的原始积累是先靠白领对小游戏的需求积累一定用户，再用白领对微妙浅层的好友交互需求来病毒式传播，吸引了大量的用户做到的。QQ是靠大量的已有用户积累，每人配一个，有人写就有人看，登录QQ访问又方便，这个太容易了。那么百度hi要怎么做？新颖？并不，空间的样子大家都见过，市场上有相当多同类产品可以做到。百度又没有原始的好友关系积累。那么，在校内、QQ、开心牢牢抓住用户分治天下的现今，要怎么完成原始积累？</p>
<p>百度的核心理念是搜索+社区，然而怎样从搜索牵引到社区，怎样在社区中建立牢不可破粘性巨大的好友关系，似乎又是一个华丽丽的难题。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=427</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to remove logical volume on ArchLinux</title>
		<link>http://www.renxiaochen.com/?p=424</link>
		<comments>http://www.renxiaochen.com/?p=424#comments</comments>
		<pubDate>Tue, 08 Sep 2009 09:52:04 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=424</guid>
		<description><![CDATA[A simple lvremove vol/part would fail on ArchLinux while fuser shows no process referencing it.
This is because of the device mapper. It maps /dev/vol/part into /dev/vol-part and thus makes kernel reference.
So, dmsetup remove vol-part first
And then, lvremove vol/part
]]></description>
			<content:encoded><![CDATA[<p>A simple lvremove vol/part would fail on ArchLinux while fuser shows no process referencing it.<br />
This is because of the device mapper. It maps /dev/vol/part into /dev/vol-part and thus makes kernel reference.<br />
So, <strong>dmsetup remove vol-part</strong> first<br />
And then, <strong>lvremove vol/part</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=424</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2009.5.7</title>
		<link>http://www.renxiaochen.com/?p=416</link>
		<comments>http://www.renxiaochen.com/?p=416#comments</comments>
		<pubDate>Thu, 07 May 2009 10:29:15 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=416</guid>
		<description><![CDATA[此刻我正在实验室，背后是轰隆隆的服务器。看文档背单词灌水发呆等whisper回来吃饭。
此时whisper同学正在五道口某处辛勤的写书，我能想象他写程序的表情和玩戒指的动作，以及被人打断时痴呆的样子…… ——&#124;&#124;&#124;
看Google Reader， Space又抽风（告诉我这种团队是如何生存下去的啊啊啊啊啊啊啊），翻出来了好多女王姐姐的旧文，颇为感慨。
最近一直在问自己为什么要出国。后来发现这真是人生谜题之一，每个人境遇特色不同，选择太多其实是最令人心生恐惧的事情。控制欲望才能让心灵平静。然而我做不到。
昨天和whisper在清华散步，坐在图书馆憧憬未来。yy如果我在Stanford，我们的日子将会怎样怎样。想象mountain view的山有多高，天有多蓝，wifi有多快，白人有多少；Bay Area的建筑有多酷，程序员有多牛，生活有多便宜。我想憧憬是couple们在一起时最幸福的时刻之一，但是终究会有多少成分梦想照进现实？
然而我的神经实在是太粗了，纠结总是敌不过自我乐观的美好假象。合上单词书，一节Paganini过去，又觉得宁静幸福。不管前方怎样，要努力，要勇敢，不逃避，不放弃。十指相扣，两个人一个梦想，还不能实现吗？
强迫自己关掉牛校的网页，告诉自己NB的program看看就好，终究还是要回到这里脚踏实地，写两段程序背两页单词，做靠谱实际的工作。我想我还是有很多很美很不切实际的梦想，看来自己还没度过“蒙昧的少女时代”，然而年轻真好不是吗？有那么多可能，就算是泡沫，也耀眼美丽的一塌糊涂。
我确实是好久都没有博一下了。下笔生涩，语言乏力。
特别是当校内这个发文大玩具变成了工作场所之后，无法随心所欲的装酷，就越来越发现自己没有写作的动力了。（顺便鄙视自己做校内隐私5个月都没有把日志相册分组隐私设置做出来……）
我想要的幸福，似乎近在手边，明亮安静。希望可以无所畏惧，看时间流过。
]]></description>
			<content:encoded><![CDATA[<p>此刻我正在实验室，背后是轰隆隆的服务器。看文档背单词灌水发呆等whisper回来吃饭。</p>
<p>此时whisper同学正在五道口某处辛勤的写书，我能想象他写程序的表情和玩戒指的动作，以及被人打断时痴呆的样子…… ——|||</p>
<p>看Google Reader， Space又抽风（告诉我这种团队是如何生存下去的啊啊啊啊啊啊啊），翻出来了好多女王姐姐的旧文，颇为感慨。</p>
<p>最近一直在问自己为什么要出国。后来发现这真是人生谜题之一，每个人境遇特色不同，选择太多其实是最令人心生恐惧的事情。控制欲望才能让心灵平静。然而我做不到。</p>
<p>昨天和whisper在清华散步，坐在图书馆憧憬未来。yy如果我在Stanford，我们的日子将会怎样怎样。想象mountain view的山有多高，天有多蓝，wifi有多快，白人有多少；Bay Area的建筑有多酷，程序员有多牛，生活有多便宜。我想憧憬是couple们在一起时最幸福的时刻之一，但是终究会有多少成分梦想照进现实？</p>
<p>然而我的神经实在是太粗了，纠结总是敌不过自我乐观的美好假象。合上单词书，一节Paganini过去，又觉得宁静幸福。不管前方怎样，要努力，要勇敢，不逃避，不放弃。十指相扣，两个人一个梦想，还不能实现吗？</p>
<p>强迫自己关掉牛校的网页，告诉自己NB的program看看就好，终究还是要回到这里脚踏实地，写两段程序背两页单词，做靠谱实际的工作。我想我还是有很多很美很不切实际的梦想，看来自己还没度过“蒙昧的少女时代”，然而年轻真好不是吗？有那么多可能，就算是泡沫，也耀眼美丽的一塌糊涂。</p>
<p>我确实是好久都没有博一下了。下笔生涩，语言乏力。</p>
<p>特别是当校内这个发文大玩具变成了工作场所之后，无法随心所欲的装酷，就越来越发现自己没有写作的动力了。（顺便鄙视自己做校内隐私5个月都没有把日志相册分组隐私设置做出来……）</p>
<p>我想要的幸福，似乎近在手边，明亮安静。希望可以无所畏惧，看时间流过。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=416</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>透明代理</title>
		<link>http://www.renxiaochen.com/?p=412</link>
		<comments>http://www.renxiaochen.com/?p=412#comments</comments>
		<pubDate>Fri, 24 Apr 2009 07:40:57 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[iproute2]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[X-Forwarded-For]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=412</guid>
		<description><![CDATA[这两天没时间写spider，主要时间都花在弄透明代理上了。
问题是这样的，假设有两台WWW服务器，其中w1是主力，w2做冗余。后来，w2上部署了新的测试版服务，当服务稳定后，打算把w1也升级了。那么要升级就要满足一下几个条件：

直接该DNS记录不好，因为一旦w2正式上线失败，就需要2 * TTL左右的时间来切回w1
基于IP技术的机制不可行，包括换IP、ARP冗余和上级路由，我这是因为交换机锁MAC而我又没权限控制
没有第三台机器充当balancer

具体结构是：w1上运行apache；w2上运行nginx反向代理apache。为了保险，我首先采取的措施是，让w1上的apache不再处理请求，而是反向代理w2。但是如何让w2上的apache看到真实请求IP呢？方法是X-Forwarded-For
但问题紧跟着出现：如果请求是直接到w2/nginx上，那么nginx就需要使用：

proxy_set_header X-Forwarded-For $proxy_x_forwarded_for

如果请求是从w1/apache上反向代理过来的，那么nginx需要使用：

proxy_set_header X-Forwarded-For $http_x_forwarded_for

。如何协调呢？
这时就需要强大的 if 和 set 指令了：

1
2
3
4
5
set $real_ip $remote_addr;
if ($real_ip = 'address of w1') {
  set $real_ip $http_x_forwarded_for;
}
proxy_set_header X-Forwarded-For $real_ip;

有了上面的代码，就可以正式上线。首先不换DNS，如果有问题，只需要停止w1的反向代理即可；当测试没有问题之后，更换DNS，这时用户会随着DNS的更新逐步由w1迁移至w2，但整个过程不会感觉到任何迁移，因为请求最终都是w2响应的；最后，当确定w1上没有请求时，就可以对w1实施更新了。

还没完，下面介绍另一种方式，一种我没成功的方式，一种充分证明Linux脑残的方式：

request from any to w1:80 &#124;-nat_as-> from any to w2:80 &#124;-route_forward-> w2:80
reply from w2:80 to any &#124;-route_to-> w1 &#124;->nat_as-> from w1:80 to any &#124;-normal_route-> any

这就需要两次NAT和一次策略路由。
w1上这样：

iptables -t nat -A PREROUTING -p tcp [...]]]></description>
			<content:encoded><![CDATA[<p>这两天没时间写spider，主要时间都花在弄透明代理上了。</p>
<p>问题是这样的，假设有两台WWW服务器，其中w1是主力，w2做冗余。后来，w2上部署了新的测试版服务，当服务稳定后，打算把w1也升级了。那么要升级就要满足一下几个条件：</p>
<ol>
<li>直接该DNS记录不好，因为一旦w2正式上线失败，就需要2 * TTL左右的时间来切回w1</li>
<li>基于IP技术的机制不可行，包括换IP、ARP冗余和上级路由，我这是因为交换机锁MAC而我又没权限控制</li>
<li>没有第三台机器充当balancer</li>
</ol>
<p>具体结构是：w1上运行apache；w2上运行nginx反向代理apache。为了保险，我首先采取的措施是，让w1上的apache不再处理请求，而是反向代理w2。但是如何让w2上的apache看到真实请求IP呢？方法是X-Forwarded-For</p>
<p>但问题紧跟着出现：如果请求是直接到w2/nginx上，那么nginx就需要使用：</p>

<div class="wp_syntax"><div class="code"><pre class="nginx" style="font-family:monospace;">proxy_set_header X-Forwarded-For $proxy_x_forwarded_for</pre></div></div>

<p>如果请求是从w1/apache上反向代理过来的，那么nginx需要使用：</p>

<div class="wp_syntax"><div class="code"><pre class="nginx" style="font-family:monospace;">proxy_set_header X-Forwarded-For $http_x_forwarded_for</pre></div></div>

<p>。如何协调呢？</p>
<p>这时就需要强大的 if 和 set 指令了：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="nginx" style="font-family:monospace;">set $real_ip $remote_addr;
if ($real_ip = 'address of w1') {
  set $real_ip $http_x_forwarded_for;
}
proxy_set_header X-Forwarded-For $real_ip;</pre></td></tr></table></div>

<p>有了上面的代码，就可以正式上线。首先不换DNS，如果有问题，只需要停止w1的反向代理即可；当测试没有问题之后，更换DNS，这时用户会随着DNS的更新逐步由w1迁移至w2，但整个过程不会感觉到任何迁移，因为请求最终都是w2响应的；最后，当确定w1上没有请求时，就可以对w1实施更新了。
</p>
<p>还没完，下面介绍另一种方式，一种我没成功的方式，一种充分证明Linux脑残的方式：</p>
<ul>
<li>request from any to w1:80 |-nat_as-> from any to w2:80 |-route_forward-> w2:80</li>
<li>reply from w2:80 to any |-route_to-> w1 |->nat_as-> from w1:80 to any |-normal_route-> any</li>
<ul>
这就需要两次NAT和一次策略路由。<br />
w1上这样：</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">iptables -t nat -A PREROUTING -p tcp -d w1_address --dport http -j DNAT --to-destination w2_address
iptables -t nat -A POSTROUTING -p tcp -s w2_address --sport http -j SNAT --to-source w1_address</pre></div></div>

<p>w2上这样：</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">iptables -t mangle -A OUTPUT -p tcp -s w2_address --sport http -j MARK --set-mark 80
ip route add table 80 w1_network dev eth0 proto kernel scope link src
ip route add table 80 default via w1_address dev eth0
ip rule add fwmark 80 table 80</pre></div></div>

<p>前一步的NAT很成功，后面的策略路由就没成功过。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=412</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>第一个Spider</title>
		<link>http://www.renxiaochen.com/?p=401</link>
		<comments>http://www.renxiaochen.com/?p=401#comments</comments>
		<pubDate>Wed, 22 Apr 2009 07:51:51 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Spider Journal]]></category>
		<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=401</guid>
		<description><![CDATA[开始写Spider，工具是perl + libcurl + SQLite。原理很简单，先从已知的链接抓起，然后从抓来的网页中提取链接，把新的链接放入数据库，然后从数据库取出要抓的链接。
SQLite采用最简单的结果，就一张表：

1
2
3
4
5
6
CREATE TABLE links &#40;
  uri TEXT CONSTRAINT pk_uri PRIMARY KEY,
  code INTEGER NOT NULL,
  type TEXT,
  created_at INTEGER NOT NULL,
  fetched_at INTEGER NOT NULL&#41;;

分别记录链接地址、HTTP状态码(未抓取就是0)、Content-Type类型、入库时间和抓取时间

Perl本身有LWP但是速度比较慢，所以选取libcurl，此外使用URI规范链接地址，代码如下：

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use WWW::Curl;
use URI;
&#160;
my $curl = new WWW::Curl::East;
$curl-&#62;setopt&#40;CURLOPT_HEADER, 1&#41;;
$curl-&#62;setopt&#40;CURLOPT_USERAGENT, 'mozillabot'&#41;;
$curl-&#62;setopt&#40;CURLOPT_ENCODING, 'identity,deflate,gzip'&#41;;
$curl-&#62;setopt&#40;CURLOPT_AUTOREFERER, 1&#41;;
$curl-&#62;setopt&#40;CURLOPT_FOLLOWLOCATION, 1&#41;;
$curl-&#62;setopt&#40;CURLOPT_MAXREDIRS, 5&#41;;
&#160;
my $body;
open &#40;my $fileb, '&#62;', \$body&#41;;
$curl-&#62;setopt&#40;CURLOPT_WRITEDATA, $fileb&#41;;
&#160;
my $uri = new URI&#40;'http://www.mozillaonline.com'&#41;;
$curl-&#62;setopt&#40;CURLOPT_URL, [...]]]></description>
			<content:encoded><![CDATA[<p>开始写Spider，工具是perl + libcurl + SQLite。原理很简单，先从已知的链接抓起，然后从抓来的网页中提取链接，把新的链接放入数据库，然后从数据库取出要抓的链接。</p>
<p>SQLite采用最简单的结果，就一张表：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> links <span style="color: #66cc66;">&#40;</span>
  uri TEXT CONSTRAINT pk_uri <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
  code INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  type TEXT<span style="color: #66cc66;">,</span>
  created_at INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  fetched_at INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>分别记录链接地址、HTTP状态码(未抓取就是0)、Content-Type类型、入库时间和抓取时间
</p>
<p>Perl本身有LWP但是速度比较慢，所以选取libcurl，此外使用URI规范链接地址，代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Curl</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> URI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WWW<span style="color: #339933;">::</span><span style="color: #006600;">Curl</span><span style="color: #339933;">::</span><span style="color: #006600;">East</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_USERAGENT<span style="color: #339933;">,</span> <span style="color: #ff0000;">'mozillabot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_ENCODING<span style="color: #339933;">,</span> <span style="color: #ff0000;">'identity,deflate,gzip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_AUTOREFERER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_MAXREDIRS<span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$body</span><span style="color: #339933;">;</span>
<span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fileb</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_WRITEDATA<span style="color: #339933;">,</span> <span style="color: #0000ff;">$fileb</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'http://www.mozillaonline.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">setopt</span><span style="color: #009900;">&#40;</span>CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">$url</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">canonical</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">perform</span><span style="color: #339933;">;</span>
<span style="color: #000066;">return</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$ret</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$httpcode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getinfo</span><span style="color: #009900;">&#40;</span>CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ctype</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$curl</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getinfo</span><span style="color: #009900;">&#40;</span>CURLINFO_CONTENT_TYPE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>有了内容下一步就是提取链接地址，使用正则表达式匹配，并插入数据库：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ins</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;insert or ignore into links values (?, 0, null, strftime('%s', 'now'), 0)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@re</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+href=<span style="color: #000099; font-weight: bold;">\&quot;</span>([^<span style="color: #000099; font-weight: bold;">\&quot;</span>]+)<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+href='([^']+)'&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+href=([^'<span style="color: #000099; font-weight: bold;">\&quot;</span> &gt;]+)[ &gt;]&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+src=<span style="color: #000099; font-weight: bold;">\&quot;</span>([^<span style="color: #000099; font-weight: bold;">\&quot;</span>]+)<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+src='([^']+)'&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;[^&gt;<span style="color: #000099; font-weight: bold;">\\</span>n]+src=([^'<span style="color: #000099; font-weight: bold;">\&quot;</span> &gt;]+)[ &gt;]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@m</span><span style="color: #339933;">;</span>
<span style="color: #000066;">push</span> <span style="color: #0000ff;">@m</span><span style="color: #339933;">,</span> <span style="color: #000066;">map</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&amp;absolute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$base</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">$response</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">m</span><span style="color: #339933;">|</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">|</span>gi <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@re</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">begin_work</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$ins</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@m</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$ins</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">finish</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">commit</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这里提取的是所有href和src属性里的链接，并根据原始链接把相对地址处理成绝对地址。
</p>
<p>关于并发。spider的特点就是要非常好并发，但存在这样的问题：如何保证各个spider之间不抓同样的地址呢？目前的方法是取链接在数据库中行号对spider总数的模，不同的spider使用不同的模。代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> Getopt<span style="color: #339933;">::</span><span style="color: #006600;">Std</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$opt_n</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$opt_f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
getopt<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'n:f:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">&amp;spawn</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">&amp;fetch_url</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> spawn <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pid</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">..</span> <span style="color: #0000ff;">$opt_n</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$serial</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #000066;">fork</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">return</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$pid</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">warn</span> <span style="color: #ff0000;">'Fail to fork child'</span> <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$pid</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">push</span> <span style="color: #0000ff;">@pids</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$pid</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066;">wait</span> <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@pids</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> fetch <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$links</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">selectall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;select uri from links where code = 0 and ROWID % $opt_n = $serial order by created_at asc limit 10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@rows</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">push</span> <span style="color: #0000ff;">@rows</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@$links</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">sleep</span> <span style="color: #cc66cc;">5</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">@rows</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">&amp;extract</span> <span style="color: #b1b100;">for</span> <span style="color: #0000ff;">@rows</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p>性能问题。根据测量，抓取一个网页的速度在1s左右，虽然不是很快，但也算是能接受。但是经过16个小时10进程的抓取，发现提取出6M链接，但是只完成了44k的抓取。这个问题源于SQLite，但记录数达到M级别的时候，SQLite的查询性能会极度降低；同时作为嵌入式数据库，SQLite的锁是文件锁，性能也很差；而且数据库本身的设计也不是多好。下一步的工作是改用PostgreSQL，并进行能细致的测量。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=401</wfw:commentRss>
		<slash:comments>142</slash:comments>
		</item>
		<item>
		<title>配置ModPerl2</title>
		<link>http://www.renxiaochen.com/?p=390</link>
		<comments>http://www.renxiaochen.com/?p=390#comments</comments>
		<pubDate>Wed, 22 Apr 2009 03:30:14 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Spider Journal]]></category>
		<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[modperl]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=390</guid>
		<description><![CDATA[话说这个东西跟爬虫关系不大，为什么要弄呢？其实我打算做一个基于Firefox的自动UI测试，Firefox从数据库里取出网址，渲染，然后把渲染错误和其他的统计信息报告出来。
这样就需要一个库提供和保存网址，Firefox的addon虽然在chrome模式下有很高的权限，但是API本身很底层（除了HTTP的库），这样直接连数据库就比较难受，我选择的方法是读JSON。
其实这也不是用Apache+ModPerl2的充分条件，用个CGI::Application也足够，不过我就是想再练练，之前用ModPerl2写了多半年的程序，后来不用了也就都忘了。这次把整个过程记录下来，免得以后再重头想，ModPerl2的配置不难，就是麻烦。
第一步是安装包，以前用FreeBSD，现在用ArchLinux（严重声明：我不喜欢Linux，任意的Linux，只是公司都用这破东西没办法而已，Arch的pacman算是不错了，但是跟ports/pkgsrc还是没法比，根本不在一个档次上）
sudo pacman -S apache mod_perl perl-libapreq2 perl-dbi perl-dbd-sqlite
之后在/var/www/webwatcher目录下开始程序

# 指定模块路径
PerlSwitches -Mlib=/var/www/webwatcher/lib
&#60;VirtualHost *:80&#62;
  ServerName webwatcher
  DocumentRoot /var/www/webwatcher
&#160;
  # 自动加载模块，这样省的写PerlModule
  PerlOptions +Autoload
  &#60;IfModule !apreq_module&#62;
    LoadModule apreq_module modules/mod_apreq2.so
  &#60;/IfModule&#62;
&#160;
  &#60;Location &#34;/&#34;&#62;
    Options FollowSymLinks
    Order allow,deny
    Allow from all
&#160;
   [...]]]></description>
			<content:encoded><![CDATA[<p>话说这个东西跟爬虫关系不大，为什么要弄呢？其实我打算做一个基于Firefox的自动UI测试，Firefox从数据库里取出网址，渲染，然后把渲染错误和其他的统计信息报告出来。<br />
这样就需要一个库提供和保存网址，Firefox的addon虽然在chrome模式下有很高的权限，但是API本身很底层（除了HTTP的库），这样直接连数据库就比较难受，我选择的方法是读JSON。<br />
其实这也不是用Apache+ModPerl2的充分条件，用个CGI::Application也足够，不过我就是想再练练，之前用ModPerl2写了多半年的程序，后来不用了也就都忘了。这次把整个过程记录下来，免得以后再重头想，ModPerl2的配置不难，就是麻烦。</p>
<p>第一步是安装包，以前用FreeBSD，现在用ArchLinux（严重声明：我不喜欢Linux，任意的Linux，只是公司都用这破东西没办法而已，Arch的pacman算是不错了，但是跟ports/pkgsrc还是没法比，根本不在一个档次上）</p>
<p>sudo pacman -S apache mod_perl perl-libapreq2 perl-dbi perl-dbd-sqlite</p>
<p>之后在/var/www/webwatcher目录下开始程序</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># 指定模块路径</span>
PerlSwitches -Mlib=/var/www/webwatcher/lib
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
  <span style="color: #00007f;">ServerName</span> webwatcher
  <span style="color: #00007f;">DocumentRoot</span> /var/www/webwatcher
&nbsp;
  <span style="color: #adadad; font-style: italic;"># 自动加载模块，这样省的写PerlModule</span>
  PerlOptions +Autoload
  &lt;<span style="color: #000000; font-weight:bold;">IfModule</span> !apreq_module&gt;
    <span style="color: #00007f;">LoadModule</span> apreq_module modules/mod_apreq2.so
  &lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;
&nbsp;
  &lt;<span style="color: #000000; font-weight:bold;">Location</span> <span style="color: #7f007f;">&quot;/&quot;</span>&gt;
    <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">FollowSymLinks</span>
    <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
    <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
&nbsp;
    <span style="color: #00007f;">SetHandler</span> modperl
    PerlResponseHandler WebWatcher
  &lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>之后就是写程序 /var/www/webwatcher/lib/webwatcher.pm</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">package</span> WebWatcher<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> Apache2<span style="color: #339933;">::</span><span style="color: #006600;">RequestRec</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Apache2<span style="color: #339933;">::</span><span style="color: #006600;">RequestIO</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Apache2<span style="color: #339933;">::</span><span style="color: #006600;">Const</span> <span style="color: #339933;">-</span>compile <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">':common'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> CGI<span style="color: #339933;">::</span><span style="color: #006600;">Carp</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> handler <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$r</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content_type</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'application/x-javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">print</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">qq</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #ff0000;">'http://www.mozillaonline.com'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #ff0000;">'http://www.g-fox.cn'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066;">return</span> Apache2<span style="color: #339933;">::</span><span style="color: #006600;">Const</span><span style="color: #339933;">::</span><span style="color: #006600;">OK</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>之后的工作就是在handler里面做处理，注意ModPerl2跟PHP不同，它不会自动加载改变的代码（倒是有个库可以），所以Apache总需要reload</p>
<p>ps. 我确实觉得这么做比较麻烦，确实是没必要用这么大的工具，切记切记</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=390</wfw:commentRss>
		<slash:comments>168</slash:comments>
		</item>
		<item>
		<title>反向代理重写URL条件下的URL生成问题</title>
		<link>http://www.renxiaochen.com/?p=387</link>
		<comments>http://www.renxiaochen.com/?p=387#comments</comments>
		<pubDate>Mon, 30 Mar 2009 07:28:07 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[add_query_log]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[http_request_uri]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[request_uri]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=387</guid>
		<description><![CDATA[现在的网站架构有个趋势，就是使用多层WWW服务器。一个很常见的架构就是使用轻量级的WWW服务器处理HTTP连接，包括https gzip rewrite，甚至静态页；然后将请求转发至缓存服务器，根据请求内容的类型确定缓存策略；最后是应用服务器，负责真正的跑程序。
比如，使用nginx做前端，响应静态页面和URL重写，然后将 .*\.php$ 反向代理至后端apache，中间根据需求使用varnish做缓存。
这里就存在一个问题，如果前端的URL是http://example.org/test/index.php，但是test是个虚拟目录——也就是说后端期望看到的请求是 http://test.example.org/index.php，那么前端就需要重写URL。在这种条件下，后端的程序会在渲染网页时做出错误的选择，如 http://test.example.org/another.php，而不是 http://example.org/test/another.php。这个问题源于对REQUEST_URI的处理上。
显然对于apache而言，REQUEST_URI是 /index.php 而不是 /test/index.php，因为nginx的URL重写已经把请求地址转换了，这时Web程序会显而易见的把 / 当作document root，从而生成错误的URL地址。重要的是，我们并不应该手动的修改这个错误的document root，因为这样会导致网站在更换了反向代理地址后继续生成错误的URL（除非我们确保能记得改）。那么，哪个量是重写后仍然保持不变的呢？答案是HTTP_REQUEST_URI，这个地址记录了原始的URL请求，以它为参考就能找到正确的前缀 /test。
WordPress在2.3以上时，需要去掉canocial_url才能正确的工作于带URL重写的反向代理下，但是add_query_log系列函数仍然会报错，因为它拒绝使用baseurl和home变量，这就需要我们手工修改其实现，把REQUEST_URI变为HTTP_REQUEST_URI。
]]></description>
			<content:encoded><![CDATA[<p>现在的网站架构有个趋势，就是使用多层WWW服务器。一个很常见的架构就是使用轻量级的WWW服务器处理HTTP连接，包括https gzip rewrite，甚至静态页；然后将请求转发至缓存服务器，根据请求内容的类型确定缓存策略；最后是应用服务器，负责真正的跑程序。</p>
<p>比如，使用nginx做前端，响应静态页面和URL重写，然后将 .*\.php$ 反向代理至后端apache，中间根据需求使用varnish做缓存。</p>
<p>这里就存在一个问题，如果前端的URL是http://example.org/test/index.php，但是test是个虚拟目录——也就是说后端期望看到的请求是 http://test.example.org/index.php，那么前端就需要重写URL。在这种条件下，后端的程序会在渲染网页时做出错误的选择，如 http://test.example.org/another.php，而不是 http://example.org/test/another.php。这个问题源于对REQUEST_URI的处理上。</p>
<p>显然对于apache而言，REQUEST_URI是 /index.php 而不是 /test/index.php，因为nginx的URL重写已经把请求地址转换了，这时Web程序会显而易见的把 / 当作document root，从而生成错误的URL地址。重要的是，我们并不应该手动的修改这个错误的document root，因为这样会导致网站在更换了反向代理地址后继续生成错误的URL（除非我们确保能记得改）。那么，哪个量是重写后仍然保持不变的呢？答案是HTTP_REQUEST_URI，这个地址记录了原始的URL请求，以它为参考就能找到正确的前缀 /test。</p>
<p>WordPress在2.3以上时，需要去掉canocial_url才能正确的工作于带URL重写的反向代理下，但是add_query_log系列函数仍然会报错，因为它拒绝使用baseurl和home变量，这就需要我们手工修改其实现，把REQUEST_URI变为HTTP_REQUEST_URI。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=387</wfw:commentRss>
		<slash:comments>1846</slash:comments>
		</item>
		<item>
		<title>我们搬家啦！</title>
		<link>http://www.renxiaochen.com/?p=383</link>
		<comments>http://www.renxiaochen.com/?p=383#comments</comments>
		<pubDate>Tue, 17 Mar 2009 13:15:01 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=383</guid>
		<description><![CDATA[在轰轰烈烈的低俗整风运动中，作为大批网络黑户之一的未注册网站，我们也不能幸免。
于是，在meyu一封又一封的邮件和一次又一次的无法访问之后，我崩溃了。
这时，一位天使般的饭友caii同学出现在我们的眼前，将美利坚合众国自由的空气吹进了我们的心田。
Dreamhost，我们来啦！
ps:为什么没有Geek跑去黑了信息产业部备案的网站？我就差去那里放火了。
]]></description>
			<content:encoded><![CDATA[<p>在轰轰烈烈的低俗整风运动中，作为大批网络黑户之一的未注册网站，我们也不能幸免。<br />
于是，在meyu一封又一封的邮件和一次又一次的无法访问之后，我崩溃了。</p>
<p>这时，一位天使般的<a href="http://fanfou.com/caii">饭友caii同学</a>出现在我们的眼前，将美利坚合众国自由的空气吹进了我们的心田。</p>
<p>Dreamhost，我们来啦！</p>
<p>ps:为什么没有Geek跑去黑了信息产业部备案的网站？我就差去那里放火了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=383</wfw:commentRss>
		<slash:comments>164</slash:comments>
		</item>
		<item>
		<title>安装Gentoo，完成自动部署</title>
		<link>http://www.renxiaochen.com/?p=377</link>
		<comments>http://www.renxiaochen.com/?p=377#comments</comments>
		<pubDate>Fri, 20 Feb 2009 10:52:12 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=377</guid>
		<description><![CDATA[首先说，这两个没什么联系，就是想同时干
先说第二件，这是工作：

部署服务器上建立本地git（在公司要使用讨厌的CentOS，爷迟早把他们全变成Gentoo，或者FreeBSD，更好）：sudo yum install git git-svn; git svn clone https://domain.com/repo src; git branch deploy;
装服务器：ssh work.server &#8217;sudo sh -c &#8220;yum install nginx httpd php php-mysql; chkconfig nginx on; chkconfig httpd on; chkconfig mysqld on; service nginx start; service mysqld start;&#8221;&#8216;，注意在CentOS下直接用这条命令会报错，成功运行的前提条件是：1. sudo 启用无密码 2. 注释掉 sudoer 里面的 requiretty 3. 安装EPEL(Extra Packages for Enterprise Linux)
倒mysql数据：ssh db.server &#8216;echo &#8220;create database [...]]]></description>
			<content:encoded><![CDATA[<p>首先说，这两个没什么联系，就是想同时干</p>
<p>先说第二件，这是工作：</p>
<ol>
<li><strong>部署服务器上建立本地git</strong>（在公司要使用讨厌的CentOS，爷迟早把他们全变成Gentoo，或者FreeBSD，更好）：sudo yum install git git-svn; git svn clone https://domain.com/repo src; git branch deploy;</li>
<li><strong>装服务器：</strong>ssh work.server &#8217;sudo sh -c &#8220;yum install nginx httpd php php-mysql; chkconfig nginx on; chkconfig httpd on; chkconfig mysqld on; service nginx start; service mysqld start;&#8221;&#8216;，注意在CentOS下直接用这条命令会报错，成功运行的前提条件是：1. sudo 启用无密码 2. 注释掉 sudoer 里面的 requiretty 3. 安装EPEL(Extra Packages for Enterprise Linux)</li>
<li><strong>倒mysql数据：</strong>ssh db.server &#8216;echo &#8220;create database db; grant all on db.* to db_usr identified by db_pwd;&#8221; | mysql -u root&#8217;; ssh db.ori &#8216;mysqldump -q -l db | bzip2&#8242; | ssh db.server &#8216;bzcat | sed &#8220;s/CHARSEST=ori/CHARSET=dst/g&#8221; | mysql -u root db;&#8217;</li>
<li><strong>增加部署描述文件：</strong>vi .deploy; git add .deploy; git commit .deploy -m &#8220;Deploy descriptor&#8221;; git svn rebase; git svn dcommit; git checkout master; git svn rebase;</li>
<li><strong>实际部署：</strong>git checkout master; git svn rebase; git checkout deploy; git merge master; git diff HEAD^; git archive &#8211;format=tar HEAD some_files | bzip2 | ssh work.server &#8217;sh -c &#8220;bzcat | sudo tar xjf &#8211; -C target; sudo chown -R www:wheel target; sudo chmod -R 575 target; sudo find target -type f -exec chmod 464 {} \;;&#8221;&#8216;; cat nginx.conf | ssh work.server &#8217;sudo dd of=/etc/conf.d/nginx/target.conf; sudo service nginx reload;&#8217;，<em>这一步就包含了自动部署的基本原理，无非是依靠 git diff HEAD^ path | wc -l 来判断是否有更新，写成脚本放到 crontab 里就是自动部署了</em></li>
<li> <strong>处理apache和反向代理：</strong>注释掉/etc/httpd/conf/httpd.conf里面的所有Listen条目，把User和Group改为www（同时把nginx也改为www，这就能让两个服务器共享权限），然后找个地方写具体的apache配置去；nginx的反向代理可以参考<a title="Nginx Proxy Module" href="http://wiki.codemongers.com/NginxHttpProxyModule" target="_blank">http://wiki.codemongers.com/NginxHttpProxyModule</a></li>
</ol>
<p>工作之余装个Gentoo，虽然我很讨厌Linux，但是某些地方还是值得肯定的：Ubuntu和ArchLinux都能比较容易的获得一个可用桌面，LVM可以动态的管理分区大小从而很好的管理磁盘容量，KVM虚拟化很彪悍（我现在让虚拟机直接看到/dev/sda，然后虚拟机挂载LVM里面的卷做root，这使得我能够很容易的让虚拟服务器变为物理服务器）</p>
<p>装Gentoo注意以下几个问题：</p>
<ol>
<li> 从stage1开始的话，默认的脚本会在lzma-utils挂掉（因为没有c++），所以需要给STAGE1_USE增加nocxx</li>
<li> 到了stage2，把gcc的fortran拿掉是个好选择，openssl增加X509是有价值的（搞个自签名）</li>
<li> 使用LVM做root时，一定要emerge lvm，然后在initrd里面也要增加device-mapper和lvm-utils，否则是必然起不来的，grub的参数要包含 root=/dev/ram0 real_root=&#8221;dev/mapper/your_gentoo_root_vol&#8221; dolvm udev init=/linuxrc</li>
</ol>
<p>今天还做了日志分析，发现alex会无耻的更改浏览器agent，很多依靠agent的统计脚本会出错。所以，我决定以后把alex的流量全当作spam</p>
<p>下周会有新程序，我很想把m$做的SCOPE模拟出来，那东西还不错</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=377</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unix-like system network configuration</title>
		<link>http://www.renxiaochen.com/?p=368</link>
		<comments>http://www.renxiaochen.com/?p=368#comments</comments>
		<pubDate>Fri, 20 Feb 2009 02:51:03 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=368</guid>
		<description><![CDATA[
#unix_like_system_network_conf dl dt {font-weight:bold; text-indent:1em;}
#unix_like_system_network_conf dl dd {}



FreeBSD

configure interfaces
@/etc/rc.conf =&#62; ifconfig_em0=&#8221;inet a.b.c.d/mask&#8221; ifconfig_re0=&#8221;DHCP&#8221;
configure route
@/etc/rc.conf =&#62; static_routes=&#8221;a b&#8221; route_a=&#8221;$network $mask $gateway&#8221; route_b=&#8221;$network $mask $gateway&#8221;
configure hostname
@/etc/rc.conf =&#62; hostname=&#8221;somehost&#8221;
restart network
/etc/rc.d/network restart

Gentoo

configure interfaces
@/etc/conf.d/net =&#62; config_eth0=(&#8221;inet a.b.c.d/mask&#8221;) config_eth1=(&#8221;dhcp&#8221;)
configure route
@/etc/conf.d/net =&#62; routes_eth0=(&#8221;default via $gateway&#8221;, &#8220;$network/$mask via $gateway&#8221;)
configure hostname
@/etc/conf.d/hostname =&#62; HOSTNAME=somehost
restart network
/etc/init.d/net.eth0 restart; rc-config restart net.eth0

Debian/Ubuntu

configure interfaces
@/etc/network/interfaces =&#62; auto eth0 , iface [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#unix_like_system_network_conf dl dt {font-weight:bold; text-indent:1em;}
#unix_like_system_network_conf dl dd {}
</style>
<div id="unix_like_system_network_conf">
<ul>
<li>FreeBSD</li>
<dl>
<dt>configure interfaces</dt>
<dd>@/etc/rc.conf =&gt; ifconfig_em0=&#8221;inet a.b.c.d/mask&#8221; ifconfig_re0=&#8221;DHCP&#8221;</dd>
<dt>configure route</dt>
<dd>@/etc/rc.conf =&gt; static_routes=&#8221;a b&#8221; route_a=&#8221;$network $mask $gateway&#8221; route_b=&#8221;$network $mask $gateway&#8221;</dd>
<dt>configure hostname</dt>
<dd>@/etc/rc.conf =&gt; hostname=&#8221;somehost&#8221;</dd>
<dt>restart network</dt>
<dd>/etc/rc.d/network restart</dd>
</dl>
<li>Gentoo</li>
<dl>
<dt>configure interfaces</dt>
<dd>@/etc/conf.d/net =&gt; config_eth0=(&#8221;inet a.b.c.d/mask&#8221;) config_eth1=(&#8221;dhcp&#8221;)</dd>
<dt>configure route</dt>
<dd>@/etc/conf.d/net =&gt; routes_eth0=(&#8221;default via $gateway&#8221;, &#8220;$network/$mask via $gateway&#8221;)</dd>
<dt>configure hostname</dt>
<dd>@/etc/conf.d/hostname =&gt; HOSTNAME=somehost</dd>
<dt>restart network</dt>
<dd>/etc/init.d/net.eth0 restart; rc-config restart net.eth0</dd>
</dl>
<li>Debian/Ubuntu</li>
<dl>
<dt>configure interfaces</dt>
<dd>@/etc/network/interfaces =&gt; auto eth0 , iface eth0 inet dhcp</dd>
<dt>configure route</dt>
<dd>not know yet</dd>
<dt>configure hostname</dt>
<dd>@/etc/hostname =&gt; somehost</dd>
<dt>restart network</dt>
<dd>/etc/init.d/networking restart; service networking restart</dd>
</dl>
<li>Centos/RHEL</li>
<dl>
<dt>configure interfaces</dt>
<dd>@/etc/sysconfig/network-script/ifcfg-eth0 =&gt; BOOTPROTO=dhcp</dd>
<dt>configure route</dt>
<dd>not know yet</dd>
<dt>configure hostname</dt>
<dd>@/etc/sysconfig/network =&gt; HOSTNAME=somehost DOMAIN=some.domain</dd>
<dt>restart network</dt>
<dd>/etc/init.d/network restart; service network restart</dd>
</dl>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=368</wfw:commentRss>
		<slash:comments>7348</slash:comments>
		</item>
		<item>
		<title>使用Haskell编写日志分析程序</title>
		<link>http://www.renxiaochen.com/?p=353</link>
		<comments>http://www.renxiaochen.com/?p=353#comments</comments>
		<pubDate>Mon, 09 Feb 2009 06:40:27 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[日志]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=353</guid>
		<description><![CDATA[如果你要学会一种语言，就强迫自己用这门语言完成工作
Haskell作为一个Functional语言，在处理日常工作是不可避免的需要使用action，以下是写了好长时间的代码，终于能用了  

-- activate.hs
module Main where
&#160;
import IO
import Data.Maybe
import qualified Data.HashTable as Hash
import System.Environment
import Text.Regex.Posix
&#160;
main = do &#123;
	args &#60;- getArgs;
	rec &#60;- Hash.new &#40;==&#41; Hash.hashString;
	bracket &#40;openFile &#40;args!!0&#41; ReadMode&#41; hClose &#40;\log -&#62; do &#123;
		hSetBuffering log LineBuffering;
		hProcessLog log rec 0
	&#125;&#41;;
	recl &#60;- Hash.toList rec;
	output recl;
&#125; where
&#160;
hProcessLog log rec cnt = do &#123;
	eof &#60;- hIsEOF log;
&#160;
	if eof == False &#38;&#38; cnt [...]]]></description>
			<content:encoded><![CDATA[<p>如果你要学会一种语言，就强迫自己用这门语言完成工作</p>
<p><a href="http://en.wikipedia.org/wiki/Special:Search/Haskell">Haskell</a>作为一个Functional语言，在处理日常工作是不可避免的需要使用action，以下是写了好长时间的代码，终于能用了 <img src='http://www.renxiaochen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- activate.hs</span>
<span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Maybe</span>
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> Data<span style="color: #339933; font-weight: bold;">.</span>HashTable <span style="color: #06c; font-weight: bold;">as</span> Hash
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>Regex<span style="color: #339933; font-weight: bold;">.</span>Posix
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
	args <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs;
	rec <span style="color: #339933; font-weight: bold;">&lt;-</span> Hash<span style="color: #339933; font-weight: bold;">.</span>new <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">==</span><span style="color: green;">&#41;</span> Hash<span style="color: #339933; font-weight: bold;">.</span>hashString;
	bracket <span style="color: green;">&#40;</span>openFile <span style="color: green;">&#40;</span>args<span style="color: #339933; font-weight: bold;">!!</span><span style="color: red;">0</span><span style="color: green;">&#41;</span> ReadMode<span style="color: green;">&#41;</span> hClose <span style="color: green;">&#40;</span>\<span style="font-weight: bold;">log</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
		hSetBuffering <span style="font-weight: bold;">log</span> LineBuffering;
		hProcessLog <span style="font-weight: bold;">log</span> rec <span style="color: red;">0</span>
	<span style="color: green;">&#125;</span><span style="color: green;">&#41;</span>;
	recl <span style="color: #339933; font-weight: bold;">&lt;-</span> Hash<span style="color: #339933; font-weight: bold;">.</span>toList rec;
	output recl;
<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
hProcessLog <span style="font-weight: bold;">log</span> rec cnt <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
	eof <span style="color: #339933; font-weight: bold;">&lt;-</span> hIsEOF <span style="font-weight: bold;">log</span>;
&nbsp;
	<span style="color: #06c; font-weight: bold;">if</span> eof <span style="color: #339933; font-weight: bold;">==</span> False <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> cnt <span style="color: #339933; font-weight: bold;">&lt;=</span> <span style="color: red;">200000</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
		line <span style="color: #339933; font-weight: bold;">&lt;-</span> hGetLine <span style="font-weight: bold;">log</span>;
		fields <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> split ' ' line;
		url <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> fields<span style="color: #339933; font-weight: bold;">!!</span><span style="color: red;">6</span>;
		<span style="color: #06c; font-weight: bold;">if</span> url <span style="color: #339933; font-weight: bold;">=~</span> <span style="background-color: #3cb371;">&quot;^/live.php?&quot;</span><span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">Bool</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
			attrs <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> extract <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">drop</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> <span style="background-color: #3cb371;">&quot;/live.php?&quot;</span><span style="color: green;">&#41;</span> url;
			update rec attrs;
		<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;
&nbsp;
		cnt <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> cnt <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span>;
		<span style="color: #06c; font-weight: bold;">if</span> cnt `<span style="font-weight: bold;">mod</span>` <span style="color: red;">10000</span> <span style="color: #339933; font-weight: bold;">==</span> <span style="color: red;">0</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
			hPutStrLn stderr <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;Processed &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> cnt<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; lines&quot;</span>;
		<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;
		hProcessLog <span style="font-weight: bold;">log</span> rec cnt;
	<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
		<span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;
	<span style="color: green;">&#125;</span>
<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
split sep lst <span style="color: #339933; font-weight: bold;">=</span> split<span style="color: #339933; font-weight: bold;">_</span> sep <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> lst <span style="color: #06c; font-weight: bold;">where</span>
	split<span style="color: #339933; font-weight: bold;">_</span> sep done cur <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span>
		<span style="color: #339933; font-weight: bold;">|</span> sep <span style="color: #339933; font-weight: bold;">==</span> x <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> <span style="font-weight: bold;">length</span> cur <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">=</span> split<span style="color: #339933; font-weight: bold;">_</span> sep <span style="color: green;">&#40;</span>done <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>cur<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> xs
		<span style="color: #339933; font-weight: bold;">|</span> sep <span style="color: #339933; font-weight: bold;">==</span> x <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> <span style="font-weight: bold;">length</span> cur <span style="color: #339933; font-weight: bold;">==</span> <span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">=</span> split<span style="color: #339933; font-weight: bold;">_</span> sep done <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> xs
		<span style="color: #339933; font-weight: bold;">|</span> sep <span style="color: #339933; font-weight: bold;">/=</span> x <span style="color: #339933; font-weight: bold;">=</span> split<span style="color: #339933; font-weight: bold;">_</span> sep done <span style="color: green;">&#40;</span>cur <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>x<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> xs
	split<span style="color: #339933; font-weight: bold;">_</span> sep done cur <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> done <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>cur<span style="color: green;">&#93;</span>
&nbsp;
join sep <span style="color: green;">&#40;</span>x:x':xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> x <span style="color: #339933; font-weight: bold;">++</span> sep <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>join sep <span style="color: green;">&#40;</span>x':xs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
join sep <span style="color: green;">&#91;</span>x<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> x
join sep <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">error</span> <span style="background-color: #3cb371;">&quot;Cannot join empty list.&quot;</span>
&nbsp;
extract url <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> part <span style="color: #339933; font-weight: bold;">$</span> split '<span style="color: #339933; font-weight: bold;">=</span>' x<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>split '&amp;' url<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
part <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span> join <span style="background-color: #3cb371;">&quot;=&quot;</span> xs<span style="color: green;">&#41;</span>
&nbsp;
update rec attrs <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
	c <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> channel attrs;
	<span style="color: #06c; font-weight: bold;">if</span> <span style="font-weight: bold;">length</span> c <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">0</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
		m <span style="color: #339933; font-weight: bold;">&lt;-</span> Hash<span style="color: #339933; font-weight: bold;">.</span><span style="font-weight: bold;">lookup</span> rec c;
		<span style="color: #06c; font-weight: bold;">if</span> isJust m <span style="color: #06c; font-weight: bold;">then</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
			Hash<span style="color: #339933; font-weight: bold;">.</span>update rec c <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>fromJust m<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span>;
			<span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;
		<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">else</span> Hash<span style="color: #339933; font-weight: bold;">.</span>insert rec c <span style="color: red;">0</span>;
	<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;
<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
channel <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span>:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">if</span> k <span style="color: #339933; font-weight: bold;">==</span> <span style="background-color: #3cb371;">&quot;channelid&quot;</span>
	<span style="color: #06c; font-weight: bold;">then</span> v
	<span style="color: #06c; font-weight: bold;">else</span> channel xs
channel <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;&quot;</span>
&nbsp;
output <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span>:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span>
	<span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> k <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;: &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="font-weight: bold;">show</span> v;
	output xs;
<span style="color: green;">&#125;</span>
output <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>;</pre></div></div>

<p>很多人说Haskell是他最喜欢的命令式语言，我认为关键在于以下几点：</p>
<ul>
<li>判断的一致性，if/then/else三个分支是必须的，then/else的返回类型必须一样，这使我们明确的记住各种退出条件</li>
<li>强类型，严格的类型推导很大程度上避免了隐式类型转换带来的潜在错误，也强调了明确的形式转换</li>
<li>代码更美观，Haskell的IO是<a href="http://en.wikipedia.org/wiki/Special:Search/Monads">Monads</a>，根本的写法是 act1 >> (\x -> act2) >>= return ()的形式，这让我们明确的串联执行流程；或者使用do-syntax，这要求一个明确的缩进，如同python；或者在do-syntax内增加{}，里面使用 ; 区分各行，形成一个C风格</li>
</ul>
<p>代码使用到了Data.HashTable，这是Monads化的哈希表，qualified与as几乎是必要的，因为像update这样的函数名在Haskell的各个包里面太普遍了，直接使用Data.HashTable.update太长，不使用名称空间又跟Prelude.update冲突。</p>
<p>Data.Maybe是对Maybe a类型的扩展，提供了isJust fromJust这样的方便函数。</p>
<p>Text.Regex.Posix提供了perl式的=~操作，但目前还没发现完成替换功能的函数。</p>
<p>目前还麻烦的地方在于经常需要使用如同 cnt <- return $ cnt + 1的形式，因为 <- 右侧必须是IO a类型，这就需要明确的记住右侧使用的函数到底是function（比如 +），还是action（比如getLine）；此外，let-syntax在使用 ; 的do-syntax里无法编译，目前还在探索中。</p>
<p>以前的文章<a href="http://lileding.com/?p=63">计算就是范畴映射</a>解释了 <- 的实际意义，x <- return $ x + 1 里面左右两个x根本不是同一个变量，do-syntax背后的形式是 act1 >> (\x -> x + 1) >> (\x -> act2 x)，前后通过lambda law覆盖同名。所谓修改变量，从C的观点上看，实际上是一个传递参数的过程，只是形参和实参恰好重名。</p>
<p>关于let，let用于定义常函数，在monads里有着复杂的规则：</p>
<ul>
<li>let后面使用<-修改变量是可以的</li>
<li>let前面使用<-定义变量也是可以的</li>
<li>let x = x + 1不是在修改变量，而是定义一个完成加一的函数，这会导致在action里出现loop</li>
<li>let在 ; 写法中不可用</li>
</ul>
<p>ps. wp-syntax的代码高亮很不错 <img src='http://www.renxiaochen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=353</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>敲锣打鼓庆祝whisper同学正式入职</title>
		<link>http://www.renxiaochen.com/?p=339</link>
		<comments>http://www.renxiaochen.com/?p=339#comments</comments>
		<pubDate>Mon, 02 Feb 2009 02:49:26 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=339</guid>
		<description><![CDATA[撒花先～
2009年2月2日，我们的傲游男，Live Search男&#8211;whisper同学，
终于在党的领导和号召下，摇身一变成了火狐男。
这标志着我们正式向丁克一族迈进的伟大历史进程终于开始推动。
为了纪念这一美好的时刻，远在三元桥的Darkness同学特写此文，
立此存照。
让Firefox来的更猛烈些吧～
P.S.：whisper同学，历史任务再恢弘，也不要忘记，今天你还要：
1.修卫星
2.修遥控器
3.安装无线网关
完毕。
我爱你～

]]></description>
			<content:encoded><![CDATA[<p>撒花先～</p>
<p>2009年2月2日，我们的傲游男，Live Search男&#8211;whisper同学，<br />
终于在党的领导和号召下，摇身一变成了火狐男。</p>
<p>这标志着我们正式向丁克一族迈进的伟大历史进程终于开始推动。</p>
<p>为了纪念这一美好的时刻，远在三元桥的Darkness同学特写此文，</p>
<p>立此存照。<br />
让Firefox来的更猛烈些吧～</p>
<p>P.S.：whisper同学，历史任务再恢弘，也不要忘记，今天你还要：</p>
<p>1.修卫星</p>
<p>2.修遥控器</p>
<p>3.安装无线网关</p>
<p>完毕。<br />
我爱你～</p>
<p><img class="aligncenter size-full wp-image-343" title="whisper同学入职啦～" src="http://www.renxiaochen.com/wp-content/uploads/2009/02/e597b7e597b7.png" alt="whisper同学入职啦～" width="450" height="343" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=339</wfw:commentRss>
		<slash:comments>167</slash:comments>
		</item>
		<item>
		<title>爱情果然是百态</title>
		<link>http://www.renxiaochen.com/?p=331</link>
		<comments>http://www.renxiaochen.com/?p=331#comments</comments>
		<pubDate>Thu, 29 Jan 2009 19:31:06 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=331</guid>
		<description><![CDATA[我写我写我写写写。
空虚无聊果然是写作的伟大助推器。
==============这是正文序言的分割线===================
正月的漠北很寒冷。但是因为在父母身边，所以心里暖洋洋，幸福的要溢出来。
无奈whisper同学不能像钥匙链一样打包带着。就好像是我七巧板里面最小的那一块：你总是觉得它最好找，然而你总是因为这块而拼不全。
所以，于是，最后，总之，日子并不如想象的那么精彩。
在我把海顿巴赫莫扎特听恶心，把红楼梦Scheme产品UCD看恶心之后，新年假期综合症终于出现了。我可以一晚上在QQ群里无聊的晃来晃去写潜水ID的讣告，然后用人肉的方式不厌其烦的试验电驴的服务器哪个更快些，并且不停地看已经看过一万遍的晋商连续剧。
=================我是正文我来了====================
于是，在我无聊的在ibk看了偶像mm一百个帖子，然后又在校内翻了另一个偶像mm的相册，又听了另另外一个偶像mm的甜蜜爱情故事之后，我崩溃了。
爱情果然是百态。
你不能想象那么酷酷的彪悍的强大的事业型的绝世大美女居然那么细腻可人，为爱情奋不顾身改变自己义无反顾。
你也不能想象原来围绕在身边的人们之间发生过那么诡秘神奇的爱情故事，以至于当你看到男主角和女主角的时候，心里无法把他们与八卦联系在一起。
你更不能想象这个世界上有那么甜蜜的一对情侣，他们可以疯狂追求，一月被感动二月见父母三月照合影四月合家欢过年。当你看到照片里娇艳的玫瑰花闪耀的love&#38;love对戒，亦或是手牵手相拥的幸福表情，好吧，我承认，即便是有着客观理智从容逻辑思维的灭绝师太的我，也不得不经历从鄙视到不看好到不适应到嫉妒到对自己不满意到羡慕到看好到真心祝福的过程。
==================我是回忆的引导员===================
我发现自从身边多了whisper同学，我的倾诉脸现象似乎升级了。
原先大家只是同我畅谈理想，或是在失恋的时候痛诉革命家史。然而当她们发现原来我的名字前面已经可以加上一个Mrs的时候，大家开始亢奋的向我拓展倾诉的范围。从追求指南到配偶攻略，从驯夫之道到家庭矛盾。于是我身边清一色的悲剧变成了闹剧。所以，每每也要感叹爱情的丰富，幸福的couple都是一样的，不幸的couple各有各的不幸。
将上面的三个故事按顺序编号，请大家在脑中自动进行交叉引用（LaTex男语：这年头果然什么都比Word靠谱。）
我对MM一号绝对是一见钟情。当她向我伸出她那双骨瘦如柴岌岌可危的手时，我顿时明白，这才是我一生奋斗的目标。这女人强大而又聪明，记得见她之后，我喋喋不休的用了两个小时向whisper同学阐述我是如何爱她的，之后又无比认真的要求whisper同学充当第三者将她娶进门来。
然而当我一路回看MM一号写的文章时，脑中只能回想起海顿同学的《G大调第九十四号交响曲》。这么洒脱聪明的女人，对待自己爱的男人，居然这么细腻，无私和执着。我不知道该遗憾还是该敬佩，只是有隐隐的心疼。我已经承受和聆听了太多离别的故事，这一次，我真的希望，她能找到幸福。
MM二号是我长久以来的偶像。我毫不避讳的承认，我做她狂热而执着的粉丝已经快五年了。这期间，她的文字，动态，生活状况，不断的影响着我对这个世界的认识和对品味的理解。我常常觉得这是又辛苦而又偷懒的事情，我可以不用思考的踏着她的脚印前行，可是，要追上她的步速，我还要花钱买好几个魔瓶。
所以，当男偶像二号与女偶像相遇的时候，当我意外的发现他们之间若隐若现的关联，我不禁感叹，门当户对这个词不仅仅用在家世上，在思想上依然恒等成立。
Great  minds  thinks  alike. Great people can always find each other.
MM三号不曾出现在我的生活中，然而我的生活中出现了一位与MM三号密切相关的男钻石王老五一枚。从他的叙述开始，我先是对微软男表示了极度的不信任和讽刺，之后对MM三号进行了恶毒的攻击和鄙夷。当事情的发展已经脱线到不可救药水到渠成生米煮成熟饭的时候，我依然贼心不死恣意妄为的想要预言这件事情终究有个凄凉的结尾。
然而当幸福的大泡泡已经炫目刺眼到不能直视，我的情绪终于由鄙视转化为嫉妒。当赤裸裸的嫉妒照耀大地的时候，我才发现，原来一直以来，可能是我不相信的美好太多。虽然素未谋面，也从未相识，我依然祝福微软男夫妻，你们会幸福的，请用更加赤裸的现实来向我开炮吧。
贝壳上依然有情侣在闹分手，QQ上依然有“是否要冷静下来&#8221;的同学等待我去答疑，几十个小时之后我依然会握着whisper同学的手感觉他脉搏的频率。
爱情果然是百态，就算是用范畴论也无法虚构新的逻辑去解释它们。如果我们不能控制，那么不如忘记，宁静的享受每一分钟。
但愿明天会更好。
]]></description>
			<content:encoded><![CDATA[<p>我写我写我写写写。<br />
空虚无聊果然是写作的伟大助推器。</p>
<p>==============这是正文序言的分割线===================</p>
<p>正月的漠北很寒冷。但是因为在父母身边，所以心里暖洋洋，幸福的要溢出来。</p>
<p>无奈whisper同学不能像钥匙链一样打包带着。就好像是我七巧板里面最小的那一块：你总是觉得它最好找，然而你总是因为这块而拼不全。</p>
<p>所以，于是，最后，总之，日子并不如想象的那么精彩。</p>
<p>在我把海顿巴赫莫扎特听恶心，把红楼梦Scheme产品UCD看恶心之后，新年假期综合症终于出现了。我可以一晚上在QQ群里无聊的晃来晃去写潜水ID的讣告，然后用人肉的方式不厌其烦的试验电驴的服务器哪个更快些，并且不停地看已经看过一万遍的晋商连续剧。</p>
<p>=================我是正文我来了====================</p>
<p>于是，在我无聊的在ibk看了偶像mm一百个帖子，然后又在校内翻了另一个偶像mm的相册，又听了另另外一个偶像mm的甜蜜爱情故事之后，我崩溃了。</p>
<p>爱情果然是百态。</p>
<p>你不能想象那么酷酷的彪悍的强大的事业型的绝世大美女居然那么细腻可人，为爱情奋不顾身改变自己义无反顾。</p>
<p>你也不能想象原来围绕在身边的人们之间发生过那么诡秘神奇的爱情故事，以至于当你看到男主角和女主角的时候，心里无法把他们与八卦联系在一起。</p>
<p>你更不能想象这个世界上有那么甜蜜的一对情侣，他们可以疯狂追求，一月被感动二月见父母三月照合影四月合家欢过年。当你看到照片里娇艳的玫瑰花闪耀的love&amp;love对戒，亦或是手牵手相拥的幸福表情，好吧，我承认，即便是有着客观理智从容逻辑思维的灭绝师太的我，也不得不经历从鄙视到不看好到不适应到嫉妒到对自己不满意到羡慕到看好到真心祝福的过程。</p>
<p>==================我是回忆的引导员===================</p>
<p>我发现自从身边多了whisper同学，<a href="http://www.renxiaochen.com/?p=44" target="_blank">我的倾诉脸现象</a>似乎升级了。</p>
<p>原先大家只是同我畅谈理想，或是在失恋的时候痛诉革命家史。然而当她们发现原来我的名字前面已经可以加上一个Mrs的时候，大家开始亢奋的向我拓展倾诉的范围。从追求指南到配偶攻略，从驯夫之道到家庭矛盾。于是我身边清一色的悲剧变成了闹剧。所以，每每也要感叹爱情的丰富，幸福的couple都是一样的，不幸的couple各有各的不幸。</p>
<p>将上面的三个故事按顺序编号，请大家在脑中自动进行交叉引用（LaTex男语：这年头果然什么都比Word靠谱。）</p>
<p>我对MM一号绝对是一见钟情。当她向我伸出她那双骨瘦如柴岌岌可危的手时，我顿时明白，这才是我一生奋斗的目标。这女人强大而又聪明，记得见她之后，我喋喋不休的用了两个小时向whisper同学阐述我是如何爱她的，之后又无比认真的要求whisper同学充当第三者将她娶进门来。</p>
<p>然而当我一路回看MM一号写的文章时，脑中只能回想起海顿同学的<span style="color: #000000;">《G大调第九十四号交响曲》。这么洒脱聪明的女人，对待自己爱的男人，居然这么细腻，无私和执着。我不知道该遗憾还是该敬佩，只是有隐隐的心疼。我已经承受和聆听了太多离别的故事，这一次，我真的希望，她能找到幸福。</span></p>
<p><span style="color: #000000;">MM二号是我长久以来的偶像。我毫不避讳的承认，我做她狂热而执着的粉丝已经快五年了。这期间，她的文字，动态，生活状况，不断的影响着我对这个世界的认识和对品味的理解。我常常觉得这是又辛苦而又偷懒的事情，我可以不用思考的踏着她的脚印前行，可是，要追上她的步速，我还要花钱买好几个魔瓶。</span></p>
<p><span style="color: #000000;">所以，当男偶像二号与女偶像相遇的时候，当我意外的发现他们之间若隐若现的关联，我不禁感叹，门当户对这个词不仅仅用在家世上，在思想上依然恒等成立。</span></p>
<p>Great  minds  thinks  alike. Great people can always find each other.</p>
<p>MM三号不曾出现在我的生活中，然而我的生活中出现了一位与MM三号密切相关的<a href="http://www.jiangtianzheng.com" target="_blank">男钻石王老五一枚</a>。从他的叙述开始，我先是对微软男表示了极度的不信任和讽刺，之后对MM三号进行了恶毒的攻击和鄙夷。当事情的发展已经脱线到不可救药水到渠成生米煮成熟饭的时候，我依然贼心不死恣意妄为的想要预言这件事情终究有个凄凉的结尾。</p>
<p>然而当幸福的大泡泡已经炫目刺眼到不能直视，我的情绪终于由鄙视转化为嫉妒。当赤裸裸的嫉妒照耀大地的时候，我才发现，原来一直以来，可能是我不相信的美好太多。虽然素未谋面，也从未相识，我依然祝福微软男夫妻，你们会幸福的，请用更加赤裸的现实来向我开炮吧。</p>
<p>贝壳上依然有情侣在闹分手，QQ上依然有“是否要冷静下来&#8221;的同学等待我去答疑，几十个小时之后我依然会握着whisper同学的手感觉他脉搏的频率。</p>
<p>爱情果然是百态，就算是用范畴论也无法虚构新的逻辑去解释它们。如果我们不能控制，那么不如忘记，宁静的享受每一分钟。</p>
<p>但愿明天会更好。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=331</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>关于“搂草打兔子”的考据</title>
		<link>http://www.renxiaochen.com/?p=291</link>
		<comments>http://www.renxiaochen.com/?p=291#comments</comments>
		<pubDate>Thu, 29 Jan 2009 13:14:53 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>
		<category><![CDATA[假期 无聊 考据 维基百科]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=291</guid>
		<description><![CDATA[
Darkness同学的父亲，是一位“生活上很伟大的语言学家”。
最近他老人家又发掘出一句叫做“搂草打兔子”的学术语言。并经常使用。
本着对他老人家“两个凡是”的原则，Darkness和Whisper同学迅速组织起了轰轰烈烈的学习工作，不仅在生活上积极使用先进词汇，并且从历史渊源和科学分析的角度对其进行了考据，以下是学习成果，供组织上审阅纠正。
一. 历史渊源
“搂草打兔子”是来自河南民间的一句俗语，意思是在割草的同时把躲在里面的兔子一并擒获。干一件事情的同时，又获得了其他收益。
用我们更加熟悉的方言来说，就是“顺带着”，“捎带手”，“一举两得”。
例句：
Darkness同学正在测试她的blog，于是她搂草打兔子写了一篇考据。
二. 科学分析
对于这样一句俗语，我们不禁有以下两个疑问：
1.为什么搂草的时候可以打到兔子？
2.兔子不是生活在洞穴里么？为什么会在草的后面？
首先，根据文献和常识判断，我们可以认定，这里说的兔子，应该是指野兔，而非普通的兔子。
维基百科这样告诉我们：（原文请点击 这里）
兔，俗称兔子，是哺乳类兔形目、草食性脊椎动物。
兔科（学名 Leporidae） 包括大约50种兔和野兔。所有的属，除了兔属（Lepus）以外，通常被归类于兔；而兔属（Lepus）大约占近一半的种类则常被称为野兔。
而通过分析野兔的生活习性，我们惊喜的发现了如下结论：
野兔的巢穴不像兔般是在地底的，而是一个以草堆成或浅窝的巢。野兔出生时已有完整的兔毛及打开的眼睛，故习惯了没有天然屏障的巢。它们在出生后立刻能快速的闪避，相反兔及林兔属都是胎后发育的，幼兔出生时没有毛及是盲的。


由此可以判断，在搂草的过程中，很有可能接触到野兔的窝，于是便有了“搂草打兔子”的典故。这个俗语，还是很有科学依据的。
新年假期很无聊，有以上文章为证。
]]></description>
			<content:encoded><![CDATA[<div class="storycontent">
<p>Darkness同学的父亲，是一位“生活上很伟大的语言学家”。</p>
<p>最近他老人家又发掘出一句叫做“搂草打兔子”的学术语言。并经常使用。</p>
<p>本着对他老人家“<a onclick="javascript:pageTracker._trackPageview('/outbound/article/http://baike.baidu.com/view/67133.html?tp=0_11');" href="http://baike.baidu.com/view/67133.html?tp=0_11" target="_blank">两个凡是</a>”的原则，Darkness和Whisper同学迅速组织起了轰轰烈烈的学习工作，不仅在生活上积极使用先进词汇，并且从历史渊源和科学分析的角度对其进行了考据，以下是学习成果，供组织上审阅纠正。</p>
<p><strong>一. 历史渊源</strong></p>
<p><strong>“搂草打兔子”</strong>是来自河南民间的一句俗语，意思是在割草的同时把躲在里面的兔子一并擒获。干一件事情的同时，又获得了其他收益。</p>
<p>用我们更加熟悉的方言来说，就是“顺带着”，“捎带手”，“一举两得”。</p>
<p>例句：</p>
<p>Darkness同学正在测试她的blog，于是她<span style="text-decoration: underline;">搂草打兔子</span>写了一篇考据。</p>
<p><strong>二. 科学分析</strong></p>
<p>对于这样一句俗语，我们不禁有以下两个疑问：</p>
<p>1.为什么搂草的时候可以打到兔子？</p>
<p>2.兔子不是生活在洞穴里么？为什么会在草的后面？</p>
<p>首先，根据文献和常识判断，我们可以认定，这里说的兔子，应该是指野兔，而非普通的兔子。</p>
<p><a onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org');" href="http://zh.wikipedia.org/" target="_blank">维基百科</a>这样告诉我们：（原文请点击 <a onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E5%85%94&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E5%85%94&amp;variant=zh-cn" target="_blank">这里</a>）</p>
<blockquote><p><em><strong>兔</strong>，俗称<strong>兔子</strong>，是哺乳类<a title="兔形目" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E5%85%94%E5%BD%A2%E7%9B%AE&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E5%85%94%E5%BD%A2%E7%9B%AE&amp;variant=zh-cn">兔形目</a>、草食性脊椎<a title="动物" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E5%8A%A8%E7%89%A9&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E5%8A%A8%E7%89%A9&amp;variant=zh-cn">动物</a>。</em></p>
<p><em><strong>兔科</strong>（学名 </em><em>Leporidae） 包括大约50种<strong class="selflink">兔</strong>和<a title="野兔" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E9%87%8E%E5%85%94&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E9%87%8E%E5%85%94&amp;variant=zh-cn">野兔</a>。所有的属，除了兔属（</em><em>Lepus）以外，通常被归类于兔；而兔属（</em><em>Lepus）大约占近一半的种类则常被称为野兔。</em></p></blockquote>
<p>而通过分析<a onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E5%85%94%E5%B1%AC&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E5%85%94%E5%B1%AC&amp;variant=zh-cn">野兔</a>的生活习性，我们惊喜的发现了如下结论：</p>
<blockquote><p><em><span style="color: #ff0000;"><strong>野兔的巢穴不像<a title="兔" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E5%85%94&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E5%85%94&amp;variant=zh-cn">兔</a>般是在地底的，而是一个以草堆成或浅窝的巢。</strong></span>野兔出生时已有完整的兔毛及打开的<a class="mw-redirect" title="眼睛" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E7%9C%BC%E7%9D%9B&amp;variant=zh-cn');" href="http://zh.wikipedia.org/w/index.php?title=%E7%9C%BC%E7%9D%9B&amp;variant=zh-cn">眼睛</a>，故习惯了没有天然屏障的巢。它们在出生后立刻能快速的闪避，相反兔及<a class="new" title="林兔屬 (尚未撰写)" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://zh.wikipedia.org/w/index.php?title=%E6%9E%97%E5%85%94%E5%B1%AC&amp;action=edit&amp;redlink=1');" href="http://zh.wikipedia.org/w/index.php?title=%E6%9E%97%E5%85%94%E5%B1%AC&amp;action=edit&amp;redlink=1">林兔属</a>都是胎后发育的，幼兔出生时没有毛及是盲的。</em></p>
<p><em><br />
</em></p></blockquote>
<p>由此可以判断，在搂草的过程中，很有可能接触到野兔的窝，于是便有了“搂草打兔子”的典故。这个俗语，还是很有科学依据的。</p>
<p>新年假期很无聊，有以上文章为证。</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=291</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我们需要什么样的爱国主义教育？</title>
		<link>http://www.renxiaochen.com/?p=277</link>
		<comments>http://www.renxiaochen.com/?p=277#comments</comments>
		<pubDate>Thu, 29 Jan 2009 11:33:08 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>
		<category><![CDATA[电影 政治 爱国 观感]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=277</guid>
		<description><![CDATA[追忆似水年华，度过无聊假期。
翻出老电影，看了《Independence Day》。
片子是不错的，特效和音响，都绝对配得起96年票王的称号。
然而除了这些刺激的观感，心里似乎还有别样的滋味。
2个多小时的片子，自恋的美国人就没有一刻停止yy他们的国家。
美国人是前锋英雄，是地球的救世主。
美国人可以调遣多国部队，引导世界军备。
美国人是科技的引领者，告诉其他国家，什么才是正确的方法。
看的时候忿忿的想，着美国鬼子也太猖狂，嚣张于此。
然而，反过来，站在美国绿卡民众们的立场上，这难道不是一次伟大的爱国主义教育么？
美国代表着所有的正义，英勇。代表着世界领袖强大的实力和魄力。
无论是军事设施，还是总统人选，总是这个世界上最完美的形式。
无怪世界警察的美国，民众如此齐心自恋。
总是观看这样的片子，几十年如一日的看，谎言讲一千遍也成了真理，能不坚信于心吗？
在我们传统的意识里，爱国本是个严肃紧张的事儿。
而万恶的美帝国主义居然放开了爱，放开了宣传，居然不通过新闻联播这种正经和谐的方式，居然不经过广电总局这样正经的单位审核，就放这样的主旋律电影，真是令人发指。
想想我们的政治课本，想想我们每学期必修6学分的思想政治课程，想想我们必须组织学习的党课，想想我们“只有社会主义才能救中国”的英明结论。
曲径通幽处，柳暗花明时。
如果有一天，我们不这么主旋律，不这么又红又专，而是旁敲侧击。
也许“国外的月亮比较圆”这一页，能更快的翻过去。
]]></description>
			<content:encoded><![CDATA[<p>追忆似水年华，度过无聊假期。<br />
翻出老电影，看了《<a href="http://www.douban.com/subject/1293013/?i=0"><span style="font-size: x-small;"><span style="font-weight: normal;">Independence Day</span></span></a>》。</p>
<p>片子是不错的，特效和音响，都绝对配得起96年票王的称号。<br />
然而除了这些刺激的观感，心里似乎还有别样的滋味。</p>
<p>2个多小时的片子，自恋的美国人就没有一刻停止yy他们的国家。<br />
美国人是前锋英雄，是地球的救世主。<br />
美国人可以调遣多国部队，引导世界军备。<br />
美国人是科技的引领者，告诉其他国家，什么才是正确的方法。</p>
<p>看的时候忿忿的想，着美国鬼子也太猖狂，嚣张于此。<br />
然而，反过来，站在美国绿卡民众们的立场上，这难道不是一次伟大的爱国主义教育么？<br />
美国代表着所有的正义，英勇。代表着世界领袖强大的实力和魄力。<br />
无论是军事设施，还是总统人选，总是这个世界上最完美的形式。<br />
无怪世界警察的美国，民众如此齐心自恋。<br />
总是观看这样的片子，几十年如一日的看，谎言讲一千遍也成了真理，能不坚信于心吗？</p>
<p>在我们传统的意识里，爱国本是个严肃紧张的事儿。<br />
而万恶的美帝国主义居然放开了爱，放开了宣传，居然不通过新闻联播这种正经和谐的方式，居然不经过广电总局这样正经的单位审核，就放这样的主旋律电影，真是令人发指。<br />
想想我们的政治课本，想想我们每学期必修6学分的思想政治课程，想想我们必须组织学习的党课，想想我们“只有社会主义才能救中国”的英明结论。<br />
曲径通幽处，柳暗花明时。</p>
<p>如果有一天，我们不这么主旋律，不这么又红又专，而是旁敲侧击。<br />
也许“国外的月亮比较圆”这一页，能更快的翻过去。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=277</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected: where is the way?</title>
		<link>http://www.renxiaochen.com/?p=272</link>
		<comments>http://www.renxiaochen.com/?p=272#comments</comments>
		<pubDate>Mon, 26 Jan 2009 17:09:04 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>
		<category><![CDATA[Love]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=272</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://www.renxiaochen.com/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-272">Password:<br />
<input name="post_password" id="pwbox-272" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=272</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2009新年计划</title>
		<link>http://www.renxiaochen.com/?p=266</link>
		<comments>http://www.renxiaochen.com/?p=266#comments</comments>
		<pubDate>Sat, 24 Jan 2009 10:53:43 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>
		<category><![CDATA[新年 计划]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=266</guid>
		<description><![CDATA[已经蹉跎过了元旦，要赶在农历新年之前。
计划计划。
比起2008年冗长和华丽的计划，经过这一年的打磨，自己已然踏实许多。
尽管依然浮躁，但是总归是在进步。性格的打磨，还是需要时间的。
2009年的任务是：
踏踏实实学好数学。
踏踏实实学好英语。
完毕。
希望站在这一年的尾巴上，我能笑着说：
零九年的任务，我还完成的不错。
这将是更恢弘的一年。
]]></description>
			<content:encoded><![CDATA[<p>已经蹉跎过了元旦，要赶在农历新年之前。<br />
计划计划。</p>
<p>比起<span style="color: #99ccff;"><a href="http://renxiaochen.blogspot.com/2007/12/2008plan.html" target="_blank">2008年冗长和华丽的计划</a></span>，经过这一年的打磨，自己已然踏实许多。<br />
尽管依然浮躁，但是总归是在进步。性格的打磨，还是需要时间的。</p>
<p>2009年的任务是：</p>
<p><span style="color: #ff0000;"><strong>踏踏实实学好数学。<br />
踏踏实实学好英语。</strong></span></p>
<p>完毕。</p>
<p>希望站在这一年的尾巴上，我能笑着说：<br />
零九年的任务，我还完成的不错。</p>
<p>这将是更恢弘的一年。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=266</wfw:commentRss>
		<slash:comments>163</slash:comments>
		</item>
		<item>
		<title>Google Friend Connect与多域名WordPress协作方法</title>
		<link>http://www.renxiaochen.com/?p=253</link>
		<comments>http://www.renxiaochen.com/?p=253#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:07:05 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[f(x)=x]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=253</guid>
		<description><![CDATA[Google Friend Connect的实现机制是在网页中嵌入iframe,这使得同一个人在不同站点上实现单点登陆，因为实际上是大家都登陆了Google Friend Connect那个网站。那么既然用户实际上是登陆了同一个网站，这个网站怎么区分实际的内容是需要被放置在哪个网站上呢？
答案是在iframe里增加另一个field，这个field代表了实际上用户正在用的网站是哪个。那这个field的值又是从哪得到的呢？答案就是在iframe的URL里面，这个iframe是根据实际网站的script创建的，在创建时就可以动态给定那个关键的gfci_side_id了。
gfci_side_id被包含在最终网页的json里，那这个json是怎么来的呢？是wordpress生成的。
wp-content/plugins/google-friend-connect-integration/gfcintegration.php中包含以下代码:

function gfci_sit() {
  $gfci_val = get_option( gfci_side_id );
  echo $gfci_val;
}

get_option方法是在wordpress的wp_options里面，条目是gfci_side_id
说到这，方法就很明显了，修改成：

function gfci_sit() {
  $gfci_val = get_option( gfci_side_id . $_SERVER['HTTP_HOST'] );
  echo $gfci_val;
}

然后在数据库的wp-options里面增加gfci_side_idxxx.com条目，值是相应的网站ID，即可满足同一个网站，不同域名下均能使用Google Friend Connect的需求
]]></description>
			<content:encoded><![CDATA[<p>Google Friend Connect的实现机制是在网页中嵌入iframe,这使得同一个人在不同站点上实现单点登陆，因为实际上是大家都登陆了Google Friend Connect那个网站。那么既然用户实际上是登陆了同一个网站，这个网站怎么区分实际的内容是需要被放置在哪个网站上呢？</p>
<p>答案是在iframe里增加另一个field，这个field代表了实际上用户正在用的网站是哪个。那这个field的值又是从哪得到的呢？答案就是在iframe的URL里面，这个iframe是根据实际网站的script创建的，在创建时就可以动态给定那个关键的gfci_side_id了。</p>
<p>gfci_side_id被包含在最终网页的json里，那这个json是怎么来的呢？是wordpress生成的。</p>
<p>wp-content/plugins/google-friend-connect-integration/gfcintegration.php中包含以下代码:</p>
<pre name="code" class="php">
function gfci_sit() {
  $gfci_val = get_option( gfci_side_id );
  echo $gfci_val;
}
</pre>
<p>get_option方法是在wordpress的wp_options里面，条目是gfci_side_id<br />
说到这，方法就很明显了，修改成：</p>
<pre name="code" class="php">
function gfci_sit() {
  $gfci_val = get_option( gfci_side_id . $_SERVER['HTTP_HOST'] );
  echo $gfci_val;
}
</pre>
<p>然后在数据库的wp-options里面增加gfci_side_idxxx.com条目，值是相应的网站ID，即可满足同一个网站，不同域名下均能使用Google Friend Connect的需求</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=253</wfw:commentRss>
		<slash:comments>165</slash:comments>
		</item>
		<item>
		<title>从baidu搬家到wordpress，现在我们一起写</title>
		<link>http://www.renxiaochen.com/?p=239</link>
		<comments>http://www.renxiaochen.com/?p=239#comments</comments>
		<pubDate>Fri, 16 Jan 2009 15:30:39 +0000</pubDate>
		<dc:creator>whisper</dc:creator>
				<category><![CDATA[Whisper Says]]></category>
		<category><![CDATA[f(x)=x]]></category>

		<guid isPermaLink="false">http://lileding.com/?p=239</guid>
		<description><![CDATA[从即日起，whisper同学正式将自己维护许久的blog作废，融合入darkness同学很少更新的blog里，以为滥竽充数
代码是偶花了很多个小时才写出来的，很久不会c#了，话说应该是用perl，怎奈媳妇实验室的机器那个破windows啊，那个破visual studio啊
比如说吧，原来的blog是host在baidu上的。那个东西的rss只支持10个输出，还没有完整内容，以上很讨厌。搬家的程序就是parse他的网页，注意不是xhtml，我是用了HtmlParser做处理
以下是写这个程序搂草打兔子学会的其他内容：

StreamReader在建立的时候，一定要给定编码，而在输出的时候就是完美的utf-8。HttpWebRequest提供了Charset和Content-Encoding两个属性作为编码指示，目前还不清楚他们之间的关系
.NET异步操作在完成的时候，AsyncWaitHandle.WaitOne与AsyncCallback调用是否完成没关系。因此，在一次性等待多个WaitHandle完成并根据完成后的结果做处理时，回调函数的执行与完成后的处理函数是错乱执行的，目前的解决方案是等待另一个AutoResetEvent，然后在回调函数里Set这个Event
.NET本身并不提供IOCP功能，也就是说，要么串行等着，要么使用线程，要么使用异步方法配合WaitAny。目前并不清楚在.Net 3.5中是否提供了IOCP功能
wordpress导入时，只需要post_author, post_date, post_title, post_content以及一部分选项即可。如何同时导入分类和标签还不清楚

媳妇我爱你
]]></description>
			<content:encoded><![CDATA[<p>从即日起，whisper同学正式将自己维护许久的blog作废，融合入darkness同学很少更新的blog里，以为滥竽充数
<p>代码是偶花了很多个小时才写出来的，很久不会c#了，话说应该是用perl，怎奈媳妇实验室的机器那个破windows啊，那个破visual studio啊</p>
<p>比如说吧，原来的blog是host在baidu上的。那个东西的rss只支持10个输出，还没有完整内容，以上很讨厌。搬家的程序就是parse他的网页，注意不是xhtml，我是用了HtmlParser做处理</p>
<p>以下是写这个程序搂草打兔子学会的其他内容：</p>
<ol>
<li>StreamReader在建立的时候，一定要给定编码，而在输出的时候就是完美的utf-8。HttpWebRequest提供了Charset和Content-Encoding两个属性作为编码指示，目前还不清楚他们之间的关系</li>
<li>.NET异步操作在完成的时候，AsyncWaitHandle.WaitOne与AsyncCallback调用是否完成没关系。因此，在一次性等待多个WaitHandle完成并根据完成后的结果做处理时，回调函数的执行与完成后的处理函数是错乱执行的，目前的解决方案是等待另一个AutoResetEvent，然后在回调函数里Set这个Event</li>
<li>.NET本身并不提供IOCP功能，也就是说，要么串行等着，要么使用线程，要么使用异步方法配合WaitAny。目前并不清楚在.Net 3.5中是否提供了IOCP功能</li>
<li>wordpress导入时，只需要post_author, post_date, post_title, post_content以及一部分选项即可。如何同时导入分类和标签还不清楚</li>
</ol>
<p style="font-size:large">媳妇我爱你</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=239</wfw:commentRss>
		<slash:comments>185</slash:comments>
		</item>
		<item>
		<title>Wave To 2008 &amp; Happy New Year</title>
		<link>http://www.renxiaochen.com/?p=50</link>
		<comments>http://www.renxiaochen.com/?p=50#comments</comments>
		<pubDate>Wed, 31 Dec 2008 19:22:31 +0000</pubDate>
		<dc:creator>Darkness</dc:creator>
				<category><![CDATA[Darkness Says]]></category>
		<category><![CDATA[总结]]></category>
		<category><![CDATA[新年]]></category>

		<guid isPermaLink="false">http://www.renxiaochen.com/?p=50</guid>
		<description><![CDATA[又是一年草木轮回。
2008，我继续与这个我热爱的国家一同跌宕起伏着。
这是传奇性的一年，历经磨难却注定璀璨绚烂。
 
 
一月
复习，考试，泡论坛，逛网站。
这一个月，我在ibeike发了1000个帖子，在饭否上发了几百条消息，认识了无数人。
考完之后一个人在北京上新东方。天天水清和学校跑着。简单充实。
但我从未想到，新年夜伤痛的小插曲，会贯穿整个年度始终。
 
二月
南方冰雪弥漫，每日看新闻超过2小时。
去贵州的计划破产，家人来北京团聚过年。虽说已经不是第一次，但是仍然寂寞温暖。
和爸妈一起看了三场京剧，两次演出，路遇无数大小名人。
最后还是忍不住回家小住。漠北二月的天气干燥寒冷，但亲情温暖。
告诉自己，也许这才是我想要的。
过了自己第19个单身的情人节，V day晚宴上，和某ET女青年互见家长。
 
三月
开学，工作，研究互联网。
对校会投入日渐增多，其间情绪时有反复，却不能否认日渐增长的热爱。
各种折腾之后架起了www.renxiaochen.com，与BUAA愈发联系紧密。
也许就是这个三月，奠定了我浓重的“嫁人要嫁BUAA人”的情结。
逛遍了北京吃喝玩乐的大街小巷。
 
四月
每日必关注圣火走向，对西方世界耿耿于怀，虽不愤青，也不舒服。
很多人，很多事坚定了我对前往大洋彼岸的决心。然而依旧理智的知道困难重重。
看到身边人的幸福，应接不暇，心里充满祝福的喜悦。
春暖花开的季节，时日静好，工作铺展顺利。
常常一个人看话剧听戏曲，结识大把文艺男女青年。
 
五月
这是个神秘的月份。五月，总是有很多不可言说的秘密。
于是，当巨大的悲怆向我们的土地袭来，我选择了回避。
进退两难，举步维艰。戏称是一场“精神灾难”。
然而，如今我回头望去，除了笑笑，留下的，却全是感动。
我爱你们每一个人。
离开校会，虽然选择做的很艰难。
除了不适应就是不适应，觉得一颗心无处安放。难过的不知道如何表述。
 
六月
在我生辰的这个月份。过的很疯狂，很年轻，很文艺。
永远记得凌晨2点什刹海的镜面，中南海静谧的红墙，长安街稀疏过往的车辆。
偶像远赴欧洲，退休综合征让我伤感的不能自已。
去北大看了两场话剧，去后海吃了无数顿晚餐。
过了有史以来最安静的一个生日，某人从此出现在我的生活中，强势霸道，无法抹掉。
 
七月
考试周华丽落幕。跌宕起伏的过了三个月，身心俱疲。
好的是，在忙碌中终于忘记了什么人，开始面对更精彩的生活。
入职，在银行的实习，才发现真实的工作与自己想象的相差甚远。
Hermes、Armanni。金融的魅力鲜活的展现在我面前，然而我依旧选择放弃。
 
八月
奥运吉祥耀眼的出现在盛夏的北京。一片盛世祥和喜气洋洋。
志愿服务、实习工作、GRE复习。
看了北京主要场馆的所有比赛，对奥运的激情一点点褪去。
永远记得在鸟巢看比赛的时候，对自己说，无论怎样，要用最多的时间陪父母。
 
九月
漫长的假期。GRE机考。
苏州街刺眼的阳光，手机里的短信和电话。
一瞬间突然意识到，也许对我来说，你不仅仅是短信和符号。
回家完成了一件秘密的使命。带着满心欢喜和重重的行李回到北京。
飞机晚点6小时，包头机场通宵的等待。
 
十月
被开学的课业压力折磨的喘不过气来。面对完全陌生的程序一头雾水。
还好有你在身边。发现，握着你的手，有前所未有的安定。
入职，开始在校内全新的旅程。
依旧很对命运的安排感恩。困难，是我唯一不惧怕的东西。
 
十一月
Work hard, Play hard. 
焦虑是这个月的主线。课业压力，纠结的情绪。
等不到答案，找不到方向。疲惫的一塌糊涂。
那个时候，常常想把自己的生活打包烧掉。
感谢那个我最好的姐妹，在我最困难的时候听我讲话，给我安慰。
那些你在楼道里把我骂的无法还嘴的日子，才是最珍贵的感情。
 
十二月
台湾政局风起云涌，好戏连台。常常看着报纸，无奈的笑笑。
阿扁摧毁的不仅仅是台湾人民给他的信任，还有无数对民主心存信仰知识分子心中的希冀。
厨房、咖啡馆、宿舍楼。
在这个要划下休止符的月份，你却为我划出最美的咏叹调。
 
这是很恢弘的一年。气场起伏的让我常常想起海顿的曲子们。
然而当我站在新年的尖角上，我想，我可以轻松的转身挥手，向这过去的一年致意。
 
“I figure life is a gift and I don’t intend on wasting it. You never know what hand you’re going to get dealt next. You learn to take life as it comes at you. ”
在《TITANIC》里Leonardo这样说。
 
亲爱的们，新年快乐。
已经到来的2009年，我们会更努力。
这一年会很美好。
Best Wishes.:-)
]]></description>
			<content:encoded><![CDATA[<p>又是一年草木轮回。</p>
<p>2008，我继续与这个我热爱的国家一同跌宕起伏着。</p>
<p>这是传奇性的一年，历经磨难却注定璀璨绚烂。</p>
<p> </p>
<p> </p>
<p>一月</p>
<p>复习，考试，泡论坛，逛网站。</p>
<p>这一个月，我在ibeike发了1000个帖子，在饭否上发了几百条消息，认识了无数人。</p>
<p>考完之后一个人在北京上新东方。天天水清和学校跑着。简单充实。</p>
<p>但我从未想到，新年夜伤痛的小插曲，会贯穿整个年度始终。</p>
<p> </p>
<p>二月</p>
<p>南方冰雪弥漫，每日看新闻超过2小时。</p>
<p>去贵州的计划破产，家人来北京团聚过年。虽说已经不是第一次，但是仍然寂寞温暖。</p>
<p>和爸妈一起看了三场京剧，两次演出，路遇无数大小名人。</p>
<p>最后还是忍不住回家小住。漠北二月的天气干燥寒冷，但亲情温暖。</p>
<p>告诉自己，也许这才是我想要的。</p>
<p>过了自己第19个单身的情人节，V day晚宴上，和某ET女青年互见家长。</p>
<p> </p>
<p>三月</p>
<p>开学，工作，研究互联网。</p>
<p>对校会投入日渐增多，其间情绪时有反复，却不能否认日渐增长的热爱。</p>
<p>各种折腾之后架起了www.renxiaochen.com，与BUAA愈发联系紧密。</p>
<p>也许就是这个三月，奠定了我浓重的“嫁人要嫁BUAA人”的情结。</p>
<p>逛遍了北京吃喝玩乐的大街小巷。</p>
<p> </p>
<p>四月</p>
<p>每日必关注圣火走向，对西方世界耿耿于怀，虽不愤青，也不舒服。</p>
<p>很多人，很多事坚定了我对前往大洋彼岸的决心。然而依旧理智的知道困难重重。</p>
<p>看到身边人的幸福，应接不暇，心里充满祝福的喜悦。</p>
<p>春暖花开的季节，时日静好，工作铺展顺利。</p>
<p>常常一个人看话剧听戏曲，结识大把文艺男女青年。</p>
<p> </p>
<p>五月</p>
<p>这是个神秘的月份。五月，总是有很多不可言说的秘密。</p>
<p>于是，当巨大的悲怆向我们的土地袭来，我选择了回避。</p>
<p>进退两难，举步维艰。戏称是一场“精神灾难”。</p>
<p>然而，如今我回头望去，除了笑笑，留下的，却全是感动。</p>
<p>我爱你们每一个人。</p>
<p>离开校会，虽然选择做的很艰难。</p>
<p>除了不适应就是不适应，觉得一颗心无处安放。难过的不知道如何表述。</p>
<p> </p>
<p>六月</p>
<p>在我生辰的这个月份。过的很疯狂，很年轻，很文艺。</p>
<p>永远记得凌晨2点什刹海的镜面，中南海静谧的红墙，长安街稀疏过往的车辆。</p>
<p>偶像远赴欧洲，退休综合征让我伤感的不能自已。</p>
<p>去北大看了两场话剧，去后海吃了无数顿晚餐。</p>
<p>过了有史以来最安静的一个生日，某人从此出现在我的生活中，强势霸道，无法抹掉。</p>
<p> </p>
<p>七月</p>
<p>考试周华丽落幕。跌宕起伏的过了三个月，身心俱疲。</p>
<p>好的是，在忙碌中终于忘记了什么人，开始面对更精彩的生活。</p>
<p>入职，在银行的实习，才发现真实的工作与自己想象的相差甚远。</p>
<p>Hermes、Armanni。金融的魅力鲜活的展现在我面前，然而我依旧选择放弃。</p>
<p> </p>
<p>八月</p>
<p>奥运吉祥耀眼的出现在盛夏的北京。一片盛世祥和喜气洋洋。</p>
<p>志愿服务、实习工作、GRE复习。</p>
<p>看了北京主要场馆的所有比赛，对奥运的激情一点点褪去。</p>
<p>永远记得在鸟巢看比赛的时候，对自己说，无论怎样，要用最多的时间陪父母。</p>
<p> </p>
<p>九月</p>
<p>漫长的假期。GRE机考。</p>
<p>苏州街刺眼的阳光，手机里的短信和电话。</p>
<p>一瞬间突然意识到，也许对我来说，你不仅仅是短信和符号。</p>
<p>回家完成了一件秘密的使命。带着满心欢喜和重重的行李回到北京。</p>
<p>飞机晚点6小时，包头机场通宵的等待。</p>
<p> </p>
<p>十月</p>
<p>被开学的课业压力折磨的喘不过气来。面对完全陌生的程序一头雾水。</p>
<p>还好有你在身边。发现，握着你的手，有前所未有的安定。</p>
<p>入职，开始在校内全新的旅程。</p>
<p>依旧很对命运的安排感恩。困难，是我唯一不惧怕的东西。</p>
<p> </p>
<p>十一月</p>
<p><span class="content">Work hard, Play hard.</span> </p>
<p>焦虑是这个月的主线。课业压力，纠结的情绪。</p>
<p>等不到答案，找不到方向。疲惫的一塌糊涂。</p>
<p>那个时候，常常想把自己的生活打包烧掉。</p>
<p>感谢那个我最好的姐妹，在我最困难的时候听我讲话，给我安慰。</p>
<p>那些你在楼道里把我骂的无法还嘴的日子，才是最珍贵的感情。</p>
<p> </p>
<p>十二月</p>
<p>台湾政局风起云涌，好戏连台。常常看着报纸，无奈的笑笑。</p>
<p>阿扁摧毁的不仅仅是台湾人民给他的信任，还有无数对民主心存信仰知识分子心中的希冀。</p>
<p>厨房、咖啡馆、宿舍楼。</p>
<p>在这个要划下休止符的月份，你却为我划出最美的咏叹调。</p>
<p> </p>
<p>这是很恢弘的一年。气场起伏的让我常常想起海顿的曲子们。</p>
<p>然而当我站在新年的尖角上，我想，我可以轻松的转身挥手，向这过去的一年致意。</p>
<p> </p>
<p>“I figure life is a gift and I don’t intend on wasting it. You never know what hand you’re going to get dealt next. You learn to take life as it comes at you. ”</p>
<p>在《TITANIC》里Leonardo这样说。</p>
<p> </p>
<p>亲爱的们，新年快乐。</p>
<p>已经到来的2009年，我们会更努力。</p>
<p>这一年会很美好。</p>
<p>Best Wishes.:-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.renxiaochen.com/?feed=rss2&amp;p=50</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
