<?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"
	>

<channel>
	<title>米饭@hit.cs</title>
	<atom:link href="http://www.leezii.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leezii.com/blog</link>
	<description>What should I do in a binary world?</description>
	<pubDate>Sat, 27 Dec 2008 11:48:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Python Challenge</title>
		<link>http://www.leezii.com/blog/archives/25</link>
		<comments>http://www.leezii.com/blog/archives/25#comments</comments>
		<pubDate>Sat, 27 Dec 2008 11:43:50 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=25</guid>
		<description><![CDATA[Python Challenge is a game in which each level can be solved by a bit  of Python programming. 
很久以前就看到bbs上有人推荐这个，一直没有时间做，今天比较闲，找出来看了看，过了level 0和level 1，感觉还是挺有意思的。
level 0 不用写代码 直接 2**38就可以得到答案。
level 1 代码如下：

#!/usr/bin/env python

fd = open('Q1.text')
data = fd.read()
lenth = len(data)
result = []
for i in range(0, lenth):
    if data[i].isalpha():
        if data[i] [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #800080;"><strong><a href="http://www.pythonchallenge.com/">Python Challenge</a> is a game in which each level can be solved by a bit  of Python<a href="http://www.python.org/"></a> programming. </strong></span></p>
<p>很久以前就看到bbs上有人推荐这个，一直没有时间做，今天比较闲，找出来看了看，过了level 0和level 1，感觉还是挺有意思的。</p>
<p>level 0 不用写代码 直接 2**38就可以得到答案。</p>
<p>level 1 代码如下：</p>
<pre class="python" line="1">
#!/usr/bin/env python

fd = open('Q1.text')
data = fd.read()
lenth = len(data)
result = []
for i in range(0, lenth):
    if data[i].isalpha():
        if data[i] == 'y':
            result.append('a')
        elif data[i] == 'z':
            result.append('b')
        else:
            result.append(chr(ord(data[i]) + 2))
    else:
        result.append(data[i])

    i += 1

print ''.join(result) 
</pre>
<p>有一点和推荐做法不一样，推荐用string.maketrans方法， 但是string类仿佛用得越来越少了，我都没有接触过这个，没办法，山寨做法了……</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/25/feed</wfw:commentRss>
		</item>
		<item>
		<title>Spaces instead of Tabs</title>
		<link>http://www.leezii.com/blog/archives/24</link>
		<comments>http://www.leezii.com/blog/archives/24#comments</comments>
		<pubDate>Tue, 09 Dec 2008 05:34:03 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=24</guid>
		<description><![CDATA[在写程序的时候，许多人，包括我，都习惯于以一个tab进行缩进，但是这样有一个很严重的问题，每个人可以定义不同的tab宽度，这样，相同的程序会呈现不同的效果。所以，很多编程规范建议我们采取空格做缩进，但是一下子敲入4个，8个空格实在太烦人了。
Emacs可以帮助我们……

(setq c-basic-offset 4)
(setq tab-width 4)
(setq indent-tabs-mode nil)
这样设置以后，缩进为4个字符，tab-width的宽度为4，在c-mode中 按一下tab可以缩进两个空格，而C-q C-i可以插入一个制表符，宽度为4。解释一下，最后一条语句的效果是禁止在缩进中插入制表符。如果没有这一句，可能是两种情况：

c-basic-offset &#62;= tab-width：如果这样设置，比如 c-basic-offset == 4 , tab-width == 2，这样emacs就会插入两个tab进行缩进；c－basic-offset ==6 , tab-width == 4 ，此时emacs会插入一个制表符，两个空格。也就是说emacs会优先插入制表符。
c-basic-offset &#60; tab-width: emacs 按照 c-basic-offset指定的宽度缩进，全部插入空格。

所以，如果我们期望缩进宽度和制表符宽度一致，必须加入最后那条语句。
还有一点需要说明，多数mode都会使用c-basic-offset这个变量来控制缩进，但是python-mode是个例外。

(setq py-smart-indentation nil)
(setq tab-width 4)
(setq-default py-indent-offset 4)
(setq indent-tabs-mode nil)
python-mode使用py-indent-offset来控制缩进，其他的原理同上。
]]></description>
			<content:encoded><![CDATA[<p>在写程序的时候，许多人，包括我，都习惯于以一个tab进行缩进，但是这样有一个很严重的问题，每个人可以定义不同的tab宽度，这样，相同的程序会呈现不同的效果。所以，很多编程规范建议我们采取空格做缩进，但是一下子敲入4个，8个空格实在太烦人了。</p>
<p>Emacs可以帮助我们……<br />
<code><br />
(setq c-basic-offset 4)<br />
(setq tab-width 4)<br />
(setq indent-tabs-mode nil)</code></p>
<p>这样设置以后，缩进为4个字符，tab-width的宽度为4，在c-mode中 按一下tab可以缩进两个空格，而C-q C-i可以插入一个制表符，宽度为4。解释一下，最后一条语句的效果是禁止在缩进中插入制表符。如果没有这一句，可能是两种情况：</p>
<ol>
<li>c-basic-offset &gt;= tab-width：如果这样设置，比如 c-basic-offset == 4 , tab-width == 2，这样emacs就会插入两个tab进行缩进；c－basic-offset ==6 , tab-width == 4 ，此时emacs会插入一个制表符，两个空格。也就是说emacs会优先插入制表符。</li>
<li>c-basic-offset &lt; tab-width: emacs 按照 c-basic-offset指定的宽度缩进，全部插入空格。</li>
</ol>
<p>所以，如果我们期望缩进宽度和制表符宽度一致，必须加入最后那条语句。<br />
还有一点需要说明，多数mode都会使用c-basic-offset这个变量来控制缩进，但是python-mode是个例外。<br />
<code><br />
(setq py-smart-indentation nil)<br />
(setq tab-width 4)<br />
(setq-default py-indent-offset 4)<br />
(setq indent-tabs-mode nil)</code></p>
<p>python-mode使用py-indent-offset来控制缩进，其他的原理同上。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/24/feed</wfw:commentRss>
		</item>
		<item>
		<title>Note about s2mem and s2disk under Linux</title>
		<link>http://www.leezii.com/blog/archives/22</link>
		<comments>http://www.leezii.com/blog/archives/22#comments</comments>
		<pubDate>Sun, 05 Oct 2008 02:50:19 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=22</guid>
		<description><![CDATA[With the help of thinkwiki, s2mem  cost a little time to work fine.  If your computer resume immediately after s2mem, you should try:

modprobe -r uhci_hcd
&#160;
modprobe -r ehci_hcd

This remove the modules which would awake the computer aumatically. Surely, after your computer resume, you must load these modules for your USB devices.
S2mem is easy and [...]]]></description>
			<content:encoded><![CDATA[<p>With the help of <a href="http://www.thinkwiki.org">thinkwiki</a>, s2mem  cost a little time to work fine.  If your computer resume immediately after s2mem, you should try:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">modprobe -r uhci_hcd
&nbsp;
modprobe -r ehci_hcd</pre></div></div>

<p>This remove the modules which would awake the computer aumatically. Surely, after your computer resume, you must load these modules for your USB devices.</p>
<p>S2mem is easy and S2disk is not.</p>
<p>First, I got a error &#8220;write error: no such device&#8221; and i didn&#8217;t understand it . Which device is needed? Once I reboot the computer and found a message &#8220;Unable find swap signature&#8221;. Oh , I havn&#8217;t allocate swap space.</p>
<p>Such a stupid error. So</p>

<div class="wp_syntax"><div class="code"><pre class="bash">mkswap <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7
&nbsp;
swapon -v <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7</pre></div></div>

<p>OK, let me try</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #7a0874; font-weight: bold;">echo</span> disk <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>power<span style="color: #000000; font-weight: bold;">/</span>state</pre></div></div>

<p>Now, my computer can suspend. But when I press the power button to resume, it boot as like it never suspend. Why？&#8221;Unable find swap signature&#8221; reminds me. I should modify /etc/initramfs-tools/conf.d/resume. It should be like this: RESUME=/dev/sda7. Then</p>

<div class="wp_syntax"><div class="code"><pre class="bash">update-initramfs -u</pre></div></div>

<p>OK, after these, my computer suspend and resume fine.^_^</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/22/feed</wfw:commentRss>
		</item>
		<item>
		<title>Got my first notebook thinkpad x61!</title>
		<link>http://www.leezii.com/blog/archives/21</link>
		<comments>http://www.leezii.com/blog/archives/21#comments</comments>
		<pubDate>Fri, 26 Sep 2008 17:15:01 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[X61]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=21</guid>
		<description><![CDATA[Yestaday,  I got my first notebook thinkpad x61. It has a T8100 CPU, 2GB memory and 250GB HD. (You can find more detail at here. The first one is my type.) 9:25a.m, I got to the Harbin’ Branch of Digital China. There are two nice boys and they help me finish the process for getting [...]]]></description>
			<content:encoded><![CDATA[<p>Yestaday,  I got my first notebook thinkpad x61. It has a T8100 CPU, 2GB memory and 250GB HD. (You can find more detail at <a href="http://u.thinkworld.com.cn/think_u/machine.do?method=listMachine&amp;family=X">here</a>. The first one is my type.) 9:25a.m, I got to the Harbin’ Branch of Digital China. There are two nice boys and they help me finish the process for getting the computer. Nearly one hour later, I got back to my school with the thinkpad.</p>
<p>After lunch, I started to deal with the system: Windows Vista is there but I don&#8217;t like it. I prefer to linux, whick i am more familiar with. I use Debian lenny at usual time and you know I spend much time to configure it as I wish. So I want to move the whole system on my PC to the thinkpad. For that, I follow these steps:</p>
<ol>
<li>First of all, I pack the system as a file, a big file. Use this command: tar cvpzf backup.tgz &#8211;exclude=&#8217;/proc/*&#8217; &#8211;exclude=/lost+found &#8211;exclude=/ba<br />
ckup.tgz &#8211;exclude=&#8217;/mnt/*&#8217; &#8211;exclude=&#8217;/sys/*&#8217; / . It would create a file named backup.tgz at the root directory.  Wait a while^_^.</li>
<li> Then copy the file to the partition which I got ready for linux root directory at the X61. I used Acronis software to split the partition and size it 50GB and format it to ext3 fs. After the preparation, I copy the file to the partition. How to copy? you have many choices. i.e. , under Windows Vista you can use usb device or LAN to copy the file to NTFS fs partition(fat32 is not supposed because 4G filesize limit is end~), then use ext2ifs or other software to move the file to the ext3 partition. But I didn&#8217;t do it like that. I use a use disk whick is bootable. I installed slax over the usb disk. After booting from the usb disk, mount the ext3 fs, copy the file to it. Very easy.</li>
<li>The last step, even easier! Pack the big file, and you can guess it will cost some time. Use the command: tar xvpfz backup.tgz -C /. After that you should fix the grub. Everyone can do it!. Get to the directories which you packed and find the command&#8211;grub. Run it and get into the grub command interface. Then &#8220;root (hd0, 5)&#8221; and &#8220;setup (hd0)&#8221;, at last &#8220;reboot&#8221;.Notice : here I supposed the ext3 fs locate on /dev/*da6.</li>
</ol>
<p>Finish the three steps and you can boot linux at your X61~Even better, the system is configured as you wish!Of cource, some drivers are different between your X61 and PC.That&#8217;s next……</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/21/feed</wfw:commentRss>
		</item>
		<item>
		<title>ntfs-3g的效率如何？</title>
		<link>http://www.leezii.com/blog/archives/20</link>
		<comments>http://www.leezii.com/blog/archives/20#comments</comments>
		<pubDate>Tue, 16 Sep 2008 10:38:23 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[ntfs-3g]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=20</guid>
		<description><![CDATA[还是virtualbox崩溃引来的破事儿，重新安装了virtualbox 2.0非OSE版，接着就是安装windows 2003。随手抓了一张03的安装光盘，安装成功后再安装Office 2k3，令人郁闷的事情发生了：virtualbox提示文件大小超出限制～刚开始还没有反应过来，以前都是这么安装的呀？后来突然想到，我把虚拟机文件放到了fat 32分区，查看文件大小，确实4G了。以前安装成功，估计是那个版本的windows 2003精简过～无奈，格式化为ntfs，考虑到还需要在windows下访问这个分区。用ntfs-3g挂载分区后，开始安装。不知道是不是ntfs-3g的效率问题，CPU占用很高，速度还很慢，copy文件后的配置，平时20分钟就能完成，这次40分钟也搞不定。尝试了好几次，没办法，绕过这个问题吧，搞成ext3。如此这般，5次安装2003后，终于成功了。
]]></description>
			<content:encoded><![CDATA[<p>还是virtualbox崩溃引来的破事儿，重新安装了virtualbox 2.0非OSE版，接着就是安装windows 2003。随手抓了一张03的安装光盘，安装成功后再安装Office 2k3，令人郁闷的事情发生了：virtualbox提示文件大小超出限制～刚开始还没有反应过来，以前都是这么安装的呀？后来突然想到，我把虚拟机文件放到了fat 32分区，查看文件大小，确实4G了。以前安装成功，估计是那个版本的windows 2003精简过～无奈，格式化为ntfs，考虑到还需要在windows下访问这个分区。用ntfs-3g挂载分区后，开始安装。不知道是不是ntfs-3g的效率问题，CPU占用很高，速度还很慢，copy文件后的配置，平时20分钟就能完成，这次40分钟也搞不定。尝试了好几次，没办法，绕过这个问题吧，搞成ext3。如此这般，5次安装2003后，终于成功了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/20/feed</wfw:commentRss>
		</item>
		<item>
		<title>Search for proxies via python 续</title>
		<link>http://www.leezii.com/blog/archives/19</link>
		<comments>http://www.leezii.com/blog/archives/19#comments</comments>
		<pubDate>Tue, 16 Sep 2008 06:06:50 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[python]]></category>

		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=19</guid>
		<description><![CDATA[前几天virtualbox崩溃了，一直使用的花刺代理自然也不能使用了。教育网没有代理可怎么活？没办法，只好自己搞定了。上网搜索了一下，找到一个网友的代码，拿过来，稍微修改了一下，给经常使用的代理更高的优先级，添加保存所有的下载代理功能（原来的脚步只会下载验证成功的代理）。放在46上，好像还能用～
]]></description>
			<content:encoded><![CDATA[<p>前几天virtualbox崩溃了，一直使用的花刺代理自然也不能使用了。教育网没有代理可怎么活？没办法，只好自己搞定了。上网搜索了一下，找到一个网友的代码，拿过来，稍微修改了一下，给经常使用的代理更高的优先级，添加保存所有的下载代理功能（原来的脚步只会下载验证成功的代理）。放在46上，好像还能用～</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/19/feed</wfw:commentRss>
		</item>
		<item>
		<title>Search for proxies via python~</title>
		<link>http://www.leezii.com/blog/archives/18</link>
		<comments>http://www.leezii.com/blog/archives/18#comments</comments>
		<pubDate>Tue, 16 Sep 2008 06:02:28 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[python]]></category>

		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=18</guid>
		<description><![CDATA[
#!/usr/bin/env python
&#34;&#34;&#34;Get proxies from urls, and test their speed&#34;&#34;&#34;
import urllib, re, time, threading
urls = &#91;&#34;http://www.hitchina.net/taxonomy/term/14&#34;,
&#34;http://www.hitchina.net/taxonomy/term/15&#34;,
&#34;http://www.ipbbs.com/&#34;,
&#34;http://www.pass-e.com/proxy/&#34;,
&#34;http://www.haozs.net/ip.htm&#34;
&#93;		#where to get proxies
urls_proxy = &#123;&#125;		#proxy used to connect urls
proxy_pattern = re.compile&#40;r&#34;&#34;&#34;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,}&#34;&#34;&#34;&#41;
test_url = &#34;http://setiathome.berkeley.edu/&#34;
test_pattern = re.compile&#40;r&#34;&#34;&#34;SETI@home&#34;&#34;&#34;&#41;
time_out = 30.0		#max waiting time to test proxies
output_file = &#34;Proxies.txt&#34;
template = &#34;UserdefinedTemplate.pac&#34;
pac_pattern = re.compile&#40;r&#34;&#34;&#34;MyProxy&#34;&#34;&#34;&#41;
pac_file = &#34;proxy.pac&#34;
advProxy = &#91;&#34;http://219.217.250.3:3128&#34;&#93;
&#160;
class TestTime&#40;threading.Thread&#41;:
&#34;&#34;&#34;test a proxy's speed in new thread by [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Get proxies from urls, and test their speed&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>, <span style="color: #dc143c;">re</span>, <span style="color: #dc143c;">time</span>, <span style="color: #dc143c;">threading</span>
urls = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;http://www.hitchina.net/taxonomy/term/14&quot;</span>,
<span style="color: #483d8b;">&quot;http://www.hitchina.net/taxonomy/term/15&quot;</span>,
<span style="color: #483d8b;">&quot;http://www.ipbbs.com/&quot;</span>,
<span style="color: #483d8b;">&quot;http://www.pass-e.com/proxy/&quot;</span>,
<span style="color: #483d8b;">&quot;http://www.haozs.net/ip.htm&quot;</span>
<span style="color: black;">&#93;</span>		<span style="color: #808080; font-style: italic;">#where to get proxies</span>
urls_proxy = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>		<span style="color: #808080; font-style: italic;">#proxy used to connect urls</span>
proxy_pattern = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\d</span>{1,3}<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>{1,3}<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>{1,3}<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\d</span>{1,3}:<span style="color: #000099; font-weight: bold;">\d</span>{1,}&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
test_url = <span style="color: #483d8b;">&quot;http://setiathome.berkeley.edu/&quot;</span>
test_pattern = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;SETI@home&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
time_out = <span style="color: #ff4500;">30.0</span>		<span style="color: #808080; font-style: italic;">#max waiting time to test proxies</span>
output_file = <span style="color: #483d8b;">&quot;Proxies.txt&quot;</span>
template = <span style="color: #483d8b;">&quot;UserdefinedTemplate.pac&quot;</span>
pac_pattern = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;MyProxy&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>
pac_file = <span style="color: #483d8b;">&quot;proxy.pac&quot;</span>
advProxy = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;http://219.217.250.3:3128&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> TestTime<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;test a proxy's speed in new thread by recording its connect time&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, proxy<span style="color: black;">&#41;</span>:
<span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
<span style="color: #008000;">self</span>.<span style="color: black;">proxy</span> = proxy
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">time</span> = <span style="color: #008000;">None</span>
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">stat</span> = proxy + <span style="color: #483d8b;">&quot; time out!&quot;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
start = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>test_url, proxies = <span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;http&quot;</span>:<span style="color: #483d8b;">&quot;http://&quot;</span>+<span style="color: #008000;">self</span>.<span style="color: black;">proxy</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">stat</span> = <span style="color: #008000;">self</span>.<span style="color: black;">proxy</span>+<span style="color: #483d8b;">&quot; fails!&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
data = f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
end = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> test_pattern.<span style="color: black;">search</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>: <span style="color: #808080; font-style: italic;">#if data is matched</span>
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">time</span> = end-start
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">stat</span> = <span style="color: #008000;">self</span>.<span style="color: black;">proxy</span>+<span style="color: #483d8b;">&quot; time: &quot;</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
<span style="color: #008000;">self</span>.<span style="color: #dc143c;">stat</span> = <span style="color: #008000;">self</span>.<span style="color: black;">proxy</span>+<span style="color: #483d8b;">&quot; not matched!&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> totest<span style="color: black;">&#40;</span>proxy, result<span style="color: black;">&#41;</span>:
<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;test a proxy's speed in time_out seconds&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #dc143c;">test</span> = TestTime<span style="color: black;">&#40;</span>proxy<span style="color: black;">&#41;</span>
<span style="color: #dc143c;">test</span>.<span style="color: black;">setDaemon</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#print &quot;testing &quot;+proxy</span>
<span style="color: #dc143c;">test</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">test</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>time_out<span style="color: black;">&#41;</span> 	<span style="color: #808080; font-style: italic;">#wait time_out seconds for testing</span>
<span style="color: #808080; font-style: italic;">#print test.stat</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">test</span>.<span style="color: #dc143c;">time</span>:
result.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">test</span>.<span style="color: #dc143c;">time</span>, proxy<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
<span style="color: #808080; font-style: italic;">#get old proxies in output_file</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>output_file<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
allproxies = <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
allproxies = <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>x<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">-1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> f.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#get else proxies from urls</span>
<span style="color: #ff7700;font-weight:bold;">for</span> url <span style="color: #ff7700;font-weight:bold;">in</span> urls:
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;getting proxy from &quot;</span>+url
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url, proxies=urls_proxy<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
<span style="color: #ff7700;font-weight:bold;">pass</span>
<span style="color: #808080; font-style: italic;">#print url+&quot; can not open!\n&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
data = f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
allproxies.<span style="color: black;">update</span><span style="color: black;">&#40;</span>proxy_pattern.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> url+<span style="color: #483d8b;">&quot; finished!&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#test all proxies' speed</span>
result = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> proxy <span style="color: #ff7700;font-weight:bold;">in</span> allproxies:
<span style="color: #808080; font-style: italic;">#new thread to test every proxy</span>
t = <span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#40;</span>target=totest, args=<span style="color: black;">&#40;</span>proxy, result<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">setDaemon</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#show all proxies' speed</span>
<span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span>time_out<span style="color: #ff4500;">+5.0</span><span style="color: black;">&#41;</span>
result.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#bestProxy = result[0]</span>
<span style="color: #808080; font-style: italic;">#print bestProxy</span>
bestProxy = <span style="color: #483d8b;">&quot;&quot;</span>
candProxy = <span style="color: black;">&#91;</span>result<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> adv <span style="color: #ff7700;font-weight:bold;">in</span> advProxy:
<span style="color: #ff7700;font-weight:bold;">if</span> adv <span style="color: #ff7700;font-weight:bold;">in</span> candProxy:
bestProxy = adv
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> bestProxy:
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>result<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
bestProxy = result<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">break</span>
<span style="color: #808080; font-style: italic;">#print bestProxy</span>
<span style="color: #808080; font-style: italic;">#print str(i+1)+&quot;\t&quot;+result[i][1]+&quot;   \t:\t&quot;+str(result[i][0])</span>
<span style="color: #808080; font-style: italic;">#output needed proxies</span>
<span style="color: #808080; font-style: italic;">#num = min(abs(int(raw_input(&quot;\nHow many proxies to output: &quot;))), len(result))</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>output_file, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Can not open output file!&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
f.<span style="color: black;">writelines</span><span style="color: black;">&#40;</span>proxy + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff7700;font-weight:bold;">for</span> proxy <span style="color: #ff7700;font-weight:bold;">in</span> allproxies<span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#f.writelines([x[1]+&quot;\n&quot; for x in result[:num]])</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#print str(num)+&quot; proxies are output.&quot;</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>template, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Can not open template file!&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
data = f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#data = re.sub(r&quot;MyProxy&quot;, bestProxy, data)</span>
data = pac_pattern.<span style="color: black;">sub</span><span style="color: black;">&#40;</span>bestProxy, data<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>pac_file, <span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: #483d8b;">&quot;Can not open pac file!&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/18/feed</wfw:commentRss>
		</item>
		<item>
		<title>正式上课第一天～</title>
		<link>http://www.leezii.com/blog/archives/17</link>
		<comments>http://www.leezii.com/blog/archives/17#comments</comments>
		<pubDate>Mon, 01 Sep 2008 12:10:34 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[小记]]></category>

		<category><![CDATA[导师]]></category>

		<category><![CDATA[开学]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=17</guid>
		<description><![CDATA[2008年9月1日，我的硕士研究生生活开始了。
今天课不多，一门英语一门计算机网络与通讯，英语没去，计算机网络与通讯去了，听得挺认真，居然没有睡觉。
2008年9月1日，我的导师确定了，是姜守旭老师。熟悉姜老师的同学告诉我，说姜老师挺好的，要求很严，对学生很好。感谢遇到了一个好老师！
今天算是我们数据库中心的迎新会议，李建中老师也给大家谈了很多，给予大家很大的希望。今天我才知道，两年时间确实太短暂了，而需要我做的东西又那么多……没办法，加油吧，好好地学，明年，找个perfect work吧～
God bless me !
]]></description>
			<content:encoded><![CDATA[<p>2008年9月1日，我的硕士研究生生活开始了。</p>
<p>今天课不多，一门英语一门计算机网络与通讯，英语没去，计算机网络与通讯去了，听得挺认真，居然没有睡觉。</p>
<p>2008年9月1日，我的导师确定了，是姜守旭老师。熟悉姜老师的同学告诉我，说姜老师挺好的，要求很严，对学生很好。感谢遇到了一个好老师！</p>
<p>今天算是我们数据库中心的迎新会议，李建中老师也给大家谈了很多，给予大家很大的希望。今天我才知道，两年时间确实太短暂了，而需要我做的东西又那么多……没办法，加油吧，好好地学，明年，找个perfect work吧～</p>
<p>God bless me !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/17/feed</wfw:commentRss>
		</item>
		<item>
		<title>四年毕业，各奔东西</title>
		<link>http://www.leezii.com/blog/archives/16</link>
		<comments>http://www.leezii.com/blog/archives/16#comments</comments>
		<pubDate>Wed, 09 Jul 2008 16:58:14 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[小记]]></category>

		<category><![CDATA[分别]]></category>

		<category><![CDATA[毕业]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=16</guid>
		<description><![CDATA[四年时间转瞬即逝，眨眼之间我们毕业了。相对于以前的初高中毕业，大学毕业才是真正的毕业。四年时光，我们在这儿搭建一个自己的家；四年时光，我们在这儿找到新的亲人；四年时光，我们脱离父母，寻找自己的人生之路。毫不夸张地说，大学的四年，是我们真正开始融入到社会中去，我们真正长大成人的四年时光。我想，这四年是我一生永难忘记的回忆。
四年时光给我们留下了很多，有快乐，有痛苦，有无形的知识，有有形的行李。最后的短暂时光总是相似的，收拾行李打包，吃饭喝酒，送别某人，回来继续下一个循环。不得不承认，最触动人心的是送别，有人嚎啕大哭，有人有说有笑，有人用力握手，有人紧紧相拥。祝福总是真诚的，心情总是沉重的，而我，几乎总是沉默的。不想多说。
我总觉得那个时候特别不自在，因而今早特地走得早一些，没有和一些兄弟告别，哎~
]]></description>
			<content:encoded><![CDATA[<p>四年时间转瞬即逝，眨眼之间我们毕业了。相对于以前的初高中毕业，大学毕业才是真正的毕业。四年时光，我们在这儿搭建一个自己的家；四年时光，我们在这儿找到新的亲人；四年时光，我们脱离父母，寻找自己的人生之路。毫不夸张地说，大学的四年，是我们真正开始融入到社会中去，我们真正长大成人的四年时光。我想，这四年是我一生永难忘记的回忆。</p>
<p>四年时光给我们留下了很多，有快乐，有痛苦，有无形的知识，有有形的行李。最后的短暂时光总是相似的，收拾行李打包，吃饭喝酒，送别某人，回来继续下一个循环。不得不承认，最触动人心的是送别，有人嚎啕大哭，有人有说有笑，有人用力握手，有人紧紧相拥。祝福总是真诚的，心情总是沉重的，而我，几乎总是沉默的。不想多说。</p>
<p>我总觉得那个时候特别不自在，因而今早特地走得早一些，没有和一些兄弟告别，哎~</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/16/feed</wfw:commentRss>
		</item>
		<item>
		<title>致全体十四班同学的一封信zz</title>
		<link>http://www.leezii.com/blog/archives/13</link>
		<comments>http://www.leezii.com/blog/archives/13#comments</comments>
		<pubDate>Tue, 20 May 2008 03:34:18 +0000</pubDate>
		<dc:creator>firenet</dc:creator>
		
		<category><![CDATA[important]]></category>

		<category><![CDATA[地震]]></category>

		<category><![CDATA[意向]]></category>

		<category><![CDATA[捐助]]></category>

		<guid isPermaLink="false">http://www.leezii.com/blog/?p=13</guid>
		<description><![CDATA[有一个想法，就是在这次地震过后，失去双亲，或者是家庭深受地震灾害而经济困难的孩子，我们十四班，能够出一些人力和财力，对他们进行捐助。
我的想法是，在川外的朋友，如果资金允许，每年能出100元钱（更多当然更好），让我们在成都的十四班的同学和朋友管理；而在成都的朋友、同学，在周六日 或节假日抽出一点时间和精力，轮流把这些钱或者物资，负责送到扶助的她（他）手里。而且最好能抽出时间和精力去与被扶助对象沟通、交流。
这只是我的初步想法，有很多细节上的问题，等看看大家的反应再讨论和解决了。如果大家支持或者有别的想法或意见，都可以提出来，发在班级邮箱里，并请注意在班级邮箱里注明自己的姓名。谢谢大家！
邓富耀，唐光明
&#8212;&#8212;&#8211;***分割线***&#8212;&#8212;&#8211;
谈一下我自己的看法。我觉得这个想法很好，当然问题也很显然，很多细节都还没有想法或者实施的步骤，所以我建议大家把这个看作一个意向性的公告，我想，如果决定实施的话，那个时候还是应该有一个包含更多细节，令人觉得可行的报告。
PS:大家可以发意见到邮箱，也可以在这儿直接评论。Any question is welcome~
PS2:公共邮箱ybsyz0414@163.com 密码见群公告～
]]></description>
			<content:encoded><![CDATA[<p>有一个想法，就是在这次地震过后，失去双亲，或者是家庭深受地震灾害而经济困难的孩子，我们十四班，能够出一些人力和财力，对他们进行捐助。<br />
我的想法是，在川外的朋友，如果资金允许，每年能出100元钱（更多当然更好），让我们在成都的十四班的同学和朋友管理；而在成都的朋友、同学，在周六日 或节假日抽出一点时间和精力，轮流把这些钱或者物资，负责送到扶助的她（他）手里。而且最好能抽出时间和精力去与被扶助对象沟通、交流。<br />
这只是我的初步想法，有很多细节上的问题，等看看大家的反应再讨论和解决了。如果大家支持或者有别的想法或意见，都可以提出来，发在班级邮箱里，并请注意在班级邮箱里注明自己的姓名。谢谢大家！</p>
<div>邓富耀，唐光明</div>
<div>&#8212;&#8212;&#8211;***分割线***&#8212;&#8212;&#8211;</div>
<div>谈一下我自己的看法。我觉得这个想法很好，当然问题也很显然，很多细节都还没有想法或者实施的步骤，所以我建议大家把这个看作一个意向性的公告，我想，如果决定实施的话，那个时候还是应该有一个包含更多细节，令人觉得可行的报告。</div>
<div>PS:大家可以发意见到邮箱，也可以在这儿直接评论。Any question is welcome~</div>
<div>PS2:公共邮箱ybsyz0414@163.com 密码见群公告～</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leezii.com/blog/archives/13/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
