<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>半瓶墨水 - 任中方</title>
	
	<link>http://www.2maomao.com/blog</link>
	<description>兔毛猫(2maomao)的试验田</description>
	<pubDate>Sun, 11 Dec 2011 20:50:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/2maomao" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="2maomao" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>邮局，快递，还有修车的</title>
		<link>http://www.2maomao.com/blog/postman-story-about-professional/</link>
		<comments>http://www.2maomao.com/blog/postman-story-about-professional/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 01:24:37 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[原创精选]]></category>

		<category><![CDATA[思维像发情的猴子]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1443</guid>
		<description><![CDATA[最近有些感触，讲两个故事。
故事一：邮局和快递
如果你在网上下了一个订单，这个订单对你比较重要，你会用邮局吗？
邮局绝对不是我的首选。
有段时间，邮局是这样工作的：货物发出以... ]]></description>
			<content:encoded><![CDATA[<p>最近有些感触，讲两个故事。</p>
<p><strong>故事一：邮局和快递</strong></p>
<p>如果你在网上下了一个订单，这个订单对你比较重要，你会用邮局吗？</p>
<p>邮局绝对不是我的首选。</p>
<p>有段时间，邮局是这样工作的：货物发出以后，直到货物到达你手上，中途不会有任何消息，直到有一天货物到了，让你去签收。或者某一天你突然发现东西怎么还~~~没到，打电话过去查询，告诉你，没事，还在路上；有时候你会变得神经质，怀疑电话号码写错了，怀疑邮编写错了，怀疑地址写错了，怀疑收件人写错了；几个电话以后，你很沮丧，什么都没错，但是就是没到，到哪儿了？什么时候到？我也不知道，等吧。</p>
<p>虽然最后可能邮包到了，你对邮局开始有看法了。<br />
然后是第二次。<br />
然后是第三次第四次第n次。。。<br />
然后你就对对邮局彻底失去信心了。</p>
<p>快递呢？<br />
货物发出以后，给你发个邮件，告诉你收件人发件人联系信息等等等等，还有个链接，可以查结果</p>
<p>然后你就可以看到不断的结果更新：<br />
  到xx集散地了，<br />
  到xx机场了，<br />
  到北京了，<br />
  到回龙观了，<br />
  到某某分发处了，<br />
  到某个快递员了。。。</p>
<p>直到到达你的手中，你都会很踏实。</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>好吧，这个故事很平淡，好像没啥意思。但是工作中，“邮局”的事情每天都在发生。</p>
<p>某天，工头老张给员工小李安排了一个工作，小李说，好，我去做。</p>
<p>从此杳无音信。<br />
一个星期过去了。<br />
没有email，没有电话。<br />
连小李是不是还在干这个都不知道。<br />
这时候老张怎么想？</p>
<p><strong>如果你是小李，你该怎么做？你是邮局还是快递？</strong></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>故事二：修车的故事</strong></p>
<p>有天周末，下午两点，你去修车，打算修完以后晚上拉着女朋友去看演唱会。</p>
<p>先把车开到“<strong>卜靠谱</strong>汽车专修”，说，车有点儿问题，能给修修吗？</p>
<p>店老板说，好。然后他拿出了钳子扳手千斤顶，开始拆卸了。</p>
<p>这时候你会怎么想？ </p>
<p>！！他到底知不知道我要干嘛~~~~！！</p>
<p>你实在憋不住了，问他，你知道哪儿坏了吗？</p>
<p>他说，哦，对不起，我忘了问了，哪儿坏了？</p>
<p>你压着火，跟他说：车开着开着就没气了，开着还总回跑偏。。。blablabla，总算搞清楚问题</p>
<p>然后店老板再次上阵，千斤顶、钳子、扳手。</p>
<p>你等了半小时，总算明白过来，他是要给你换轮胎，而且还要换后车轴，估计要5个小时才能搞定了，一堆的￥￥￥在眼前飘过</p>
<p>这时候你又会怎么想？</p>
<p>天哪，你为什么不早说！！！<br />
能不能不换轮胎？！<br />
能不能不换后车轴？！</p>
<p>你提出问题来了，老板说，可以，补胎，后车轴其实调调也能用，换了更好。</p>
<p><strong>是不是很崩溃呢？下次你想修车，还会不会再光顾呢？</strong></p>
<p>然后这天你知道了一家“薪胖子放心店”，听说不错。</p>
<p>开去修车。</p>
<p>老板问清楚了状况，说需要几分钟检查一下。<br />
十分钟以后，查清楚了原因。<br />
然后给你两种解决方案，一种临时的一种长久的，价位都给出来了。推荐一个长久的（更换轮胎啊，￥￥￥）。<br />
问你看怎么办？<br />
你犹豫了一下，说先来临时的吧，晚上还要用呢。<br />
那需要半小时。<br />
没问题，我先切会儿水果。<br />
店老板嘁哩喀喳，搞定收工。<br />
然后你从fruit ninjia回落到现实世界，交钱开车走人。</p>
<p>多么和谐啊。</p>
<p><strong>好了，现在你被分配了一个任务，你打算怎么办？卜靠谱还是薪胖子？</strong></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fpostman-story-about-professional%2F&amp;linkname=%E9%82%AE%E5%B1%80%EF%BC%8C%E5%BF%AB%E9%80%92%EF%BC%8C%E8%BF%98%E6%9C%89%E4%BF%AE%E8%BD%A6%E7%9A%84"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/postman-story-about-professional/feed/</wfw:commentRss>
		</item>
		<item>
		<title>折腾 - 发芽网后台更新Python2.7.2, Django1.3, Pygments1.4, jQuery1.6.2</title>
		<link>http://www.2maomao.com/blog/bluehost-python272-django13-pygments14-jquery162/</link>
		<comments>http://www.2maomao.com/blog/bluehost-python272-django13-pygments14-jquery162/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 10:28:06 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[DJango]]></category>

		<category><![CDATA[发芽网开发记录]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1433</guid>
		<description><![CDATA[发芽网后台更新了：Django1.3, Python2.7.2，jQuery1.6.2，Pygments1.4
其中Pygments的更新带了更多的语法高亮支持，包含了许多人熟悉的AutoHotkey
话说，似乎是临时的，很多的国外网站都没法访问了，连ssh... ]]></description>
			<content:encoded><![CDATA[<p>发芽网后台更新了：Django1.3, Python2.7.2，jQuery1.6.2，Pygments1.4</p>
<p>其中Pygments的更新带了更多的语法高亮支持，包含了许多人熟悉的<a href="http://www.autohotkey.com/">AutoHotkey</a></p>
<p>话说，似乎是临时的，很多的国外网站都没法访问了，连ssh也不可用了，这些网站都是技术性网站，应该没问题的，加上vpn就可以访问了，奇怪的是，用vpn也访问不了twitter了，难道传说中的白名单制度开始试水了？Fuck GFW! @ 2011-08-21, 18:47:11</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>最近有人在<a href="http://fayaa.com/code/feedback/">代码发芽网上留言</a>问能不能加上AutoHotkey的高亮支持，瞄了一眼<a href="http://pygments.org">Pygments</a>的新版本1.4，发现已经支持了，打算搞过来。另外发现发芽网后台的Django和Python以至于jQuery都老了，想起前几天看到<a href="http://www.ruanyifeng.com/blog/2011/08/jquery_best_practices.html">阮一峰介绍新版jQuery性能的文章</a>，据说快了很多，决定把这些一起更新一下，折腾开始了，且看一个业余的网页开发者会遇到多少问题。。。</p>
<p><strong>1. 首先，参考<a href="http://www.2maomao.com/blog/your-own-python-on-bluehost/">以前的文章&#8221;configure your own python 2.5.2 on bluehost&#8221;</a>安装Python2.7.2</strong>，下载编译安装，搞定。顺手改了.bashrc，这样下次ssh到服务器用的就是2.7了</p>
<p><strong>2. 然后，下载easy_install的egg包，用 sh xxx.egg 安装完毕</strong>，然后，easy_install安装了发芽网依赖的库：django1.3, PIL, flup, MySQL-Python, Pygments1.4, markdown2, python-openid，为了用起来顺手，又安装了ipython</p>
<p><strong>3. </strong>然后，参考以前的文章<a href="http://www.2maomao.com/blog/bluehost-django-fastcgi-static/">Bluehost Django fastcgi配置, 静态(static)文件处理</a>更改了t.fcgi，指向新的python库</p>
<p><strong>4. 然后到后台杀死所有t.fcgi进程，网站立马不可访问了，500 Error</strong>或者干脆半天都不返回，杯具。 </p>
<p><strong>5. 查吧，一个个查，根据多次折腾的经验，觉得应该是t.fcgi里面出异常了</strong>。这个好办（现在说好办，当时也想了半天），因为t.fcgi也是python脚本，直接执行之，居然没有发现任何问题，突然发现，t.fcgi最上面一行，对，就是指定python可执行文件地址的地方，用的还是python2.5，sigh，亏我还在以前的文章里专门写过注意事项。</p>
<p><strong>6. 再次杀死进程，打开网站，nnd，依然是挂的</strong>，再次执行t.fcgi，这次报了异常 - flup库没有安装，晕倒（前面步骤2里是全的，当时忘了装了），再次执行，没有啥问题了&#8230;&#8230;&#8230;中间由于每次fail都会发日志给我的邮箱，还遇上了bluehost发email的限制，不得不在Django配置文件里打开了Debug=True调试选项</p>
<p><strong>7. 再次杀死进程，打开网络，tnnd，依然是挂的</strong>；好吧没关系，就放我换个姿势再来一次，在发芽网源文件目录底下，敲入python manage.py runserver，对，就是起了一个本地Django Server，果然起不来，但是可以看到异常了，看出来似乎是PIL里面出的问题，错误信息是MemoryError还提到了ctypes，肿么办？这个吓不倒我，<a href="https://encrypted.google.com/search?hl=en&#038;newwindow=1&#038;btnG=Search&#038;lr=&#038;q=MemoryError+%2B+ctypes+%2B+Django+%2B+PIL">Google之</a>，发现<a href="http://stackoverflow.com/questions/5914673/python-ctypes-memoryerror-in-fcgi-process-from-pil-library">这篇文章</a>，里面说，打开$HOME/lib/python2.7/ctypes/__init__.py，找到CFUNCTYPE(c_int)(lambda: None)，注释掉它就ok但是不知道到底为神马。我打开一看，里面居然有一段注释，意思是，写这几行代码的人也不完全清楚为什么要写这行代码：</p>
<pre class="ohmycode">
# XXX for whatever reasons, creating the first instance of a callback
# function is needed for the unittests on Win64 to succeed.  This MAY
# be a compiler bug, since the problem occurs only when _ctypes is
# compiled with the MS SDK compiler.  Or an uninitialized variable?
CFUNCTYPE(c_int)(lambda: None)
</pre>
<p><strong>8. </strong>这样的神问题都碰上了，我像个小强一样挺了过来，注释掉这一行，居然，就搞定了~~~</p>
<p><strong>9. 终于，发芽网可以打开了，世界和平了</strong>，王子和公主从此过上了幸福的生活~~~直到，我发现admin页面无法访问了</p>
<p><strong>10. </strong>这时候我大概已经患上了斯德哥尔摩综合症，看到这个问题，居然虎躯一震，精神焕发，查起了Django1.4的文档，发现，<a href="https://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf">urls.py里面有个地方要改改</a>了。这么快就搞定，很是乏味啊~</p>
<p><strong>11. 终于成功的打开了admin页面，发现页面布局有些古怪</strong>，突然想起以前发的另一篇文章<a href="http://www.2maomao.com/blog/bluehost-django-admin/">Bluehost上架设Django之Admin</a>，原来admin_media还是指向以前安装的1.1的，删掉链接文件重新ln一下，搞定</p>
<p><strong>12. 终于，看起来一切正常了</strong>，siteuptime服务告诉我说 back to normal 。。。咚咚呛</p>
<p><strong>13. 然后发现代码发芽网贴代码以后，看起来就是一片漆黑</strong>，用chrome的developer tools验证了一下，原来所有的jQuery.ajax调用都会跑到异常分支里去，加上了几行代码发现报错 Unexpected token 。继续Google关键字Unexpected token和jQuery，发现<a href="http://stackoverflow.com/questions/5276790/jquery-1-5-1-breaks-all-ajax-calls">stackoverflow上面有个帖子</a>说这个事情，居然是个<a href="http://bugs.jquery.com/ticket/8302">jQuery的bug</a>？jQuery会把返回结果当成json进行eval，当然会有些问题啦，于是把所有的ajax调用里面都加上了一句 dataType: &#8216;text&#8217; 之后，一切ok了</p>
<p><strong>14. </strong>至此，好像一切都好了，第二天，tianyi song同学给我写信，<strong>问我为什么代码发芽网不能用了？</strong>还给我发来了截图。来回交流了几次，发现我原来的代码里对Pygments的一个格式有严格依赖，在Pygments1.4里面这个格式有些改动，没办法，把Pygments源码里面html.py这个formatter改了几行，总算搞定了</p>
<p><strong>15.</strong> 篇幅限制，省略细节问题十数条，还会遇到神马问题？期待~~~</p>
<p><strong>经验总结</strong>：</p>
<p>1. 不要怕，找到问题，细心分析，想各种方式去debug，搜索Google，大不了去看代码</p>
<p>2. 本地环境和部署的环境的一致性很重要，Service Engineer很重要啊，要想再更新的同时网络不下线，没有SE的支持是很困难的</p>
<p>3. 做个大网站，没有unit test也没有测试团队，那是不可能地~</p>
<p>btw, 或许有人问，搞这么多问题，就为了一个小小的网站，值吗？</p>
<p>值！兴趣是无价的，折腾是永恒的~~~在折腾中学习就是爽~~~！</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fbluehost-python272-django13-pygments14-jquery162%2F&amp;linkname=%E6%8A%98%E8%85%BE%20-%20%E5%8F%91%E8%8A%BD%E7%BD%91%E5%90%8E%E5%8F%B0%E6%9B%B4%E6%96%B0Python2.7.2%2C%20Django1.3%2C%20Pygments1.4%2C%20jQuery1.6.2"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/bluehost-python272-django13-pygments14-jquery162/feed/</wfw:commentRss>
		</item>
		<item>
		<title>zz: 爱的规则，自由的条件</title>
		<link>http://www.2maomao.com/blog/love-with-rules-and-freedom-with-condition/</link>
		<comments>http://www.2maomao.com/blog/love-with-rules-and-freedom-with-condition/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 07:16:31 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[宝宝我爱你]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1427</guid>
		<description><![CDATA[zz from: http://www.zreading.cn/archives/2417.html
非常有意思的文章，对其中的观点很是赞同，可以学到了一些和孩子相处的方法
一、饮水机事件
女儿快一岁时，对什么都好奇，尤其对饮水机的开关好奇... ]]></description>
			<content:encoded><![CDATA[<p>zz from: <a href="http://www.zreading.cn/archives/2417.html">http://www.zreading.cn/archives/2417.html</a><br />
非常有意思的文章，对其中的观点很是赞同，可以学到了一些和孩子相处的方法</p>
<p><strong>一、饮水机事件</strong></p>
<p>女儿快一岁时，对什么都好奇，尤其对饮水机的开关好奇，她外婆带着她很担心，一直看着并不停阻止，要知道这是很难的事，大人总有走开的时候，而女儿在学步车里是可以到处走动的。于是我决定不用看着了，饮水机的开关并不很危险，只要一放手水就会停，与其一直提心吊胆地看着不如让她烫到一次来得有用，很快她给烫到了，并记住了这是危险的，在很长一段时间内没有再去触摸。顺便我告诉她我们阻止她是因为这个东西是有危险的，所以要记住，大人阻止你动的东西都有道理，别以为一岁的小孩不懂，其实他们会听明白。好吧，应该是女孩明白得早一点，男孩会晚一点。</p>
<p><strong>二、插座事件</strong></p>
<p>女儿快两岁时，对墙上的插座孔很感兴趣，于是我拿来了她的录音机，告诉她墙上的孔里有电，是录音机需要的，插插头的时候需要拿着后面的塑料部分，这才安全，如果拿了前面的两片金属是会死的，而且手湿的时候插插座也是会死的。女儿对死还是很敬畏的，虽然未必明白具体会怎样，但总之是一件很不好很可怕的事。在两岁不到的日子里她学会了插插座，从那天起我们经常叫她XX来帮我插一下这样那样的插座，她也经常拖着她的录音机这个房间听听，再拖到那个房间听听，不用求我们帮她了。好吧，她很安全地活到了现在，从没触过电，我也没再担心过她会触电，我甚至曾告诉她，如果看到一根金属线你想知道是否带电，可以用手背靠上去试一下，有电的话会打到你，会有点痛有点麻，但记住千万不能用手心去抓，手背碰到会弹开，没危险，手心碰到会抓紧，那就是要命了。</p>
<p><strong>三、穿衣换挨PP</strong></p>
<p>女儿两岁时洗完澡衣服都是自己穿，可是自己穿的新鲜劲过掉后，会想办法偷懒。某日洗完澡，穿了一大半的衣服，对我说，老妈，你帮我穿衣服吧。我非常愉快的说，可以，不过有条件的，帮你穿一件一服你让我打一下吧，我很喜欢你PP打上去的手感。她考虑了一下同意交换，于是我帮她穿了两只袜子换到了两下PP，至今我仍记得那两下打得我手发痛。打完后她的脸色非常尴尬，而我又非常陶醉地在那儿夸她PP打上去的手感有多好，会让人打着上瘾。。。。。。</p>
<p>第二天，穿衣服时我相当嗨皮滴主动要求帮她穿衣服，并再三申明太喜欢打她PP的感觉了，希望她能再给我个享受的机会。</p>
<p>当然，直到现在我也没能再找到这个机会享受。</p>
<p><strong>四、自己回家</strong></p>
<p>女儿两岁半了，在小小班里也上了一段时间了，深深懂得红灯停绿灯行的规则。</p>
<p>有次我带她去逛街，在闹市区跟她说，我要去单位一下，问她是否能认识回家的路，可否自己回家,当然她认为没问题，于是我远远跟在她后面，看她如何回家。女儿很认真地在每个路口等红绿灯，甚至在其中一个路口等到了第六个绿灯的时候才过。事后我才知道，她不单只看绿灯，过的时候还要看看有没有别的车可能在闯红灯，确认100%的安全才通过。</p>
<p>其实孩子为自己负责的时候，远比大人认为的更有责任感。</p>
<p><strong>五、虫子是非常可爱的生物</strong></p>
<p>我是非常害怕那些软趴趴的肉虫，虽然知道这东西其实是无害的，但就是害怕啊。</p>
<p>小孩是不懂得害怕的，我的私心是要教女儿不怕以后可以帮我挡虫子。于是某天一只有虫的桃子，我告诉她有虫的桃子更甜，而那里面的虫子是非常可爱的，肥肥白白，还会爬动。女儿问那虫子不会咬我吗，我回答，这些虫子都是吃素的，而你是荤的，对于虫子来说也太老了咬不动。</p>
<p>女儿相当相信，她把虫子抓在手里看它爬来爬去，手心手背来回爬，左手爬到右手右手爬回左手，吃饭时把那条虫子放在桌子上看着虫子吃饭，爬远了抓回来继续看。我，我，我尖叫压在喉咙里，还不能做出害怕的表情，如果我有一点害怕的样子，从此女儿就会对无害的虫子一直莫明害怕，我一直想不起那次我是怎么把饭吃完的。</p>
<p>她开始把各种大大小小的青虫带回家养，终于我的神经变得异常坚强了，居然不再害怕这些肥肥软软的虫子了，然后发现居然有些青虫长得圆头大脑相当卡通。我们一直希望会养出蝴蝶来，事实证明，所有这些青虫最后都长成了大大小小的飞蛾。</p>
<p><strong>六、性教育</strong></p>
<p>每个小孩都会问自己从哪来，我一直在等，终于她问了，我于是带她去买了两张人体的解剖图，又找了两张外形图。然后详细解说了所有的器官，每个器官的功能，当然也包括了男女不同的生殖器官，她是由何而来再如何出来。总结就是怎么进来就怎么出去，只不过进来的时候要显微镜才能看得到，十个月后出来时已经是很大个的婴儿了。只不过是普通知识而已，实话实说，我这样认为，女儿于是也这么接受，一点也没什么神秘的。在了解得这么透彻后，女儿不再对此感兴趣，别人逗她时，她会一脸平静滴详细告诉他们自己由何而来，每个人都是这样出来的。</p>
<p><strong>七、躺在地上哭</strong></p>
<p>女儿很少用哭闹作为手段来达到目的，因为一次也没成功过，上了小小班后看到了成功案例，于是活学活用，在某天为了和我们一起吃白粥还是要单独给她下面条躺到了地上。我们全家该干嘛就干嘛去，当她空气。这里要感谢我的老妈，她更是开始了扫地，当扫到女儿躺的地方时，对她说，来来躺过去一点，这儿我要扫地，别挡着，我扫玩了你再躺回来。于是女儿挪地继续躺着哭，一会又说，好了，我把这儿扫干净了，你可以躺回来了。两岁半的女儿居然真的又躺回原来的地方来哼哼唧唧。我们全家都躲了起来狂笑。当了半小时空气的女儿终于发现别人的成功案例在她身上成功不了，爬起来讨好的说，我觉得其实白粥也是很好吃的，说完自己P颠P颠跑去把白粥吃了个干净。</p>
<p>直到现在，我也再没看到过她躺在地上哭闹作为达到目的的手段。其实小孩子很多行为只不过是试探，第一次就阻止，基本不会有第二次同样行为发生。</p>
<p><strong>八、不吃饭是自己的损失，不是别人的</strong></p>
<p>某天与我饭前吵架，饭桌上把碗重重一放恶狠狠地说，看到你就烦，我不吃了。我马上说，可以，不过一直到下次吃饭你都不可以吃任何东西。女儿开始有点心虚，继续说我不是说我不吃，只是不跟你一起吃，等你吃完我再来吃。我回答她，要么现在一起吃，要么你留着下顿再一起吃，没有第三个选择。她气鼓鼓说那我不吃了。</p>
<p>我们吃完把台子理掉，开始笑嘻嘻地讨论，怎么有这么傻的人，居然拿不吃饭来要胁别人，自己不吃饭饿的又不是别人，笑死人，居然拿饿自己要胁别人，哈哈哈哈哈。。。。。。。于是以饿一顿饭的代价，女儿明白了拿伤害自己来要胁别人，是很蠢的事。类似的事再也没在她的生活中出现过。</p>
<p><strong>九、有限的玩具，无限的乐趣</strong></p>
<p>女儿从小到大的玩具极其有限，电动的基本没有，所有的玩具拿个大袋子也就可以装起来了。</p>
<p>这么少的玩具，不是因为经济原因，是因为小孩子玩具越少越简单，注意力就越容易集中，想象力就越丰富，就越懂得珍惜东西。</p>
<p>小孩子都喜欢玩水，女儿也不例外，我的条件是，玩水可以，但只限卫生间，并且玩好要自己把卫生间弄干净。一个小桶一个盆，一只空可乐瓶，外加一个漏斗，一只小匙可以消磨掉整整下午的时间，她会把桶里的水用小瓶盖或小匙一点一点弄到大可乐瓶中，有时用漏斗有时不用，加满一瓶倒进盆里，盆里满了再用同样的方法把水弄进桶里，有时把上述各种大小工具按到桶里按到盆里，加满水按不加水按半加水按，正着按反着按，想象成各种情况，一个人玩得不亦乐乎，并且从没玩腻过。</p>
<p>小班时，女儿就可以坐在那儿一两个小时，集中专心地做一件事。</p>
<p>天线宝宝当时是女儿最爱看的节目，商场里也有卖，她很喜欢，于是我告诉她，在她生日的时候可以拥有一个，她可以在四个中挑一个，第二年的生日她等到了第二个天线宝宝，在漫长的等待后得到的东西都是值得珍惜的。从小时起她最想的东西都需要经过等待才能得到，最长的等了整整一年。于是现在她对东西都是很珍惜，很明白价值，并且想要什么都会考虑清楚是否真的需要。</p>
<p><strong>十、学写字是需要配额的</strong></p>
<p>该学写数字了，买了一本描红，交给女儿，然后告诉她，这个是有配额的，每天只能写半页，不可超过。</p>
<p>小孩子学东西，一开始总是非常有兴趣的，恨不能一下写掉半本，每天写到很高兴的时候，配额用完了，本子收掉了，求也没用，只能明天再写。于是养成了习惯，每天一定要写掉半页才高兴。很轻松愉快地完成了学写数字这个过程。</p>
<p>关键是要保持神秘，一直要吊着她，提起她的兴趣与好奇心，把求她学写字，变成她来求你要多写，但一定不能答应，继续用配额来吊着她直到任务完成。</p>
<p><strong>十一、分享</strong></p>
<p>女儿两岁不到（突然发现大多行为的纠正塑造都发生在三岁以内），她外婆经常买小虾挤虾仁炒给她吃，有次我看到了，就拿筷子夹了几个尝尝，女儿说你怎么吃我的虾仁。我回答谁说是你的虾仁，拿起勺子狠狠两勺吃掉一半，女儿反应过来，手忙脚乱来跟我抢吃，可是，她怎么抢得过我，怎么抢得过我。。。。。。嘿嘿！女儿看着空掉的虾仁碗眼泪下来了，我跟她说，东西谁都可以吃，没有什么东西是你一个人的，大家想怎么吃就怎么吃。从那天开始凡她喜欢吃的我都一定分走一半，小孩子就是好教，她很快习惯了与人分享。</p>
<p>有时候看到她特别喜欢吃的东西，我们想让她多吃一点，会说我牙痛咬不了这东西，或是这东西我不太喜欢。。。。。。等等看起来很合理的借口，你帮个忙帮我吃掉吧，一定要用求她的口气，让她觉得她是在帮你的忙（当然这种事不能做得太多，多了就没意思了），这时女儿会吃得欢天喜地，这是意外得到的快乐。如果没有学会分享，孩子会认为这是他应得的，并没有觉得开心，但是只要被别人分掉哪怕一小口都会生气；而习惯分享的孩子哪怕是多吃到一口都会觉得意外与开心。少吃点不会对人生有影响，懂得分享，容易得到快乐的心态会让孩子终身受益。</p>
<p><strong>十二、自己搞定</strong></p>
<p>比较小的时候（哪一年真忘记了，但一定是三岁不到）晚饭后天天带她下楼玩，广场上很多小孩，有些小孩会带些玩具下来，女儿有时会想去玩又不敢说，就求我帮她去说。当然我一口拒绝，告诉她，这是你想玩的东西，要么你自己去商量借来玩，要么就不要玩。忍了几天，终于她走出了第一步自己去借了一样玩，当然有时候会借不到，但大多数的时候还是能成功借到。只要成功一次，以后的事就好办得多，孩子都是自来熟的生物啊。后来她发现带样玩具下去，跟人交换玩更容易玩到自己想玩的东西，好吧，你自己搞定了。</p>
<p><strong>十三、失败的天赋训练</strong></p>
<p>孩子小的时候完全依赖成人才能存活，他们不能保护自己，于是老天给他们一项天赋，那就是精细分辨成人的语气作出判断，略大一点他们会对生活的环境观察细微，哪怕一点微小的变化都能发现，这也是天赋或者说动物的本能，因为他们不能保护自己，所以对环境变化异常敏感。当孩子一两岁的时候，几乎所有的父母都会发现孩子非常有观察力，而且近乎过目不忘，这时父母会惊喜，但很快，当他们长大，能力越来越强，天赋会逐渐消失，如何保持这稍纵即逝的天赋呢。</p>
<p>这点来说，我是失败的，方法很简单，但是持之以恒至少到六岁。。。。。。很遗憾，机会错过了就不会再有。</p>
<p>每天晚上给孩子读一段故事，当孩子会开口讲话后，让他把昨天的故事复述出来，讲不出来再读一次（请相信孩子的记忆天赋），能复述出来就继续读下一段，由短到长日复一日，持之以恒，五六岁时，你会发现，孩子可以过耳不忘，头天晚上听过一遍的大篇故事，第二天晚上可以几乎一字不差的背出来。后期因为可以完全背出故事，自己拿书来念，对照着书认字简直是水到渠成的事。这需要父母有强大的耐心与恒心（自责一万遍），每个孩子其实都是过目不忘的天才。</p>
<p>我表妹成功了，当我失败后才明白她的父母得有多强大才能造就她这样的天才。</p>
<p><strong>十四、跌倒了，出血了</strong></p>
<p>女儿在外头跌倒了，爬起来后发现皮破了不少，出血了，紧张了。我蹲下观察后，笑嘻嘻地对她说，啊，出血了，我们回去找个碗把这血盛起来吧，还能烧锅血汤呢，很补的，别浪费啦。女儿紧绷的神经一下就放松了。</p>
<p>回到家，我拿出酒精帮她消毒，先跟她说明，这个是消毒用的，抹在破掉的皮肤上可能会很痛，但是呢，不忍这个痛，可能伤口就会感染，也许就会烂掉这块肉，到时候肉掉了更痛，或者细菌进到血液里得了败血症，那就会死。女儿想了想，说，那你就消毒吧，我可以忍一下。</p>
<p><strong>十五、补牙</strong></p>
<p>女儿上小小班后，终于戒掉了叼着奶瓶睡着的习惯，但她的两颗门牙因为长期泡在奶里，蛀掉了点，于是我计划带她去修补一下，省得越蛀越大。</p>
<p>事先告知女儿，她的牙蛀掉了，如果现在不处理，发展下去会危害到她的恒牙，如果带她去修补牙齿，处理的时候可能会有点痛会出点血，但都不会太厉害，然后问她，你看是不是要去修补一下。女儿表示赞同。坐到牙医的椅子上，医生不敢下手，我只得再次当医生面问了女儿一次，得到再次肯定后，医生战战兢兢地动了手，整个过程女儿张大嘴巴木头一般一动不动，事后跟我说，你说会有点痛，其实一点也不痛。看多了坐上椅子就象杀猪一样的孩子，医生反到很不能适应这么冷静来补牙的小孩。</p>
<p>为什么女儿会这么冷静呢，因为我事先告知了可能会发生的情况，比如痛，比如出血，她有了心理准备，也就不怕了。孩子哭闹反抗或许更多的不是因为痛，而是对未知伤害本能的恐惧。</p>
<p>所以别以为孩子小，骗骗就可以了，他们会记得你骗过，会不信任你，下次再骗就没那么容易了。也不要低估孩子的承受能力，说实话会让他们更信任你，让他们对可能的疼痛作好心理准备，他们其实是很能忍痛的小生物。</p>
<p><strong>十六、体罚</strong></p>
<p>再乖巧的孩子，也总有把父母惹到怒发冲冠，恨不能一巴掌拍死的时候，否则那就不是孩子是木偶了。</p>
<p>某日，我很担心自己会忍不住对着女儿一巴掌下去，好出出心里这口鸟气。但是怒气是这样的，忍着也许会内伤，一旦动手却会象黄河溃堤，可能一掌接一掌收不了手，好多暴打孩子的父母借口是为孩子，其实更多是为了出自己心头的一口气。这是自己的女儿，所以只能内伤。</p>
<p>我对女儿说，最后提醒你一次，如果再犯我就要打你了，犯一次打一下，犯两次打两下，第三次打四下，每次加倍。女儿说，不行。我说，补充条件，受罚时你得自己脱好裤子床上挨打，如果你不肯，那我捉住了打，打一下的变两下，打两的变四下，总之加倍。</p>
<p>她挑战我，挑战我，挑战我。。。。。。最后我让她可以自由挑个地方受罚，她挑了房间，并清场不得围观，锁门，自己脱裤子挨打。对她来说，这是很丢脸的事，但也是很有效的管教办法，一般情况下只要提醒了一次立下规矩，为免再次丢脸挨打，就会遵守规定。</p>
<p><strong>三岁见老之我见：</strong></p>
<p>这句古话经常听过，但不很明白，女儿出生后，在教养中慢慢发现，古人真是太TMD（加重语气）有智慧了。</p>
<p>专家说要温情教育，要给孩子讲道理。三岁以内的孩子，听得懂大道理吗？也许。但更重要的不是给那么小的小孩讲道理，最重要的是先立规矩，一岁的孩子也会明白“不行”这个词。如果孩子错了，哪怕孩子再小也不能姑息，一定要马上阻止，并正确引导其行为，不要相信孩子大了自然会明白这种说法，只要在第一次就坚决阻止错误，孩子很快会明白并做出正确的行为。一旦孩子的偏差行为养成了习惯再阻止就难得多，孩子也会无所适从。三岁之内，孩子的大多数行为习惯都已形成，如果一开始就不断纠正矫正，就不需要后期反复地为一个个偏差纠缠，后续的教育也就会越走越顺。</p>
<p><strong>十七、绣花还是跳舞</strong></p>
<p>某天，女儿的外婆对我说，你来跟她说吧，她比较肯听你的话，幼儿园办课外班，女孩子么让她去学跳舞最好，可是她不肯，要去绣花。</p>
<p>我叫来女儿，问她，是不是要上课外班，她说是，我说，那你想上什么班呢，女儿说，我想学绣花，我还没绣过呢，可是外婆要让我去学跳舞。</p>
<p>我：不用理外婆，那是你上课，不是她去上，你想上什么课是你的自由，别人管不着，但是既然是你自己的选择，就得为自己负责，认真学好。</p>
<p>期末，女儿遗憾得说，我才绣了A和B，C字绣了一半课就结束了，没得绣了。</p>
<p><strong>十八、自己的行为自己负责结果</strong></p>
<p>小区里很多孩子，女儿由于不娇气做作，很能自来熟。</p>
<p>一天女儿问我，能否带小朋友来玩，我回答，这个家也是你的，你可以做主，如果带小朋友来玩，你们可以任意，但最后得把一切恢复原状，由于是你带来的朋友，所以你要负责。</p>
<p>孩子们非常喜欢来我家，因为自由。通常我会对他们视而不见，他们玩他们的，我做我的，而女儿会负责招待，吃的也好，玩的也好，全由她自己做主。</p>
<p>有时候玩得高兴会把地上弄得一团乱，临走，女儿会组织他们清理干净。如果走前没清理干净，最后就由女儿自己清理。这是我们说好的，她做了主人，她负责结果。</p>
<p><strong>十九、包子的底限</strong></p>
<p>女儿平时表现得很包子，不太跟人计较，从没见过她与朋友争吵不愉快。她外婆一直很担心，每每报怨我把女儿教成包子，以后是会吃亏的。</p>
<p>大班时，她带回个同学玩，决定送同学一本书。两堆书，一堆是她看过的，一堆是没看完的，女儿让同学在她看过的一堆书里挑选一本，但是她同学坚持要一本她没看过书。女儿坚持，她同学也坚持，于是女儿说，这本书我没看过，不可以送给你，但可以借给你，我写一张借书证，你签好名，看完了还给我。两个孩子认真的做了一张借书卡，签下大名,写下日期。</p>
<p>包子只是表面现象，始终有底限，当触碰到底限时，会想出办法解决，不与朋友造成冲突。父母从小放手才能逼着她找办法解决自己的问题，这个也是很需要锻练滴。</p>
<p><strong>二十、写作文</strong></p>
<p>上小学，老师要求写作文，女儿写不出，要我教。我把她带到电脑前，教她打开谷歌，模糊输入作文题目，按下搜索键，然后告诉她，这些都是你需要的作文，挑着抄吧，不过，你们老师应该都有看过，所以整篇的抄呢很容易被发现，你得多找几篇拼在一起抄。抄作文这种事一回生两回熟，三回四回就经验丰富了。</p>
<p>为什么教女儿抄作文呢，一二年级的孩子，词汇量很少，很难写出生动的作文，最好的办法就是抄别人的。当她把多篇文章拼凑在一起时，必须仔细研读所有的文章，挑出可用的词句段落，并想办法把这些连贯起来成为一篇完整的作文。</p>
<p>嘿嘿，我很懒，但是这个办法的确很有效。</p>
<p><strong>二十一、做作业到十点</strong></p>
<p>一二年级，因为学校离外婆家很近，于是就住在外婆家，可是居然常常做作业到九十点钟，开始大人报怨学校作业太多，后来跟她的同学交流后发现，同样的作业有的六点前就完成，有的孩子和女儿一样要做到九十点。其实女儿并没有专心认真做作业，边玩边做当然就这样了，后来有段时间她外公天天看着她做，但要别人看着才做的事并不很有效。于是，非常懒的楼主出现了。其实我只是很认真地对她说，我知道你们的作业量，从今天起每天作业最晚做到8点，8点以后再敢做作业，我就把本子扔了。女儿反抗，那我就告诉老师，是你不让我做完作业，我才交不出。我笑，那你就去跟老师说好了，反正交不出作业的人是你不是我，写到黑板上的名字是你不是我。女儿无奈，整整一个月，我天天去看她，整整一个月，她的作业都在六点前完成，然后，就养成了习惯，不用看着都能很快专心地完成。</p>
<p>为什么这次能这么轻易就改正了她的坏习惯呢，其实有两个必要的条件:</p>
<p>一是从小我就灌输她的人生必须她自己承担责任，我绝对不会为她负责，也是一直这样执行，所以她知道我说的都是事实，交不出作业她得自己承担后果。</p>
<p>二是从小我立下的规矩都是一定会执行，没有或许也许下次之类，所以我说8点后再做就扔了她的本子，虽然没有真的执行，但她知道只要违反我就一定会执行。</p>
<p><strong>二十二、信任</strong><br />
.<br />
六岁<br />
女儿：我要不要假期上课外班？<br />
我：谁上？<br />
女儿：当然是我上。<br />
我：你上问我干嘛？<br />
.<br />
七岁<br />
女儿：老师说写字可以考级，我要不要考呢？<br />
我：谁考？<br />
女儿：我考。<br />
我：那关我鸟事，问我干嘛？<br />
.<br />
八岁<br />
女儿：我同学要来，不认识我家，她妈妈送到公园门口，陪我一起去接一下吧。<br />
我：这种小事还要我陪？你又不是不认识路，自己去接。<br />
女儿：你就不怕我被骗走啊。<br />
我：骗你？一、你8岁了，对骗子来说年纪太大了，头脑清楚口齿伶俐，养不起；二、你是女孩，卖不起大价钱，不合算；三、要说拿你去卖给人家做老婆生孩子，你又太小了还没发育，现在骗你去还得养很多年才能卖钱，太亏了。所以，你是现在是根本没人要最安全的年纪，过马路注意安全就可以。<br />
女儿：。。。。。。。。。。<br />
.<br />
九岁<br />
女儿：外公他们要出门旅游一个星期，那放学谁来接我啊?<br />
我：都这么大了接什么接，带个钥匙自己坐公交回来.<br />
女儿：。。。。。。。。<br />
.<br />
十岁<br />
女儿：学校开运动会，我可以报一个项目也可以报两个，有跳高，跳远，100米。。。。。。。你帮我想想报哪个好啊，我很难决定<br />
我：你老妈要是靠得住会帮你拿主意，那母猪都会上树了<br />
.<br />
十一岁<br />
女儿：我的下颌矫正器磨着牙肉了，要去修正一下<br />
我：这个月我没空，你定个时间我给你买好火车票，你自己去上海找医生修正，记得带好资料和钱<br />
女儿：世博开了，我还没去过呢<br />
我：这么热，我决定不去，票在抽屉里，自己去<br />
女儿：不怕我丢掉啊<br />
我：世博开了，上海现在是全国最安全的地方，超多武警便衣，你想丢哪去？<br />
外婆：要不带我去吧（外婆很不放心一定要跟去）<br />
临去前，外婆碎碎念地反复问女儿，世博怎么坐车怎么转地铁，怎么吃饭<br />
女儿：你可不可以不这么烦啊，我可以不带你去的。<br />
外婆：好吧，我到上海一定只跟着你什么也不烦<br />
晚十点，我接到女儿电话：老妈，我们现在上火车了，火车X点X分开，大约X分钟到，你算一下时间来接我们吧。<br />
上车到后，她外婆笑得象朵花，忍也忍不住，很兴奋地说<br />
今天我跟着她先去医院修正牙套，都是她买的地铁票，负责路线，到了医院，自己挂号找医生说情况，我真的只是跟在她后面什么也不用管<br />
到世博也是她看地图挑路线场馆，带着去吃饭，走进去看别人都是大人照顾小孩，我只要坐着，全部由她负责把饭菜送到我手里。在世博里我看东西，她跟我说，外婆你看中什么跟我说好了，我买给你。</p>
<p>信任自己的孩子，不是口头上的鼓励，是真正了解你的孩子，相信他们的能力，大胆放手，才是真正的信任。</p>
<p><strong>二十三、成绩都是浮云</strong></p>
<p>上小学后，女儿仍当自己在幼儿园，考试时自己不做跑去教别人。做题目的思维有时也和别人不太一样。比如一道数学题，某店早上卖了五个苹果，下午卖了七个梨，问如果你是店主该进什么水果，为什么？其实只是简单比较哪种水果卖得多就进哪种。女儿回答，如果我是店主就进草莓，因为我喜欢吃草莓。当我无意中看到这张考卷时，笑到风中凌乱。好吧，我真没觉得这是问题，但老师看到这种回答一定是一头黑线了。可想而知，她的成绩虽不很差但也不会太好。半年后，老师对天天接女儿的外婆说，家里谁管她。答，她妈妈。老师，那请她妈妈来学校一趟。</p>
<p>我听到这个消息后很真诚地笑嘻嘻地跟女儿说，我呢不理你怎么学，混着就好，但是呢你也得给我点面子，考试怎么也得混到平均线吧，我要是没面子了，你也就没好果子，是吧。</p>
<p>女儿的外婆很着急，天天对我说，你也管管她的成绩啊，管管啊，终于有天我怒了，跟她说，成绩不重要，学会做人才重要，小学学到三年级基本的字就差不多都认识了，基本的加减乘除也全学会了，就算踏上社会一般也就用这点，成绩再好，不会做人，不会自理也是废物一个，小学学的这点狗P东西，值得这么紧张么。她外婆大惊，你可别对孩子这样说。我：。。。。。。其实我早就跟她这样说过了。但是呢，我对她还有过补充，内容是：你运气不好，出生晚了，你看,XX和XX他们也没读什么书就可以混个工作了，一般来说越晚出生呢得读得学历越高才能找到工作，中国的教育制度就是这样，你也没得挑，我对你没啥要求，不过你日后想要找个工作养自己呢，还是得混个大学文凭的。女儿点头深表赞同和遗憾，自己出生晚了得多读点书才能混个工作。</p>
<p>期末，老师发来短信，要求复习，正好我和女儿在外头散步，我对她说老师叫你们期末复习，你看需不需要，女儿摇头，不要吧，我都会了，我点头，我也这样认为，你们学的这一点点东西还需要复习就太猪了。</p>
<p>二年级结束时，数学老师对孩子的外婆说，这个孩子读上去会比较吃力。</p>
<p>三年级，一切照旧，别人的成绩开始掉下去时，女儿仍然不温不火的混着不变的成绩，四年级学期结束时，我得到消息，女儿混着的成绩到了第三名，于是提前跟家人打过招呼，这个成绩问过就行，不得奖励。因为她的成绩是混出来的，我不希望她为了这个成绩而有压力，为了保持去加倍努力，再说了读书是为她自己，成绩是她的，凭什么为了她的成绩要给奖励呢。一个孩子在一生中自由轻松能有几年，为了那浮云样的几分成绩，放弃这样那样，不值得啊。</p>
<p>五年级，六年级，她仍在混着，一次也没复习过，老师说，这个孩子没有存在感，成绩中上，不拖拉作业，好吧，这是我希望的。</p>
<p><strong>二十四、签字</strong></p>
<p>女儿学了几年的硬笔书法，学完楷书学行书。</p>
<p>我：把行书学好，以后你平时用楷书，需要我签名时，你用行书签一下就可以了。</p>
<p>女儿：不行，老师说不可以自己签。</p>
<p>我：切，平时老师叫你读书背课文你怎么不做就叫我签!</p>
<p>女儿：那是你愿意签的，现在我不愿意代你签。</p>
<p>我为什么这样随便帮女儿签作业，因为了解自己的女儿，她的行为后果都由自己负责，不论我怎么签，最后如果背不出后果还是她承担，所以她绝对不敢对自己捣浆糊。</p>
<p>女儿为什么不肯代我签名，因为她知道即使她拿着0分的考卷给我签，我也一定会签，最多笑嘻嘻地对她说，这个成绩真不是容易考出来的，要什么样的天粪才能考到这种程度，走出去别说认识我，那太丢脸了。所以她完全不必要冒险代签名。</p>
<p><strong>二十五、约定以后一起看A片</strong></p>
<p>我有一本描述男女不同的书，女儿不知道哪去扒了出来，看得津津有味，其中一段是描写男女看A片大脑不同的反应，她不明白了，跑来问我。</p>
<p>女儿：A片是什么</p>
<p>我：赤裸祼，没有情节不穿衣服的人类交配动作片</p>
<p>女儿：你看过吗</p>
<p>我：成年人一般都看过</p>
<p>女儿：跟猫咪交配一样吗</p>
<p>我：不同在于，猫咪任何时候都穿着毛皮大衣以同一姿式交配，而A片里的人多数扒光了交配，也有穿点衣服交配，以不同的角度动作交配，虽然表象不同，但性器官的接触来说，人类和猫咪或别的动物没差别。</p>
<p>女儿：我可以看吗？</p>
<p>我：现在不行，你太小了,A片规定至少年满18岁才能看。这东西没什么了不起，就是以夸张的动作声音来表现男女之间的交配过程，以后等你可以看了，我们一起看吧。</p>
<p>在边上认真杀怪的老公，终于抬起了给雷得焦黑并风中凌乱的头，对着我们内牛满面。</p>
<p>她的老婆刚和十一岁的女儿要约定一起看A片。</p>
<p><strong>二十六、钱</strong></p>
<p>女儿虽然从小不乱买东西，但对于钱还是很没概念，因为买什么都是大人掏的钱。</p>
<p>两年级时，我给她每月五元，跟她说，从现在起每个月给你五元，要买什么都用自己的钱。没两天她跑来跟我说，学校里的小店卖的键子比外面贵一倍，学校里卖一元一个，外面要卖一元两个。说的时候很懊恼，因为她刚在学校里用自己的钱买了一只。我：是的，你的五块钱在学校里只能买五个，外面可以买到十个。巨大的差额深深地刺激到她了。第二天放学，她跑来跟我说，买得太贵了，问我能不能帮她承担一半的价钱（五毛）。我：不行，你买之前谁让你不比较价格的，都说好的，你要买东西就在这五块钱里，贵也好便宜也好，反正都是你花的，我绝对不会为你的行为买这个单。</p>
<p>从那时起，她对钱金的概念就相当精准了</p>
<p>去饭店请客，拿出装一万现金的信封交给女儿，跟她说，我要跟亲威聊天没空结帐，你去办一下。她很自然地跟服务员下去结帐，一会带着剩下的钱和发票回来交给我。过后我问她是把钱全都交出去结的帐吗，她答：不是，问了一下说是4500，我就点了45张给他们，结果多点了，他们还我一张。</p>
<p>十岁时带她去上海看牙，在车上与她聊天，说起带了银行卡不用带现金，卡是有密码的。在医院我把卡交给她让她自己去结帐，凑在她耳边告诉她密码。女儿：其实我在车上就猜到是什么密码了，可是车上有司机在，我就没说。</p>
<p>女儿对于分寸的撑握，老娘我颇感欣慰。</p>
<p><strong>二十七、出国</strong></p>
<p>某日与家人聊天，聊到身边好多同事朋友的孩子，读书不咋滴，就选择出国，深深让我BS。</p>
<p>我对女儿说：你记住，以后你读书能象XX阿姨一样出类拔粹，那我们就负担你出国的费用，否则，想出国等以后自己赚了钱再去，我们绝不负担你一毛钱的费用。</p>
<p>女儿点头称明白。</p>
<p><strong>二十八、素描班</strong></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><strong>二十九、天份你有吗</strong></p>
<p>女儿：翁老师（女儿的素描老师）说，有些小孩学东学西，结果一样都学不好，还不如专心只学一样，学得精。</p>
<p>我：大师级的都需要天份，没天份再努力也只能是工匠，你有画画的天份吗？</p>
<p>女儿：没有，我们这有个小女孩，老师说她很有天份，比我晚学没几天就到里面去画了，我还在外面画，我只不过比别人坐得住，认真点。</p>
<p>我：所以呀，你不过是没天份的普通人，再努力也成不了大师，你作为普通人能做的就是认真多学点各种皮毛，将来可以唬唬不会的普通人。</p>
<p>我：普通人在这个老师这儿学的只能是皮毛，差别在于到达表皮层还是真皮层，专心努力的工匠级可以到达肌肉组织，只有真正有天份的才能通过努力到达骨骼中心。</p>
<p><strong>三十、自制力不是天生的</strong></p>
<p>因为属于早期，这一段其实该写进前十，嘿嘿，忘记了。</p>
<p>三岁内的孩子先立规矩再讲道理，道理懂不懂没关系，规矩却一定要严格执行，但也有可以打破的时候。</p>
<p>夏天，规定女儿每天可以吃一小支冷饮，某日，女儿提出要多吃一支。我回答可以，但有个条件，你今天多吃一支，那明天后天就不能再吃，你可以选择每天一支，也可以选择多吃一支放弃明后两天的份额。女儿选择多吃一支，在以后的两天她没能再吃到冷饮，于是这个规矩只打破过一次就再也没被打破了。</p>
<p>女儿：我可以现在吃薯片吗？</p>
<p>我：可以，不过现在快吃饭了，你现在吃可以吃三片，但是饭后再吃可以吃六片。</p>
<p>女儿：算了，我还是饭后吃吧</p>
<p>女儿：我现在可以出去玩沙子吗？</p>
<p>我：可以，但现在是睡午觉的时间了，要是现在玩你可以玩半小时，睡好起来玩，可以玩一小时</p>
<p>女儿：我现在去睡觉了。</p>
<p>我们对女儿规定，不是重要的日子，比如生日、比如春节。。。。。，外出不可以买东西。某日带她一起去小商品市场买线，她站在旁边的玩具摊很仔细地看了很久，老公：不可以买哦。女儿一脸平静：我只是看看呀。</p>
<p>身上抓开、受伤结了盖，我总会忍不住去剥，一直剥一直剥，伤口老也不好，虽知道这不是好行为，但很难忍住。女儿开始也有这个行为，于是我跟她说，这个盖如果剥了，以后这块皮肤就会留下疤，很难看。从此她身上伤口上的盖全部都是自然脱落，没再剥过一个，这样的自制力让我叹为观止深深汗颜。</p>
<p><strong>三十一、女孩是要富养的</strong></p>
<p>单指物质上，富养女儿必须是不动声色潜移默化，略一偏差，结果养出来的不是装13物质女就是暴发户样虚荣女。</p>
<p>浪琴事件是真实存在的，十岁的女儿需要一只手表，我给了她两只，两只手表样式大小厚薄都相似，米老鼠的粉蓝表带，卡通底盘，浪琴的鳄鱼表带，18K金表，一只价格一大家多，一只价值一万多。理由是一用一备，喜欢哪只带哪只，反正除了价格有差其他都差不多。当然我肯定女儿会选米老鼠。而且女儿也认为手表，不过因品牌材质不同所以价格差一百倍，但本质上没差别。</p>
<p>我常把十多万的卡交给女儿让她结帐，习以为常就好。如果见惯了这些，并不觉得了不起，也就不会出去炫耀，炫耀的本质是要觉得这件事了不起才会做。富养的实质是要让女儿认为，这些东西这些钱没什么了不起，只有有这个概念，将来才不容易被骗，家长没有这个心态就不要去富养女儿，不然就是害她。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Flove-with-rules-and-freedom-with-condition%2F&amp;linkname=zz%3A%20%E7%88%B1%E7%9A%84%E8%A7%84%E5%88%99%EF%BC%8C%E8%87%AA%E7%94%B1%E7%9A%84%E6%9D%A1%E4%BB%B6"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/love-with-rules-and-freedom-with-condition/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Python HTTP - Post a Binary File using urllib2</title>
		<link>http://www.2maomao.com/blog/python-http-post-a-binary-file-using-urllib2/</link>
		<comments>http://www.2maomao.com/blog/python-http-post-a-binary-file-using-urllib2/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 14:40:18 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[原创精选]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1423</guid>
		<description><![CDATA[I was trying to post a png file to our internal webserver for some quick and dirty task, but Python keep throwing ascii encoding exception.
Then I search &#8220;post http binary urllib2&#8243; and did found several options, like multipart/form-data and p... ]]></description>
			<content:encoded><![CDATA[<p>I was trying to post a png file to our internal webserver for some quick and dirty task, but Python keep throwing ascii encoding exception.</p>
<p>Then I search &#8220;post http binary urllib2&#8243; and did found several options, like <a href="http://code.activestate.com/recipes/146306/">multipart/form-data</a> and <a href="http://pycurl.sourceforge.net/">pycurl</a>, but they need the webserver&#8217;s help to accomplish a simple file posting.</p>
<p>In the end I decide to dig into Python&#8217;s httplib and urllib2 to find out what&#8217;s going on, if that doesn&#8217;t work I will fallback to raw TCP socket solution.</p>
<p>Luckily I got the following solution that works like a charm:<br />
1. set Content-Length header(of the file) before doing post<br />
2. pass a opened file when doing post</p>
<p>Sample code:</p>
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/18111/">Python Post a Binary File using urllib2</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">urllib2</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span></p>
<p> <span style="color: rgb(0, 0, 0); ">image_path</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;png</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">01.png&quot;</span><br /> <span style="color: rgb(0, 0, 0); ">url</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;http://xx.oo.com/webserviceapi/postfile/&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">length</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">path</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">getsize</span>(<span style="color: rgb(0, 0, 0); ">image_path</span>)<br /> <span style="color: rgb(0, 0, 0); ">png_data</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(0, 0, 0); ">image_path</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;rb&quot;</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">Request</span>(<span style="color: rgb(0, 0, 0); ">url</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">data</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(0, 0, 0); ">png_data</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add_header</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Cache-Control&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;no-cache&#39;</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add_header</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Content-Length&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;</span> <span style="color: rgb(0, 0, 0); ">%</span> <span style="color: rgb(0, 0, 0); ">length</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add_header</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Content-Type&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;image/png&#39;</span>)<br /> <span style="color: rgb(0, 0, 0); ">res</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">urlopen</span>(<span style="color: rgb(0, 0, 0); ">request</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">read</span>()<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">strip</span>()<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">res</span></div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fpython-http-post-a-binary-file-using-urllib2%2F&amp;linkname=Python%20HTTP%20-%20Post%20a%20Binary%20File%20using%20urllib2"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/python-http-post-a-binary-file-using-urllib2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>贴代码：从命令行卸载程序, Windows XP/Vista/Win7</title>
		<link>http://www.2maomao.com/blog/uninstall-from-command-line-for-windows/</link>
		<comments>http://www.2maomao.com/blog/uninstall-from-command-line-for-windows/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 14:23:05 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[就通一点]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1417</guid>
		<description><![CDATA[主要写给自己用，因为天天都跟windows命令行打交道，装了个CCleaner就是因为它比windows自己的“添加/删除程序”要快。最近实现工作中要用到的东西，顺便做得更加通用一点，贴到这里。还挺方... ]]></description>
			<content:encoded><![CDATA[<p>主要写给自己用，因为天天都跟windows命令行打交道，装了个CCleaner就是因为它比windows自己的“添加/删除程序”要快。最近实现工作中要用到的东西，顺便做得更加通用一点，贴到这里。还挺方便的，因为命令行更快。</p>
<p>保存成u.py，然后如下运行:</p>
<pre class="mycode" style="font-family:fixed, monospace">
D:\Documents\Dropbox\Coding\active>u apple
multiple matches, please choose:

  1  Apple Mobile Device Support
  2  Apple Software Update
  3  Apple Application Support

select a number, Ctrl+C to quit: 3

        Apple Mobile Device Support

press ENTER to uninstall, Ctrl+C to stop</pre>
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/17918/">Command line uninstaller for Windows Applications</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(249, 247, 237); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span><br /> <span style="color: rgb(136, 136, 136); ">#Author : Zhongfang Ren</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yid: renzhongfang</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; email: realfun AT gmail.com</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; website: http://2maomao.com/blog/, http://fayaa.com</span><br /> <span style="color: rgb(136, 136, 136); ">#Purpose: Command line uninstaller for windows XP(Vista and Win7 not tried yet)</span><br /> <span style="color: rgb(136, 136, 136); ">#Date&nbsp;&nbsp; : Wednesday, March 23, 2011, 10:42:34</span><br /> <span style="color: rgb(136, 136, 136); ">#</span></p>
<p> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">getpass</span><br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">subprocess</span> <span style="color: rgb(0, 0, 0); ">as</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">exe</span><br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">_winreg</span> <span style="color: rgb(0, 0, 0); ">as</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">R</span></p>
<p> <span style="color: rgb(0, 0, 0); ">target</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;&#39;</span><br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span>) <span style="color: rgb(0, 0, 0); ">&gt;</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">target</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">]</span></p>
<p> <span style="color: rgb(0, 0, 0); ">uninstalls</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[]</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">root</span> <span style="color: rgb(0, 136, 0); ">in</span> (<span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">HKEY_LOCAL_MACHINE</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">HKEY_CURRENT_USER</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">with</span> <span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">OpenKey</span>(<span style="color: rgb(0, 0, 0); ">root</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&quot;</span>) <span style="color: rgb(0, 136, 0); font-weight: bold; ">as</span> <span style="color: rgb(0, 0, 0); ">key</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">keys</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[]</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">i</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">while</span> <span style="color: rgb(0, 51, 136); ">True</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">try</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">keys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>(<span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">EnumKey</span>(<span style="color: rgb(0, 0, 0); ">key</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">i</span>))<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">i</span> <span style="color: rgb(0, 0, 0); ">+=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">except</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">Exception</span> <span style="color: rgb(0, 136, 0); font-weight: bold; ">as</span> <span style="color: rgb(0, 0, 0); ">e</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(136, 136, 136); ">#print e</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">break</span></p>
<p> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">k</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">keys</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">try</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">with</span> <span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">OpenKey</span>(<span style="color: rgb(0, 0, 0); ">key</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">k</span>) <span style="color: rgb(0, 136, 0); font-weight: bold; ">as</span> <span style="color: rgb(0, 0, 0); ">hkey</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">try</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">v</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">QueryValueEx</span>(<span style="color: rgb(0, 0, 0); ">hkey</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;DisplayName&quot;</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">v</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">str</span>(<span style="color: rgb(0, 0, 0); ">v</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">])</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">v</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">lower</span>()<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">find</span>(<span style="color: rgb(0, 0, 0); ">target</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">lower</span>()) <span style="color: rgb(0, 0, 0); ">&gt;=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>((<span style="color: rgb(0, 0, 0); ">v</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">R</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">QueryValueEx</span>(<span style="color: rgb(0, 0, 0); ">hkey</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;UninstallString&quot;</span><span style="color: rgb(0, 0, 0); ">)[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]))</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">except</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">Exception</span> <span style="color: rgb(0, 136, 0); font-weight: bold; ">as</span> <span style="color: rgb(0, 0, 0); ">e</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(136, 136, 136); ">#print e</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">pass</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">except</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">pass</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">try</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 136, 0); ">not</span> <span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;uninstall for </span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); "> not found&quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> <span style="color: rgb(0, 0, 0); ">target</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">elif</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">uninstalls</span>) <span style="color: rgb(0, 0, 0); ">==</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\t</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> <span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">][</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 51, 136); ">raw_input</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;press ENTER to uninstall, Ctrl+C to stop&quot;</span>)<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">exe</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">call</span>(<span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">][</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">])</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">else</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;multiple matches, please choose:</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\n</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">i</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">nu</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%3d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); "> &quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> <span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">nu</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(136, 136, 136); ">#, &#39;\t&#39;, nu[1]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">i</span> <span style="color: rgb(0, 0, 0); ">+=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">val</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">while</span> <span style="color: rgb(0, 0, 0); ">val</span> <span style="color: rgb(0, 0, 0); ">&lt;=</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span> <span style="color: rgb(0, 136, 0); ">or</span> <span style="color: rgb(0, 0, 0); ">val</span> <span style="color: rgb(0, 0, 0); ">&gt;</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">try</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">val</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">int</span>(<span style="color: rgb(0, 51, 136); ">raw_input</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;select a number, Ctrl+C to quit: &quot;</span>))<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">except</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">ValueError</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">pass</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">name</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">uninst</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">uninstalls</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">val</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">]</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\t</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> <span style="color: rgb(0, 0, 0); ">name</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 51, 136); ">raw_input</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;press ENTER to uninstall, Ctrl+C to stop&quot;</span>)<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">exe</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">call</span>(<span style="color: rgb(0, 0, 0); ">uninst</span>)<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">except</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">KeyboardInterrupt</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">pass</span><br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">finally</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span></div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Funinstall-from-command-line-for-windows%2F&amp;linkname=%E8%B4%B4%E4%BB%A3%E7%A0%81%EF%BC%9A%E4%BB%8E%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8D%B8%E8%BD%BD%E7%A8%8B%E5%BA%8F%2C%20Windows%20XP%2FVista%2FWin7"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/uninstall-from-command-line-for-windows/feed/</wfw:commentRss>
		</item>
		<item>
		<title>一些有用的Python库</title>
		<link>http://www.2maomao.com/blog/useful-python-libs/</link>
		<comments>http://www.2maomao.com/blog/useful-python-libs/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 06:25:53 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[一些链接]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1412</guid>
		<description><![CDATA[Update @ 2011-03-06, 15:02:57
你有没有使用过的觉得不错的Python库？请到这里跟大家分享：常用的 Python 库：请投票
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#821... ]]></description>
			<content:encoded><![CDATA[<p><strong>Update @ 2011-03-06, 15:02:57</strong><br />
你有没有使用过的觉得不错的Python库？请到这里跟大家分享：<a href="http://fayaa.com/tiku/view/203/">常用的 Python 库：请投票</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>今天整理C盘，看到python还是2.6，就给更新到了2.7，再更新所有的site-packages过程中，搜到了这个网页：<br />
<a href="http://wiki.python.org/moin/UsefulModules">http://wiki.python.org/moin/UsefulModules</a></p>
<p>网页中列出了一堆有用的库，其中有一些我曾经用过或者比较感兴趣的，选了一些混合我现在常用的lib列在下面：</p>
<p><a href="http://pypi.python.org/pypi/setuptools">Easy Install</a>: easy_install 安装工具，下面提到的多数lib都能用easy_install lib_name进行安装</p>
<p><a href="http://www.sqlalchemy.org/">SQLAlchemy</a>, <a href="http://sqlobject.org/">SQLObject</a>, <a href="http://sourceforge.net/projects/mysql-python/">Mysql-Python</a>(<a href="http://code.google.com/p/soemin/downloads/list">Win32安装包</a>)：数据库访问，<a href="http://fayaa.com">发芽网</a>后台用到了Mysql-Python</p>
<p><a class="http" href="http://starship.python.net/crew/theller/ctypes/">CTypes</a> - 直接调用dll中的函数，经常用来做Windows API的调用</p>
<p><a href="http://www.wxpython.org/">WxPython</a> - Python UI库，<a href="http://code.google.com/p/ulipad/">Ulipad</a>就是基于这个</p>
<p><a href="http://wiki.python.org/moin/Console/Ascii_table">Ascii_table</a>：在命令行界面中输出漂亮的表格</p>
<p><a href="http://www.pythonware.com/products/pil/">Python Imaging Library (PIL) </a>：图片处理，<a href="http://fayaa.com">发芽网</a>的Captcha用到了这个</p>
<p><a href="http://people.csail.mit.edu/hubert/pyaudio/#downloads">PyAudio</a>：WAV文件读写，录音，用这个写过一个录音工具，还不错</p>
<p><a href="http://code.google.com/p/httplib2/">HTTPLib2</a>：非常好用的http工具，做cookie、put请求、header、错误处理等等很方便，可以做网络爬虫或者访问webservice的脚本</p>
<p><a href="http://psyco.sourceforge.net/">Psyco </a>：只要简单的写下如下两句话，就能让你的python脚本快很多，在需要很多计算的脚本里很好用，<a href="http://fayaa.com/youxi/hrd/add/">求解华容道</a>时试过，速度改进的不错，虽然最后还是没有达到要求，改用C++写了一个：</p>
<pre>import psyco
psyco.full()</pre>
<p><a href="http://pyobjc.sourceforge.net/">PyObjC</a>: Python写ObjectiveC/cocoa程序作为一个遗憾放在这儿吧，要是支持iOS就好了</p>
<p><a href="https://sourceforge.net/projects/pywin32/">PyWin32 </a>：针对win32常用的系统api做了很好的封装，用这个写过一个彩色命令行脚本</p>
<p><a href="http://numpy.scipy.org/">NumPy</a>, <a href="http://numpy.scipy.org/">SciPy</a>, <a href="http://matplotlib.sourceforge.net/">Matplotlib</a>：科学计算的三神器，<a href="http://scipy.org/Topical_Software#head-b98ffdb309ccce4e4504a25ea75b5c806e4897b6">更多参见这里</a>。有本在线的书：<a href="http://hyry.dip.jp/pydoc/index.html">用Python做科学计算</a>，旅居日本的hyry写的，值得一看</p>
<p><a href="http://www.py2exe.org/">Py2exe</a>: 把你的python脚本转成exe可执行程序，曾经用过，仅支持到python2.5所以最近没用过了</p>
<p><a href="http://www.djangoproject.com/">Django</a>：使用最多的Python web framework，<a href="http://fayaa.com">发芽网</a>也是基于Django</p>
<p><a href="http://lxml.de/">lxml</a>：XML文件处理的利器。最近两年有点儿烦HTML，改用json了</p>
<p><a href="http://ipython.scipy.org/moin/">iPython</a>: 更加好用的Python命令行交互环境</p>
<p><a href="http://pypi.python.org/pypi/python-openid/">python-openid</a>：Python下做OpenID，都得用这个，<a href="http://fayaa.com/user/login/">发芽网的OpenID支持</a>也是基于这个做的</p>
<p><a href="http://pygments.org/">Pygements</a>：<a href="http://fayaa.com/code/">代码发芽网</a>的高亮，用的就是这个库，略该，以适应直接复制粘贴的需求</p>
<p><a href="http://code.google.com/p/python-nose/">nose</a>：python下的测试驱动工具，曾经用过，很简洁。现在我用<a href="http://docs.python.org/library/doctest.html">doctest</a>更多一点</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fuseful-python-libs%2F&amp;linkname=%E4%B8%80%E4%BA%9B%E6%9C%89%E7%94%A8%E7%9A%84Python%E5%BA%93"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/useful-python-libs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Python urllib2的使用点滴: cookie, https, put, 500/403的处理</title>
		<link>http://www.2maomao.com/blog/python-urllib2-cookie-https-put-500-403/</link>
		<comments>http://www.2maomao.com/blog/python-urllib2-cookie-https-put-500-403/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 14:31:38 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[原创精选]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1404</guid>
		<description><![CDATA[Update @ 2011-03-06, 13:46:08
刚刚发现了一个比urllib2更好用的库httplib2，可以比较简单的解决本文遇到的一些问题
http://code.google.com/p/httplib2/
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;... ]]></description>
			<content:encoded><![CDATA[<p><strong>Update @ 2011-03-06, 13:46:08</strong><br />
刚刚发现了一个比urllib2更好用的库httplib2，可以比较简单的解决本文遇到的一些问题<br />
<a href="http://code.google.com/p/httplib2/">http://code.google.com/p/httplib2/</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>最近用<a href="http://docs.python.org/library/urllib2.html">urllib2</a>写了一个公司内部用的脚本</p>
<p>这个脚本要访问一个webservice，访问之前先要用https登陆拿到cookie再到另一个地方获取一个临时用的id</p>
<h1>https登陆，获取cookie</h1>
<p>首先是https登陆，这段很好写，以前<a href="http://fayaa.com/code/view/25/">写过校内网发帖机</a>，轻车熟路，用cookielib的CookieJar加上HTTPCookieProcessor搞定，代码如下（其中那个超简单的lambda hack简直绝了：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span><br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">urllib</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">urllib2</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">cookielib</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">re</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">json</span></p>
<p> <span style="color: rgb(0, 0, 0); ">cj</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">cookielib</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">CookieJar</span>()<br /> <span style="color: rgb(0, 0, 0); ">opener</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">build_opener</span>(<span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">HTTPCookieProcessor</span>(<span style="color: rgb(0, 0, 0); ">cj</span>))<br /> <span style="color: rgb(0, 0, 0); ">url_login</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;https://xxx.yahoo.com/login/&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">body</span> <span style="color: rgb(0, 0, 0); ">=</span> ((<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;username&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;半瓶墨水&#39;</span><span style="color: rgb(0, 0, 0); ">),</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;password&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;密码&#39;</span><span style="color: rgb(0, 0, 0); ">),</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;action&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;login&#39;</span><span style="color: rgb(0, 0, 0); ">),)</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;login to get cookies&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">opener</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">open</span>(<span style="color: rgb(0, 0, 0); ">url_login</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">urllib</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">urlencode</span>(<span style="color: rgb(0, 0, 0); ">body</span>))</div>
<h1>处理HTTP 403/500 Exception</h1>
<p>但是后面用cookie去拿id的时候，就老是告诉我403错误，然后opener就抛异常，想问题想到头大，后来发现这个服务访问成功不是返回200，而是403，所以看到403的时候不要管他，直接看body内容就行了，日，不知道为什么这么设计。</p>
<p>怎么办呢？查了一下urllib2的文档，发现可以继承一下HTTPCookieProcessor，自己做了一个NoExceptionCookieProcesser，后来的过程中发现webservice有时候返回400和500的时候body中包含有用的信息，一并处理了：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span><br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">urllib</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">urllib2</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">cookielib</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">re</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">json</span><br /> <span style="color: rgb(136, 136, 136); ">#suppress the 403/400/500 exception and return the body</span><br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">class</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">NoExceptionCookieProcesser</span>(<span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">HTTPCookieProcessor</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">http_error_403</span>(<span style="color: rgb(0, 51, 136); ">self</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">req</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">fp</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">code</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">msg</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">hdrs</span><span style="color: rgb(0, 0, 0); ">):</span> <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">fp</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">http_error_400</span>(<span style="color: rgb(0, 51, 136); ">self</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">req</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">fp</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">code</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">msg</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">hdrs</span><span style="color: rgb(0, 0, 0); ">):</span> <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">fp</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">http_error_500</span>(<span style="color: rgb(0, 51, 136); ">self</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">req</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">fp</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">code</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">msg</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">hdrs</span><span style="color: rgb(0, 0, 0); ">):</span> <br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">fp</span><br /> &nbsp; <br /> <span style="color: rgb(0, 0, 0); ">cj</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">cookielib</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">CookieJar</span>()<br /> <span style="color: rgb(0, 0, 0); ">opener</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">build_opener</span>(<span style="color: rgb(0, 0, 0); ">NoExceptionCookieProcesser</span>(<span style="color: rgb(0, 0, 0); ">cj</span>))<br /> <span style="color: rgb(0, 0, 0); ">url_login</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;https://xxx.yahoo.com/login/&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">body</span> <span style="color: rgb(0, 0, 0); ">=</span> ((<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;username&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;半瓶墨水&#39;</span><span style="color: rgb(0, 0, 0); ">),</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;password&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;密码&#39;</span><span style="color: rgb(0, 0, 0); ">),</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;action&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;login&#39;</span><span style="color: rgb(0, 0, 0); ">),)</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;login to get cookies&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">opener</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">open</span>(<span style="color: rgb(0, 0, 0); ">url_login</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">urllib</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">urlencode</span>(<span style="color: rgb(0, 0, 0); ">body</span>))</div>
<h1>urllib2中用PUT进行请求</h1>
<p>然后又发现一个问题，webservice在提交的时候要求用PUT方式，并且只接受json，urllib2默认只支持GET和POST，Google了一下，发现可以创建Request对象，然后更改它的请求方法(get_method)以及header，搞定：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); "> </p>
<p> <span style="color: rgb(0, 0, 0); ">request</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">urllib2</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">Request</span>(<span style="color: rgb(0, 0, 0); ">url_ws</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">data</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;blablabla&quot;</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add_header</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Content-Type&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;application/json&#39;</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add_header</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Accept&#39;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;application/json&#39;</span>)<br /> <span style="color: rgb(0, 0, 0); ">request</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">get_method</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 136, 0); font-weight: bold; ">lambda</span><span style="color: rgb(0, 0, 0); ">:</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;PUT&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">result</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">opener</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">open</span>(<span style="color: rgb(0, 0, 0); ">request</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">read</span>()<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">strip</span>()</div>
<p>参考：<a href="http://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python">http://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-python</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fpython-urllib2-cookie-https-put-500-403%2F&amp;linkname=Python%20urllib2%E7%9A%84%E4%BD%BF%E7%94%A8%E7%82%B9%E6%BB%B4%3A%20cookie%2C%20https%2C%20put%2C%20500%2F403%E7%9A%84%E5%A4%84%E7%90%86"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/python-urllib2-cookie-https-put-500-403/feed/</wfw:commentRss>
		</item>
		<item>
		<title>tagwin - windows命令行利器 - 利用标签在文件夹中快速跳转</title>
		<link>http://www.2maomao.com/blog/win32-folder-tagging-scripts/</link>
		<comments>http://www.2maomao.com/blog/win32-folder-tagging-scripts/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 08:27:49 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[小小工具]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1392</guid>
		<description><![CDATA[Update @ Tuesday, March 1, 2011, 18:26:54: Fix 一些小问题，最新版是1.1
前两天看到了Dreamers&#8217;s blog：Bash 小技巧：给目录加上书签，快速切换目录(bashmarks)，感觉用批处理脚本实现应该不难
套用Dreamer... ]]></description>
			<content:encoded><![CDATA[<p><strong>Update @ Tuesday, March 1, 2011, 18:26:54</strong>: Fix 一些小问题，<a href="http://www.2maomao.com/blog/wp-content/uploads/tagwin-dglt-11.zip">最新版是1.1</a></p>
<p>前两天看到了Dreamers&#8217;s blog：<a href="http://www.zhuoqun.net/html/y2011/1635.html">Bash 小技巧：给目录加上书签，快速切换目录</a>(<a href="http://www.huyng.com/bashmarks-directory-bookmarks-for-the-shell/">bashmarks</a>)，感觉用批处理脚本实现应该不难</p>
<p>套用Dreamer的一段话（略改）：</p>
<blockquote><p>当我们在命令行下面做开发的时候，很大一部分时间都浪费在了目录切换上面，相信不少人每天敲 “cd” 都敲得想吐。如果目录层次多一点，Tab 键也会饱受摧残。虽然Windows命令行有内置的 “cd -”, “pushd” 和 “popd” 命令，但用起来都不是很顺手。</p>
<p>如果能用几行简单的 Batch 脚本巧妙地给目录加上了书签，这样你就可以给最常用的那几个工作目录加上书签，不需要每次都敲 cd 了。还可以在各个常用的文件夹之间来回快速切换。</p></blockquote>
<p>当天晚上回来就实现了第一版，感觉很是不错，由于一直没有时间写博，留到今天才拿出来跟大家分享</p>
<p><strong>使用方法</strong>：</p>
<p>1. 点击此处下载： <a href="http://www.2maomao.com/blog/wp-content/uploads/tagwin-dglt-11.zip">http://www.2maomao.com/blog/wp-content/uploads/tagwin-dglt-11.zip</a><br />
 　(或者尝试 <a href="http://code.google.com/p/tagwin-dglt/downloads/detail?name=tagwin-dglt-1.1.zip&#038;can=2&#038;q=">这个链接</a>）</p>
<p>2. 解压所有文件到系统PATH包含的任意目录下</p>
<p>3. 打开命令行，进入要加标签的目录<br />
　　t abc &#8212;> 给当前目录加标签为abc<br />
　　g abc &#8212;> 切换到标签为abc的目录<br />
　　d abc &#8212;> 删除标签abc<br />
　　l &#8212;&#8212;&#8212;&#8211;> 列出所有标签</p>
<p>在你解压缩的那个目录找到dglt.list文件，里面是所有的标签，也可以通过编辑这个文件来管理</p>
<p>另外在Google Code建了一个项目用来保存最新的代码，有兴趣的可以去看看代码：<br />
http://code.google.com/p/tagwin-dglt/</p>
<p>使用演示：</p>
<pre class="mycode">
D:\projects>t proj

 proj   D:\projects

D:\projects>cd py\django\fayaa

D:\projects\py\django\fayaa>t fayaa

 fayaa  D:\projects\py\django\fayaa

D:\projects\py\django\fayaa>pushd g:\relax\movie

G:\relax\movie>t movie

 movie  G:\relax\movie

G:\relax\movie>g proj

D:\projects>g fayaa

D:\projects\py\django\fayaa>g movie

G:\relax\movie>l

Tagged Folders
--------------
proj    D:\projects
fayaa   D:\projects\py\django\fayaa
movie   G:\relax\movie
</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fwin32-folder-tagging-scripts%2F&amp;linkname=tagwin%20-%20windows%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%88%A9%E5%99%A8%20-%20%E5%88%A9%E7%94%A8%E6%A0%87%E7%AD%BE%E5%9C%A8%E6%96%87%E4%BB%B6%E5%A4%B9%E4%B8%AD%E5%BF%AB%E9%80%9F%E8%B7%B3%E8%BD%AC"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/win32-folder-tagging-scripts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>把Picasa加星标的图片一次性导出</title>
		<link>http://www.2maomao.com/blog/py-script-export-all-stared-photos-in-picasa/</link>
		<comments>http://www.2maomao.com/blog/py-script-export-all-stared-photos-in-picasa/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 14:30:24 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[原创精选]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1388</guid>
		<description><![CDATA[年前买了个千万级的照相机，再加上不加节制的使用，200G的硬盘开始不够用了，为了节省空间，决定把多数照片放在一个不是很常用的地方+刻盘，只把选择出来的照片留下
为了达到这个目标... ]]></description>
			<content:encoded><![CDATA[<p>年前买了个千万级的照相机，再加上不加节制的使用，200G的硬盘开始不够用了，为了节省空间，决定把多数照片放在一个不是很常用的地方+刻盘，只把选择出来的照片留下</p>
<p>为了达到这个目标，现在安装的<a href="http://www.faststone.org/FSViewerDownload.htm">Faststone Image Viewer</a>就不是很好用，安装的光影看看更是管理图片的废材。最后Google了一下，发现最好用的还是<a href="http://picasa.google.com/">Picasa</a>。</p>
<p>下载了最新版，又花了过年的三四天的精选了照片，最后想把照片导出的时候遇到问题了，一共四五十个文件夹，Picasa并没有提供一次性导出的功能，只能一个文件夹一个文件夹的导出。最后还是决定写个脚本来搞定，研究了一下，发现每个目录下都有个.picasa.ini文件，格式十分简单，比如这个:</p>
<pre>
[IMG_0152.JPG]
faces=rect64(78f63255a1427ae3),155499df12e3d390
backuphash=4191
star=yes
</pre>
<p>其中的star=yes代表该照片已加星标。这就简单了，半小时写，十分钟导出，搞定！</p>
<p>脚本如下，注意脚本运行完以后生成了一个叫做copystar_go.bat的批处理文件，执行它才是真正的导出，这本来是调试用的，后来发现可以手工控制删掉一些不需要的导出操作（用Vim很快的），就没改回来，不多说，上代码：</p>
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/16987/">Export all stared photos in Picasa once</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#Purpose: export all picasa stared photos under a folder and it&#39;s subfolders</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; because Picasa doesn&#39;t support - it only can export one folder once</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp; Reach me via: realfun AT gmail DOT com</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp; http://2maomao.com/blog/py-script-export-all-stared-photos-in-picasa/</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp; http://www.google.com/profiles/realfun</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp; 2011-02-22, 22:26:28</span></p>
<p> <span style="color: rgb(0, 0, 0); ">from</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(0, 0, 0); ">walk</span><br /> <span style="color: rgb(0, 0, 0); ">from</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os.path</span> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(0, 0, 0); ">join</span></p>
<p> <span style="color: rgb(136, 136, 136); ">#damn python encoding hack</span><br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span><br /> <span style="color: rgb(0, 51, 136); ">reload</span>(<span style="color: rgb(0, 0, 0); ">sys</span>)<br /> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">setdefaultencoding</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;gb2312&quot;</span>)</p>
<p> <span style="color: rgb(0, 0, 0); ">PICASA</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;.picasa.ini&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">PICASA_OLD</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;Picasa.ini&#39;</span><br /> <span style="color: rgb(0, 0, 0); ">TARGET</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;G:</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">ipad</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">sync</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">temp</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">get_stars</span>(<span style="color: rgb(0, 51, 136); ">dir</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">picasa</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">stars</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[]</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">last</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">None</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(0, 0, 0); ">join</span>(<span style="color: rgb(0, 51, 136); ">dir</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">picasa</span>))<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">readlines</span><span style="color: rgb(0, 0, 0); ">():</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">rstrip</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\n</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">startswith</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;[&quot;</span>) <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">endswith</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;]&quot;</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">last</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">decode</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;utf-8&quot;</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">elif</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">startswith</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;star=yes&quot;</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">stars</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>(<span style="color: rgb(0, 0, 0); ">last</span>)<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">stars</span></p>
<p> <span style="color: rgb(0, 0, 0); ">out</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;copystar_go.bat&quot;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;wb&quot;</span>)<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">root</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">dirs</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">files</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">walk</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;.&quot;</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">picasa</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">None</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">PICASA</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">files</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">picasa</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">PICASA</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">elif</span> <span style="color: rgb(0, 0, 0); ">PICASA_OLD</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">files</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">picasa</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">PICASA_OLD</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">picasa</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">stars</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">get_stars</span>(<span style="color: rgb(0, 0, 0); ">root</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">picasa</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">star</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">stars</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;robocopy &quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot; &quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot; &quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%s</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\r</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;</span> <span style="color: rgb(0, 0, 0); ">%</span> (<span style="color: rgb(0, 0, 0); ">root</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">join</span>(<span style="color: rgb(0, 0, 0); ">TARGET</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">root</span><span style="color: rgb(0, 0, 0); ">),</span> <span style="color: rgb(0, 0, 0); ">star</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(0, 0, 0); ">&gt;&gt;</span><span style="color: rgb(0, 0, 0); ">out</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">line</span></div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fpy-script-export-all-stared-photos-in-picasa%2F&amp;linkname=%E6%8A%8APicasa%E5%8A%A0%E6%98%9F%E6%A0%87%E7%9A%84%E5%9B%BE%E7%89%87%E4%B8%80%E6%AC%A1%E6%80%A7%E5%AF%BC%E5%87%BA"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/py-script-export-all-stared-photos-in-picasa/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SRT subtitle splitter，字幕分割程序，in Python</title>
		<link>http://www.2maomao.com/blog/srt-subtitle-splitter-in-python/</link>
		<comments>http://www.2maomao.com/blog/srt-subtitle-splitter-in-python/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 08:46:48 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1386</guid>
		<description><![CDATA[Verycd终于顶不住了
这周末整理了一下从Verycd上面拖下来的一百多G电影，发现教父1/2/3依然没有看过，想要看看才发现没字幕，射手影音也没下载到，只好到射手网上面去找，找到了几个都是一... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://verycd.com/">Verycd</a>终于顶不住了</p>
<p>这周末整理了一下从Verycd上面拖下来的一百多G电影，发现教父1/2/3依然没有看过，想要看看才发现没字幕，射手影音也没下载到，只好到<a href="http://shooter.cn">射手网</a>上面去找，找到了几个都是一个字幕到底的；于是Google字母分割工具，一边找一边感叹下载站的没落，连国外的下载站也开始搞中国这一套欺骗点击的骗术。</p>
<p>找了半天，没找到一个可用的，有那么几个软件，用起来完全达不到自己的要求；<br />
研究了一下srt的格式，自己写了段python脚本，居然花了一个小时，不过总算搞定了，代码如下：</p>
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/16951/">SRT subtitle splitter，字幕分割程序</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span></p>
<p> <span style="color: rgb(136, 136, 136); ">#Author: 半瓶墨水 # 2011-02-20, 13:59:14</span><br /> <span style="color: rgb(136, 136, 136); ">#Email : realfun AT gmail DOT com</span><br /> <span style="color: rgb(136, 136, 136); ">#Usage : split srt files</span><br /> <span style="color: rgb(136, 136, 136); ">#Examples:</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp; 将&quot;教父.srt&quot;分两段,起始时间向前错位29秒</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp; 第一段长1小时45分48秒，依次为第二段第三段，剩下的为第四段</span><br /> <span style="color: rgb(136, 136, 136); ">#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srt.py 教父.srt offset=00:00:29 00:42:55 00:46:24 00:42:39</span><br /> <span style="color: rgb(136, 136, 136); "># *NOTICE* Serial number is not handled</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#写这段代码主要是因为，从Verycd上面下的教父没找到对应的字幕；Verycd is Gone <img src='http://www.2maomao.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </span></p>
<p> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">srttime2int</span>(<span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp; <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&quot;&#8221;</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; srttime2int(&quot;-00:01:19&quot;)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; -79000</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; srttime2int(&quot;00:01:19&quot;)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; 79000</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; srttime2int(&quot;10:21:29&quot;)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; 37289000</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; srttime2int(&quot;00:01:19,601&quot;)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; 79601</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; srttime2int(&quot;10:21:29,601&quot;)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; 37289601</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &quot;&quot;&#8221;</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">False</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]</span> <span style="color: rgb(0, 0, 0); ">==</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;-&#39;</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">True</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">st</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">:]</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">value</span> <span style="color: rgb(0, 0, 0); ">=</span> ((<span style="color: rgb(0, 51, 136); ">int</span>(<span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">2</span><span style="color: rgb(0, 0, 0); ">])</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">60</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 51, 136); ">int</span>(<span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">3</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">5</span><span style="color: rgb(0, 0, 0); ">]))</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">60</span><span style="color: rgb(0, 0, 0); ">+</span>(<span style="color: rgb(0, 51, 136); ">int</span>(<span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">6</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">8</span><span style="color: rgb(0, 0, 0); ">])))</span><span style="color: rgb(0, 0, 0); ">*</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1000</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 51, 136); ">int</span>(<span style="color: rgb(0, 0, 0); ">st</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">9</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">12</span><span style="color: rgb(0, 0, 0); ">]</span> <span style="color: rgb(0, 136, 0); ">or</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span>)<br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">value</span> <span style="color: rgb(0, 136, 0); ">or</span> <span style="color: rgb(0, 0, 0); ">value</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">int2srttime</span>(<span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp; <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&quot;&#8221;</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; int2srttime(-79601)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &#39;-00:01:19,601&#39;</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; int2srttime(79601)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &#39;00:01:19,601&#39;</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &gt;&gt;&gt; int2srttime(37289601)</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &#39;10:21:29,601&#39;</span><br /> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&nbsp; &quot;&quot;&#8221;</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">False</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">&lt;</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">i</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 0); ">i</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">True</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">srttime</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%02d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">:</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%02d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">:</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%02d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">,</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%03d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> (<span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">/</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">3600000</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">%</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">3600000</span><span style="color: rgb(0, 0, 0); ">/</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">60000</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">%</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">60000</span><span style="color: rgb(0, 0, 0); ">/</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1000</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">i</span><span style="color: rgb(0, 0, 0); ">%</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1000</span>)<br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">flag</span> <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;-&#39;</span> <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(0, 0, 0); ">srttime</span> <span style="color: rgb(0, 136, 0); ">or</span> <span style="color: rgb(0, 0, 0); ">srttime</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">srt_split</span><span style="color: rgb(0, 0, 0); ">():</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span>) <span style="color: rgb(0, 0, 0); ">&lt;</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">3</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\n\n\t</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">please read source code for usage</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\n\n</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">exit</span>(<span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span>)</p>
<p> &nbsp; <span style="color: rgb(0, 0, 0); ">filename</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">]</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">splits</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">2</span><span style="color: rgb(0, 0, 0); ">:]</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">offset</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">startswith</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;offset=&quot;</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">offset</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">srttime2int</span>(<span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">][</span><span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;offset=&quot;</span><span style="color: rgb(0, 0, 0); ">):])</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">splits</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">:]</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;24:00:00&quot;</span>) <span style="color: rgb(136, 136, 136); ">#assume no more than 24 hours <img src='http://www.2maomao.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">splits</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">srttime2int</span>(s) <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> s <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">]</span></p>
<p> &nbsp; <span style="color: rgb(0, 0, 0); ">lines</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(0, 0, 0); ">filename</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;rb&quot;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">read</span>()<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">splitlines</span>()<br /> &nbsp; <span style="color: rgb(0, 0, 0); ">f</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;001.srt&quot;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;wb&quot;</span>)<br /> &nbsp; <span style="color: rgb(0, 0, 0); ">newlines</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[]</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">count</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><br /> &nbsp; <span style="color: rgb(0, 0, 0); ">limit</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">]</span> <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(0, 0, 0); ">offset</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">lines</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(136, 136, 136); ">#00:01:16,564 &#8211;&gt; 00:01:18,532</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">line</span>)<span style="color: rgb(0, 0, 0); ">&gt;=</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">29</span> <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">13</span><span style="color: rgb(0, 0, 0); ">:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">16</span><span style="color: rgb(0, 0, 0); ">]</span> <span style="color: rgb(0, 0, 0); ">==</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&#8211;&gt;&quot;</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">start</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">srttime2int</span>(<span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">[:</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">12</span><span style="color: rgb(0, 0, 0); ">])</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">end</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">srttime2int</span>(<span style="color: rgb(0, 0, 0); ">line</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">17</span><span style="color: rgb(0, 0, 0); ">:])</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">start</span> <span style="color: rgb(0, 0, 0); ">&gt;</span> <span style="color: rgb(0, 0, 0); ">limit</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">writelines</span>(<span style="color: rgb(0, 0, 0); ">newlines</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">close</span>()<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">newlines</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">offset</span> <span style="color: rgb(0, 0, 0); ">+=</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">count</span><span style="color: rgb(0, 0, 0); ">]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">count</span> <span style="color: rgb(0, 0, 0); ">+=</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">limit</span> <span style="color: rgb(0, 0, 0); ">+=</span> <span style="color: rgb(0, 0, 0); ">splits</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">count</span><span style="color: rgb(0, 0, 0); ">]</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">f</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">open</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(51, 51, 187); background-color: rgb(255, 240, 240); ">%03d</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">.srt&quot;</span> <span style="color: rgb(0, 0, 0); ">%</span> (<span style="color: rgb(0, 0, 0); ">count</span><span style="color: rgb(0, 0, 0); ">+</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">),</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;wb&quot;</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">int2srttime</span>(<span style="color: rgb(0, 0, 0); ">start</span> <span style="color: rgb(0, 0, 0); ">-</span> <span style="color: rgb(0, 0, 0); ">offset</span>) <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot; &#8211;&gt; &quot;</span> <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(0, 0, 0); ">int2srttime</span>(<span style="color: rgb(0, 0, 0); ">end</span> <span style="color: rgb(0, 0, 0); ">-</span> <span style="color: rgb(0, 0, 0); ">offset</span>)<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">newlines</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>(<span style="color: rgb(0, 0, 0); ">line</span> <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\r\n</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span>)<br /> &nbsp; <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">writelines</span>(<span style="color: rgb(0, 0, 0); ">newlines</span>)<br /> &nbsp; <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">close</span>()</p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">__name__</span> <span style="color: rgb(0, 0, 0); ">==</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;__main__&quot;</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">doctest</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">doctest</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">testmod</span>()<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">srt_split</span>()</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fsrt-subtitle-splitter-in-python%2F&amp;linkname=SRT%20subtitle%20splitter%EF%BC%8C%E5%AD%97%E5%B9%95%E5%88%86%E5%89%B2%E7%A8%8B%E5%BA%8F%EF%BC%8Cin%20Python"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/srt-subtitle-splitter-in-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Windows下的用vim编辑javascript: ctags, taglist, javscript设置</title>
		<link>http://www.2maomao.com/blog/vim-ctags-taglist-javascript/</link>
		<comments>http://www.2maomao.com/blog/vim-ctags-taglist-javascript/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 10:02:31 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[发芽网开发记录]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1377</guid>
		<description><![CDATA[前提：
1. 安装Ctags，只要把ctags.exe解压到你的系统PATH所在的任意文件夹下就可以，不知道的话就放到system32下吧。其他文件不需要
2. 安装gvim的taglist.vim插件
设置：
1. 打开命令行，输入: cd %HOMED... ]]></description>
			<content:encoded><![CDATA[<p>前提：<br />
1. 安装<a href="http://ctags.sourceforge.net/ctags.html">Ctags</a>，只要把ctags.exe解压到你的系统PATH所在的任意文件夹下就可以，不知道的话就放到system32下吧。其他文件不需要<br />
2. 安装gvim的<a href="http://www.vim.org/scripts/script.php?script_id=273">taglist.vim插件</a></p>
<p>设置：<br />
1. 打开命令行，输入: cd %HOMEDRIVE%%HOMEPATH% (一般在 C:\Documents and Settings\登录用户名\ 目录下 )<br />
2. 在该目录下建立一个文件名为 ctags.cnf<br />
3. 在该文件里面输入：</p>
<pre class="mycode">
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*new[ \t]+Object\(/\1/o,object/
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/o,object/
--regex-JavaScript=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/f,function/
--regex-JavaScript=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\([^\]\)]*\)/\1/f,function/
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*new[ \t]+Array\(/\1/a,array/
--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/a,array/
--regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*[^""]'[^'']*/\1/s,string/
--regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*[^'']"[^""]*/\1/s,string/
</pre>
<p>4. 在.vimrc文件里面加上一行:</p>
<pre class="mycode">
let tlist_js_settings = 'javascript;s:string;a:array;o:object;f:function'
</pre>
<p>好了，配置完成，现在用gvim打开一个包含很多函数定义的.js文件(不要是.min.js的啊)，输入:Tlist就可以啦<br />
上图：<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/vim_taglist_ctags_js1.png" alt="vim_taglist_ctags_js1" title="vim_taglist_ctags_js1" width="600" height="362" class="alignnone size-full wp-image-1383" /><br />
其他vim+javascript设置： <a href="http://www.vim.org/scripts/script.php?script_id=1491">javascript.vim</a></p>
<p>参考：<br />
 * <a href="http://stackoverflow.com/questions/1790623/how-can-i-make-vims-taglist-plugin-show-useful-information-for-javascript">http://stackoverflow.com/questions/1790623/how-can-i-make-vims-taglist-plugin-show-useful-information-for-javascript</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fvim-ctags-taglist-javascript%2F&amp;linkname=Windows%E4%B8%8B%E7%9A%84%E7%94%A8vim%E7%BC%96%E8%BE%91javascript%3A%20ctags%2C%20taglist%2C%20javscript%E8%AE%BE%E7%BD%AE"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/vim-ctags-taglist-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>深圳的景色真不错</title>
		<link>http://www.2maomao.com/blog/shenzhen-better-city-to-live-than-beijing/</link>
		<comments>http://www.2maomao.com/blog/shenzhen-better-city-to-live-than-beijing/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 14:37:26 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[思维像发情的猴子]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1375</guid>
		<description><![CDATA[去香港玩，路过深圳姐姐家
昨天去了青青乐园，环境真好，印象深刻的是里面的大鱼海象还有恐龙山谷，特别是恐龙山谷里面逼真的恐龙以及模拟的热带雨林环境再配上恐龙叫声，如同身临其... ]]></description>
			<content:encoded><![CDATA[<p>去香港玩，路过深圳姐姐家</p>
<p>昨天去了青青乐园，环境真好，印象深刻的是里面的大鱼海象还有恐龙山谷，特别是恐龙山谷里面逼真的恐龙以及模拟的热带雨林环境再配上恐龙叫声，如同身临其境，随便录段像就成电影了</p>
<p>还有就是里面的玩具：推铁圈、肥皂泡等等，勾起了我对小时候的美好回忆；乐乐玩的很开心，不过她最钟情的是爬草坡，上去下来，乐此不疲。</p>
<p>今天去了大梅沙，一片很不错的沙滩，上面人很少，停车非常方便，乐乐跟煦煦两个小宝宝玩得不亦乐乎，我和猫猫也跑来跑去玩的很放松，很久没有这种感觉了：生活真美好！</p>
<p>对深圳的感受很好，这里路面、车子、公共环境还有人，都给人干净利落的感觉。整个环境依山傍水，天空碧蓝碧蓝的，晚上抬头可以看见月亮上面的阴影，总是禁不住要深呼吸，感觉被北京的沙尘污染的肺都被清洗了一样。</p>
<p>这篇文章归类为：思维像发情的猴子。。。主要原因是我的一个想法，关于未来的交通方式，那种直接传送是最好啦，但是在那么玄幻之前，我设想的交通方式叫做：<b>自动交通网络</b>。</p>
<p>比如我在清华大学东门，想去北京西站，只要走上街头，在触屏上选择目的地，然后一辆电梯就到了，坐进去以后，电梯自动选择交通网络，就像网络的路由一样，流量控制，排队，自动选择路线，然后帮我计算到达目的地的时间，直到到达，途中可以改变目的地，还可以在里面上网或者观看城市景色，根据里程计费。</p>
<p>没有交通事故，没有堵车，个人化，娱乐化，直达，多好的未来！！！</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fshenzhen-better-city-to-live-than-beijing%2F&amp;linkname=%E6%B7%B1%E5%9C%B3%E7%9A%84%E6%99%AF%E8%89%B2%E7%9C%9F%E4%B8%8D%E9%94%99"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/shenzhen-better-city-to-live-than-beijing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>失败的设计 - 医院报告单自助打印系统</title>
		<link>http://www.2maomao.com/blog/bad-design-auto-printer-in-hostpital/</link>
		<comments>http://www.2maomao.com/blog/bad-design-auto-printer-in-hostpital/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 03:34:41 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[失败的设计]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1371</guid>
		<description><![CDATA[失败的设计系列很久没更新啦，呃，其他的也没更新。。。
昨天去医院拿检查结果，想到报销的时候需要打单据，告诉我说改进了，可以自助打印。高兴啊，以前还要排长队的，打两张单子，... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.2maomao.com/blog/?s=%E5%A4%B1%E8%B4%A5%E7%9A%84%E8%AE%BE%E8%AE%A1&#038;sbutt=%E6%90%9C%E7%B4%A2%E6%9C%AC%E7%AB%99">失败的设计系列</a>很久没更新啦，呃，其他的也没更新。。。</p>
<p>昨天去医院拿检查结果，想到报销的时候需要打单据，告诉我说改进了，可以自助打印。高兴啊，以前还要排长队的，打两张单子，至少排一个半小时</p>
<p>后来发现，不是这样的，一部分可以打印，一部分还得排队，要想报销，得先排队打一部分单子，然后再自助打印。。。总是把好事办成坏事啊</p>
<p>好吧，上上下下好几回楼梯，缴费、复印，搞定了一半，然后来到了自助打印系统跟前。。。跟前围了一批人，说打印机坏了怎么的，我没在意，看到一个巨大的触摸屏上说点击屏幕开始，下方有个明显的卡片扫描处</p>
<p>我按照银行取款机的操作步骤，先插医院信息卡，再想去点击屏幕开始的时候，发现它自动切换到打印界面了，心中暗赞不错不错；然后点击全部打印；吱吱吱吱的声音想起。。。<br />
。。。<br />
1分钟以后<br />
。。。<br />
啥也没有！<br />
啥也没出来！</p>
<p>怎么办？问了一圈儿，一位老大妈施施然走了过来，说没看见屏幕提示吗，那么大的字都看不见，会认字的三岁小孩都看得见，先点击屏幕开始才能打印，否则有问题啊。。。</p>
<p>啊啊啊啊啊啊啊。。。然后，你猜到了，按照此步骤操作以后，信息显示我的单子已经打过了，要想再打需要挂号让医生打印了</p>
<p>Fuck！</p>
<p>如果是个很好的设计，“点击屏幕开始”这一步是不需要的<br />
如果是个不那么好的设计，没有“点击屏幕开始”之前，扫描卡片可以提示“先点击屏幕开始”<br />
如果是个不那么坏的设计，没有“点击屏幕开始”之前，扫描卡片至少不能进行后续操作<br />
如果是个有点坏的设计，没有“点击屏幕开始”之前，扫描卡片开始之后，至少打印不成功也不能把记录销了吧</p>
<p>我操！</p>
<p>&#8211;</p>
<p>之所以想写这篇博客，主要动力是愤怒，对于失败的设计的愤怒，对于医院人员态度的愤怒<br />
好吧，我知道，一切的一切的根源，实际上在于制度，这个没有反馈和自省机制的制度</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fbad-design-auto-printer-in-hostpital%2F&amp;linkname=%E5%A4%B1%E8%B4%A5%E7%9A%84%E8%AE%BE%E8%AE%A1%20-%20%E5%8C%BB%E9%99%A2%E6%8A%A5%E5%91%8A%E5%8D%95%E8%87%AA%E5%8A%A9%E6%89%93%E5%8D%B0%E7%B3%BB%E7%BB%9F"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/bad-design-auto-printer-in-hostpital/feed/</wfw:commentRss>
		</item>
		<item>
		<title>zz: 人民的利益至上，人民的生命之上</title>
		<link>http://www.2maomao.com/blog/zz-people-life-matters-the-most/</link>
		<comments>http://www.2maomao.com/blog/zz-people-life-matters-the-most/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 02:48:23 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[一些链接]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1369</guid>
		<description><![CDATA[很久没写博，主要是项目忙，工作和家庭之间留给自己的空隙太少，没有时间思考了
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
zz from: 茅于轼的博客 » 人民的利益至上，人民的生命之上
  2005... ]]></description>
			<content:encoded><![CDATA[<p>很久没写博，主要是项目忙，工作和家庭之间留给自己的空隙太少，没有时间思考了<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
zz from: <a href="http://www.de-sci.org/blogs/maoyushi/?p=49366">茅于轼的博客 » 人民的利益至上，人民的生命之上</a></p>
<p>  2005年我写了一篇题为“人民的利益，国家的利益，政治家的利益”的文章，指出这三者之间的相同和不同。过去的几千年出于政治家的利益，他们故意把人民的利益和国家的利益混为一谈，极大地误导了一国的老百姓，叫他们无谓地作出巨大牺牲。所谓的“人民群众是历史的主人”就是这样构成的。当今进入二十一世纪，人民的教育水平极大地提高，继续欺骗老百姓越来越不容易了。要想世界真正安宁，彻底消灭战争，必须十分清楚地区分这三者的不同，并且把人民的利益放在第一位，其他各种不同的说法都要被揭穿，防止百姓被愚弄。</p>
<p>    在一般情况下人民的利益和国家的利益是一致的。因为国家之所以出现正是因为人民有集体利益，需要有公共事务的管理者，于是出现了国家组织。市场可以提供百姓的吃，穿，用。但是市场的秩序需要有市场之外的权威来维持。过去还有外族的侵略，需要用集体的力量来保护自己。国家能够组织分散的百姓，成为可以抵御外侵的力量。所以国家本来就是为了人民的。</p>
<p>    但是一旦有了国家，有了公共事务的管理者，就出现了一批专门从事于政治的人，他们逐渐成为统治者。他们的利益不同于百姓的利益。可是他们为了达到自己的目的，实现自己的利益目标，往往欺骗百姓，叫他们为国牺牲。其实是为了他们一己的利益去送死。世界上绝大部分的战争就是这样打起来的。希特勒发动战争，他认为日耳曼民族是最优秀的民族，要消灭劣等民族。用牺牲上千万百姓的生命为代价，达到他那个毫无根据的目标。这个人类极大的悲剧就是希特勒等极少数人鼓动造成的。日本军国主义发动侵华战争，其理论根据是制造大东亚共荣圈，用双方死人的战争方法去实现一个自以为是的目标。现在日本和东亚国家实现了共荣，但是完全不是用战争手段。东条英机等人之所以能够动员日本百姓去送死，就是因为他们制造了效忠天皇的理论，误导了日本百姓。各国的统治者都会叫百姓为他们的利益牺牲，他们不大会主动揭穿其中的把戏。这个工作必须由民间学者来完成。</p>
<p>    什么是人民的利益？我认为就是每一个有血有肉的个人的利益，不是空洞的集体利益。的确，有一种利益被称为集体利益，它是通过集体来体现的，但这个利益最后必须落实到具体个人的利益。比如讲，为了集体利益国家对某个人判处死刑。我们就要问，是什么理由杀一个老百姓？如果不是为了其他百姓的利益（比如这个人对别人有极大的危险性），仅仅是为了国家而杀一个人是绝对不允许的。因反对毛泽东而被判死刑者不计其数。但这是完全错误的。毛泽东也是一个人，别人也是一个人，凭什么毛泽东就不能反，别人反了他就要被处死？甚至对他的照片扔墨水瓶都要判处无期徒刑？以颠覆国家的罪名给百姓判刑也是值得怀疑的。国家是不可能被颠覆的，只有政府里的执政者可能被颠覆。如果这个国家的执政者给百姓制造灾难，为什么就不能颠覆？我们都说陈胜吴广揭竿而起是符合正义的。这说明政府不是不可以反的，只有人民才是不可以反的。按照这个道理连叛国罪都未必能够成立。二战时有一些日本人反对军国主义的侵华战争而叛逃来到中国，这个叛国是非常正确的，因为这种叛国有利于中日两国人民，是符合正义的。叛国未必不可以，叛人民是绝对错误的。总之，国家的利益要服从人民的利益，而不是相反。可惜的是统治者老是灌输国家利益至上，提倡爱国主义。偶尔点一下人民的利益，也要把它置于国家利益之下。今天我们要彻底纠正这个被歪曲了几千年的理论。</p>
<p>    “个人利益”并不等同于“人民利益”。个人利益的对立面是另外一个个人；人民利益的对立面是国家。处理个人利益的原则是平等。每个人和其他人都是平等的，没有理由厚此薄彼。说此人要为那人牺牲，是完全没有道理的。但是处理人民的利益时，它面对的是国家，二者是不平等的。人们常说个人利益要服从国家利益。这时候我们要问，国家利益体现在什么地方？是不是能够落实到具体的人？处理这两种利益时，必须认清国家的利益最后一定要落实到个人，绝不许可叫人民为空洞的国家利益去牺牲，否则就会上当，上希特勒或东条英机的当。</p>
<p>   人们经常讲的国家利益往往是主权的独立，领土的完整，国家的尊严。这三者能不能还原为每一个人的具体利益是大有问题的。在某些情况下，失掉一点领土，但是那儿的百姓能够生活得更自由，更富有，对百姓是有利的。这样的领土完整就没有必要去追求。但这种观点是不能被统治者接受的，也不大会被普通人接受，因为普通人受了几千年的统治者的教育，把国家的利益放在了人民利益之上。在现实世界中，我们可以看到许多生活在缺乏自由的国家的百姓，冒着生命的危险偷渡去比较自由的国家。这是百姓对这个问题的真实回答。更有一些情况，那儿的领土压根儿就没人居住，争夺那儿的领土完整，却要百姓付出沉重的代价，有什么必要？这些例子尖锐地显示出国家利益和人民利益的不同。可惜的是经常有人喊：誓死保卫XX岛，愿意用自己的生命去保卫它。可是那儿连一个居民都没有。一个人的生命为什么那么不值钱，简单说，就是因为受了政治家的蒙骗。牺牲自己为人民的利益是对的，可是牺牲自己为国家就要好好想一想，是不是真有必要。</p>
<p>    至于国家的尊严，更不是我们应该重视的事情。所谓国家的尊严，其实是政治家的尊严。普通百姓没有任何对尊严的非分之想。可是政治家们对此非常敏感，常常鼓动人民为了国家尊严去奋斗，甚至于为此而牺牲生命。所谓尊严无非就是争个高低。这件事情本来就是没有解的，因为不可能双方都比对方高一头。有一方高，必有另一方低。双方都为高低而争，结果只能是劳民伤财，浪费人民的力量。翻开报纸看每天的新闻，绝大多数国与国之间的矛盾都跟百姓的利益无关，是政治家们制造出来的事端。有时候说美国和日本要结盟，是针对中国而来的；又说中俄联盟有利于抵制日美；又有消息说印度想联合俄国对付中国等等。这些构想都是各方面的政治家无事生非，凭空制造的，让老百姓上当受骗的理论。其实，在此期间百姓照样过自己的日子，照样去别国旅游，一点也没感到国家关系有了什么变化。政治家制造事端当然有其目的。他们就是吃这口饭的。没有了这些想象出来的矛盾，百姓过着他们的太平日子，他们就要失业了。</p>
<p>    最典型的是美苏冷战四十多年，从1945战到1989，从冷战发展到热战。双方各自耗费的人力物力不计其数，做了无数的宣传，外交家们飞来飞去，开了无数的会议。朝鲜战争，越南战争双方死亡上百万，为的是争一个什么什么主义。一国里最高的智慧都用来搞垮对方，双方的间谍出生入死，花费了天文数字的军事开支。到1989年苏联垮台，冷战无声无息地烟消云散。原来所谓的敌对国家，完全是政治家们制造出来无中生有的事。可是百姓上当受骗，为此牺牲，从冷战到热战，直接间接总共死了一亿多人。造成财富的浪费，贫困的增加，百姓的痛苦，更无法计量。冷战虽然过去了，但是没有人出来总结，这场骗局给人类什么教训。老毛病还继续在犯。政治家继续编文章，制造矛盾，鼓动百姓之间的敌对情绪，号召百姓为国牺牲。</p>
<p>    我不是说政治家都是没有良心的人。他们中绝大多数都是很想做好事的人。可是他们同样受传统教育太深，中了“以国为本”的毒，忘记了“以民为本”。再加上自身的职业利益，把国与国之间的矛盾搞的愈大，愈能显出自己职务的重要性。</p>
<p>    所谓敌对势力也是政治家制造出来的名词。统治者往往用“勾结境内外敌对分子”的罪名迫害自己的百姓。对老百姓而言，何来敌对势力？谁跟谁会无缘无故敌对起来？除了极个别的人，一般人都喜欢交朋友。所以“有朋自远方来不亦说乎”，哪来互相敌视呢。政治家则不同，他们最担心的是自己的统治者地位保不保得了，生怕有人抢了他们的统治者的地位。他们把一切想当统治者的人都看成是敌对分子，甚至不同意他们统治的人也看成是敌对分子。过去皇权社会统治者是天子，是天老爷的儿子，无人可替代。现在是人民共和国，再也不好意思说自己是天子，是不可替代的。宪法上规定年满45岁的公民有资格当选国家主席。但实际上干的是“打天下，坐天下”，还是皇权社会的一套。改革后变成“由革命党转变为执政党”，打天下的人都死了，接班人继续坐天下，基本上还是老调子。如果有人说要改变一下统治者，那就是敌对分子。其实老百姓对谁是统治者并不在乎，百姓要的是人身不受侵犯，财产得到保护，言论有自由，宗教有自由。可是统治者要享受特权，百姓就没有了人权，于是矛盾就来了。分析到这里我们看到，所谓敌对分子的来由是特权和人权的冲突。政治家的敌对分子是人权受到侵犯的一批人。政治家并不会无缘无故地侵犯别人的人权，是因为他们要有特权，才会发生冲突。</p>
<p>    政治家还有一个伎俩，把一般民间纠纷提升为国家矛盾。最近的一个例子是俄罗斯小孩被美国护士收养，一年后养母发现这孩子精神不正常，把他送回了俄罗斯。本来这是一般的家庭纠纷，但是双方的政治家为了国家的尊严，纷纷出面指责对方。外交家们坐头等舱飞机，住五星级宾馆，花百姓的钱，开会为国家挣面子，其实就是为了他们自己的职业利益。如果还原为家庭纠纷，问题并不难解决。因为变成了国家事务，就越搞越复杂了。这就是政治家们所起的作用。可惜的是大多数老百姓跟着起哄，他们不了解自己的真正利益是在什么地方。如果百姓懂得自己真正的利益所在，不被政治家的国家至上的谬论所误导，世界上大部分的战争根本打不起来。</p>
<p>    在个别情况下为国牺牲是有必要的。当外国入侵我国，要把中国人当成没有人权保障的亡国奴，我们毫无疑问要奋起反抗，甚至为此而牺牲生命。这种情况之所以发生，是因为对方国家的政治家为了自己的野心，欺骗百姓上战场去送死，形成两国对立的局面。如果全世界所有国家的百姓都懂得自己真正的利益所在，能够抵制政治家的野心，就不会发生侵略别国的事情。百姓追求的是安居乐业，如果没有政治家的鼓动和强迫，绝不会主动要求离开妻子儿女上战场去拼命，去杀和自己无冤无仇，和自己一样，也有妻子儿女的别国的百姓。一个普通百姓被政治家动员或胁迫上了战场，手上端着枪，瞄准一个敌人，他会毫不犹疑地搬动机关，把对方杀死。如果在平时他绝不会无缘无故地杀一个人。上了战场的人已经没有别的选择，你不杀死对方，对方就会把你杀了。正好像古罗马的斗兽场，贵族们让两个奴隶斗士表演杀人。这两个奴隶总有一个要死去。战场和斗兽场其实并没有根本性的区别。所以说，要消灭战争，一定要让各国的百姓能够抵制那儿的政治家的宣传，而且有力量对抗政治家对普通百姓的强制性行为。首先要提高警惕，认清盲目提倡爱国主义的宣传。爱国主义是对的，但是这个爱国必须能够落实到具体的百姓的利益。我们要旗帜鲜明地抵制坑害百姓的爱国主义。爱国主义绝不是极终真理。两个国家的爱国主义造成两国对立，挑起仇恨，最后倒霉的是两国的百姓。爱人民（中国的和外国的），这才是极终真理。</p>
<p>    我国的近代战争中，只有抗日战争是建立在人民利益之上的。其他的许多战争都不符合人民利益至上的原则。抗日战争之所以必要，是因为日本军国主义者的霸权思想。日本人可以骑在中国人的头上作威作福，可以任意残害中国人。我们没有别的选择，必须奋起抗日。其他的战争都不是为了人民，实际上是为了少数政治家，他们有统治中国的野心，还有在国际上耀武扬威的欲望。这不仅仅是中国的政治家如此，各国的政治家很少能跳出这种诱惑的。从最近解密的材料看，美国在伊拉克打死了十万人，其中七万是伊拉克人，绝大部分是平民百姓。发动战争有一万条理由，也无权杀人。发动战争的人自己并不上前线，他们要求百姓牺牲生命，牺牲每个人只能有唯一一次的生命。从百姓个人的利益来看，只有自己或别人（中国人的和外国人的）的生命受到威胁时才有牺牲自己的必要。而不是为了某个政治家的利益或理想。生命是第一性的。</p>
<p>    第二次世界大战在欧洲战场上如果希特勒胜了，这个政权是一个不讲人权的独裁者，会继续屠杀犹太人和一切非雅利安人种。幸亏是英美联军胜了，胜利一方没有漠视人权，而是帮助战败国重新站起来。现在的德国是世界强国之一，百姓享受着自由和平等。在亚洲战场上也一样，日本人并没有因战败而成为奴隶。相反，摆脱了军国主义的胁迫和欺骗，得到了繁荣和幸福。这证明了战胜的一方是符合正义的。可叹的是我们这个战胜国反而陷入了内战和百姓对百姓的阶级斗争，遭受了巨大的灾难。而这一切都是在“解放全世界无产者“和“捍卫无产阶级革命路线”等欺骗性的革命口号下进行的。我们还要随时警惕纳粹主义和日本军国主义，和一切欺骗百姓的理论的卷土重来。</p>
<p>    只有人民利益至上，世界才能太平。不过这个目标看起来离我们还远得很，一时还很难被普遍接受。但是我们不要灰心，必须不断努力争取早日实现。因为没有别的出路。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fzz-people-life-matters-the-most%2F&amp;linkname=zz%3A%20%E4%BA%BA%E6%B0%91%E7%9A%84%E5%88%A9%E7%9B%8A%E8%87%B3%E4%B8%8A%EF%BC%8C%E4%BA%BA%E6%B0%91%E7%9A%84%E7%94%9F%E5%91%BD%E4%B9%8B%E4%B8%8A"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/zz-people-life-matters-the-most/feed/</wfw:commentRss>
		</item>
		<item>
		<title>绕过Bluehost的数据库连接限制(Django/发芽网)</title>
		<link>http://www.2maomao.com/blog/work-around-max_user_connections/</link>
		<comments>http://www.2maomao.com/blog/work-around-max_user_connections/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 04:17:39 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[发芽网开发记录]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1365</guid>
		<description><![CDATA[最近个把月，发芽网的访问量有所上升，直接后果就是数据库报错，说我的数据库用户链接数超过了max_user_connections
联系了一下bluehost，客服跟我说，最近他们设置了max_user_connections为15， 建议... ]]></description>
			<content:encoded><![CDATA[<p>最近个把月，<a href="http://fayaa.com">发芽网</a>的访问量有所上升，直接后果就是数据库报错，说我的数据库用户链接数超过了max_user_connections</p>
<p>联系了一下<a href="http://www.bluehost.com/track/realfun/blog">bluehost</a>，客服跟我说，最近他们设置了max_user_connections为15， 建议我多用cache方式减少数据库连接，并根据我用的是Django推荐了<a href="http://superjared.com/projects/static-generator/">django-staticgenerator</a>，我看了一下，还不错，但是最近太忙了，时间上估计来不及。</p>
<p>跟<a href="http://www.bluehost.com/track/realfun/blog">bluehost</a>抱怨了一下连接数太少，顺便想到了一个暂时的解决方案：<br />
1. 在settings.py里面加入了一个DATABASE_USERS的新变量，里面放上很多个用户名，这些用户对发芽网的数据库都有同样的访问权限，同样的密码<br />
2. 在后台的python2.6/lib/site-packages/django/db/__init__.py里面，把获取数据库用户的赋值改成了random.choice( settings.DATABASE_USERS )</p>
<p>暂时来看，应该还是有点效果了，先观察几天再说。</p>
<p>BTW: <a href="http://www.2maomao.com/blog/fayaa-openid/">给发芽网添加了OpenID支持</a>以后，到现在已经有80个用户使用了OpenID，多数都是Google的，第二位的是Yahoo，呵呵这个结果还不错。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fwork-around-max_user_connections%2F&amp;linkname=%E7%BB%95%E8%BF%87Bluehost%E7%9A%84%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E9%99%90%E5%88%B6%28Django%2F%E5%8F%91%E8%8A%BD%E7%BD%91%29"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/work-around-max_user_connections/feed/</wfw:commentRss>
		</item>
		<item>
		<title>给发芽网添加OpenID支持，Google帐户登陆很方便</title>
		<link>http://www.2maomao.com/blog/fayaa-openid/</link>
		<comments>http://www.2maomao.com/blog/fayaa-openid/#comments</comments>
		<pubDate>Mon, 17 May 2010 14:13:01 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[发芽网开发记录]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1357</guid>
		<description><![CDATA[
上周刚刚做好，欢迎小白鼠 
(好像已经有十几个了，大部分都是Google用户)
登陆以后，可以选择生成新帐户（只要稍微改改就行，懒的话直接添个验证码，反正已经有三个人这么做了），或者... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://fayaa.com/user/login/"><img src="http://www.2maomao.com/blog/wp-content/uploads/fayaa-openid-1.gif" alt="fayaa-openid-1" title="fayaa-openid-1" width="517" height="307" class="alignnone size-full wp-image-1358" /></a></p>
<p>上周刚刚做好，欢迎小白鼠 <img src='http://www.2maomao.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
(好像已经有十几个了，大部分都是Google用户)</p>
<p>登陆以后，可以选择生成新帐户（只要稍微改改就行，懒的话直接添个验证码，反正已经有三个人这么做了），或者绑定到老帐户，以后登录发芽网就可以多渠道了。而且，支持绑定多个Openid到一个发芽网帐号哦~~~！</p>
<p><a href="http://fayaa.com/user/login/"><img src="http://www.2maomao.com/blog/wp-content/uploads/fayaa-openid-2.gif" alt="fayaa-openid-2" title="fayaa-openid-2" width="605" height="323" class="alignnone size-full wp-image-1359" /></a></p>
<hr />
<p><strong>关于实现</strong>：</p>
<p>查了一下<a href="http://fayaa.com/code/view/794/updates/">发芽网的Roadmap</a>，大概八个月前，加入了OpenID的需求，这是个计划了很久的功能，刚刚想到的时候改了一半，结果没做完的工作直接导致了八个月内不敢做其他的更新，看来版本管理还是要做做好。</p>
<p>以下是准备过程：<br />
最初的时候，想用<a href="http://code.google.com/p/django-openid-auth/">Django-Openid-Auth</a><br />
后来感觉本地用户还是需要的，就想用<a href="http://code.google.com/p/django-authopenid/">Django-Authopenid</a>，被Nonce搞到晕<br />
再后来，想过用<a href="http://www.google.com/friendconnect/">Google Friend Connect</a>(谷鸽迁徙香港后放弃）<br />
然后还试过<a href="http://uswaretech.com/blog/2009/08/django-socialauth-login-via-twitter-facebook-openid-yahoo-google/">Django SocialAuth</a><br />
还试过修改<a href="http://code.google.com/p/gaema/">gaema</a><br />
。。。<br />
最终，回到起点，仔细研究了一下<a href="http://openidenabled.com/python-openid/">python openid</a>的库以及<a href="http://openid.net/developers/specs/">openid的spec</a>，基于python openid自己写了一个<br />
(model那部分代码直接copy了django-authopenid)</p>
<hr />
<strong>PS</strong>:<br />
这段时间很少有精力改进发芽网，一半的周末用于来往京津高速回家赔<a href="http://maomao.2maomao.com/">乖女儿乐乐</a>，带她挖沙子是主要任务，呵呵</p>
<p>另外，来北京快5年了，前不久才去了故宫、簋街、南锣鼓巷，长城至今还没有去过，跟猫猫一合计，现在不转转真是对不住自己每天这么辛苦，于是另外一半的周末，一部分时间在北京转转玩玩，另一部分的时间，在睡觉，以及做爱做的事情。。。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ffayaa-openid%2F&amp;linkname=%E7%BB%99%E5%8F%91%E8%8A%BD%E7%BD%91%E6%B7%BB%E5%8A%A0OpenID%E6%94%AF%E6%8C%81%EF%BC%8CGoogle%E5%B8%90%E6%88%B7%E7%99%BB%E9%99%86%E5%BE%88%E6%96%B9%E4%BE%BF"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/fayaa-openid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>关于Singleton (单件)，线程安全</title>
		<link>http://www.2maomao.com/blog/when-cplusplus-meet-singleton/</link>
		<comments>http://www.2maomao.com/blog/when-cplusplus-meet-singleton/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 10:58:33 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1354</guid>
		<description><![CDATA[很就没写技术相关的blog了，Twitter和Buzz都很少用了，甚至很少有时间静下来思考、敲打键盘
今天面试问到static关键字的时候，有个应试者提到了Singleton的实现，就顺便多问了一点儿，回来自己... ]]></description>
			<content:encoded><![CDATA[<p>很就没写技术相关的blog了，Twitter和Buzz都很少用了，甚至很少有时间静下来思考、敲打键盘</p>
<p>今天面试问到static关键字的时候，有个应试者提到了Singleton的实现，就顺便多问了一点儿，回来自己又查了查</p>
<p>Singleton，单件，四人帮(<a href="http://en.wikipedia.org/wiki/Gang_of_Four_(disambiguation)">GoF</a>)写design pattern那本书的时候提出来的，一个进程内有且只有一个实例</p>
<p>说起这些Design Pattern，当时一看，我操，酷毙了，你不知道都不好意思跟别人说你是搞编程的</p>
<p>后来，渐渐的发现，没有银弹，只是有些Design Pattern或许有些淫荡，比如这个Singleton</p>
<p>一个最初的C++标准实现是这样的(S-V1)：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 136, 0); font-style: italic; ">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Implementation #1 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br /> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.h</span><br /> <span style="color: rgb(170, 34, 255); font-weight: bold; ">class</span> <span style="color: rgb(0, 0, 255); ">Singleton</span> <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">private</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">instance_</span>;<br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">public</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">getInstance</span>() <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">instance_</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">instance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(170, 34, 255); font-weight: bold; ">new</span> <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">instance_</span>; <span style="color: rgb(0, 0, 0); ">}</span> <span style="color: rgb(0, 0, 0); ">};</span></p>
<p> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.cpp</span><br /> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">::</span><span style="color: rgb(0, 0, 0); ">pInstance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(102, 102, 102); ">0</span>;</div>
<p>注意其中构造函数是私有的，所有只能通过getInstance构造，构造前又会先检查，所以只有一个</p>
<p>后来有人说，这样不是线程安全的，哦，那就简单点儿，这样吧(S-V2)：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 136, 0); font-style: italic; ">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Implementation #2 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br /> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.h</span><br /> <span style="color: rgb(170, 34, 255); font-weight: bold; ">class</span> <span style="color: rgb(0, 0, 255); ">Singleton</span> <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">private</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">public</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">getInstance</span>() <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">instance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(170, 34, 255); font-weight: bold; ">new</span> <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">instance_</span>; <span style="color: rgb(0, 0, 0); ">}</span> <span style="color: rgb(0, 0, 0); ">};</span></div>
<p>结果有人说，这个是依赖于编译器的，GCC能保证static的初始化不会出问题，但是VC就难说了。<br />
于是，有人觉得既然第一个实现稍微改改就行了，只要加一个淫荡的锁(S-V1.1)：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 136, 0); font-style: italic; ">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Implementation #1.1 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br /> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.h</span><br /> <span style="color: rgb(170, 34, 255); font-weight: bold; ">class</span> <span style="color: rgb(0, 0, 255); ">Singleton</span> <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">private</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">instance_</span>;<br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">public</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">getInstance</span>() <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">lock_mutex</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">instance_</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">instance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(170, 34, 255); font-weight: bold; ">new</span> <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">unlock_mutex</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">instance_</span>; <span style="color: rgb(0, 0, 0); ">}</span> <span style="color: rgb(0, 0, 0); ">};</span></p>
<p> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.cpp</span><br /> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">::</span><span style="color: rgb(0, 0, 0); ">pInstance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(102, 102, 102); ">0</span>;</div>
<p>再后来，有人说这样也不行啊，每次get都加锁，效率太低了吧，那就更加淫荡一点，加锁之前我先check，加锁以后，我再check(S-V1.2)：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 136, 0); font-style: italic; ">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Implementation #1.2 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br /> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.h</span><br /> <span style="color: rgb(170, 34, 255); font-weight: bold; ">class</span> <span style="color: rgb(0, 0, 255); ">Singleton</span> <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">private</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">instance_</span>;<br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">public</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">getInstance</span>() <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">instance_</span>) <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">lock_mutex</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">instance_</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">instance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(170, 34, 255); font-weight: bold; ">new</span> <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">unlock_mutex</span><span style="color: rgb(0, 0, 0); ">();}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">instance_</span>; <span style="color: rgb(0, 0, 0); ">}</span> <span style="color: rgb(0, 0, 0); ">};</span></p>
<p> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.cpp</span><br /> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">::</span><span style="color: rgb(0, 0, 0); ">pInstance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(102, 102, 102); ">0</span>;</div>
<p>到这里，在搜索网络以前，我曾经认为已经OK了，但是多CPU多线程的复杂超乎想象，有人说，后一个实现不是线程安全的，因为对于instance的读和写并不是原子操作会发生写一半读一半的情况！<br />
好吧，对效率没啥要求每个singleton就只会用个几次的用S-V1.1，没有多线程的用S-V2</p>
<hr />
========== 以下我也不是很懂的分割线 ==========</p>
<p>难道真的没办法优化S-V1.1了吗？</p>
<p>有办法，那个instance读一半写一半的情况对于int这个类型是不会发生的，那么，就多来一步，check一个int类型的标识吧：</p>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(0, 136, 0); font-style: italic; ">//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;Implementation #1.3 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span><br /> <span style="color: rgb(0, 136, 0); font-style: italic; ">//s.h</span><br /> <span style="color: rgb(170, 34, 255); font-weight: bold; ">class</span> <span style="color: rgb(0, 0, 255); ">Singleton</span> <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">private</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">instance_</span>;<br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 187, 0); font-weight: bold; ">int</span> <span style="color: rgb(0, 0, 0); ">flag_</span>;<br /> &nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">public</span><span style="color: rgb(102, 102, 102); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">static</span> <span style="color: rgb(0, 0, 0); ">Singleton</span><span style="color: rgb(102, 102, 102); ">*</span> <span style="color: rgb(0, 0, 0); ">getInstance</span>() <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">flag_</span>) <span style="color: rgb(0, 0, 0); ">{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">lock_mutex</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">if</span> (<span style="color: rgb(102, 102, 102); ">!</span><span style="color: rgb(0, 0, 0); ">instance_</span>)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">instance_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(170, 34, 255); font-weight: bold; ">new</span> <span style="color: rgb(0, 0, 0); ">Singleton</span>();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">unlock_mutex</span><span style="color: rgb(0, 0, 0); ">();}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">flag_</span> <span style="color: rgb(102, 102, 102); ">=</span> <span style="color: rgb(102, 102, 102); ">1</span>;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(170, 34, 255); font-weight: bold; ">return</span> <span style="color: rgb(0, 0, 0); ">instance_</span>; <span style="color: rgb(0, 0, 0); ">}</span> <span style="color: rgb(0, 0, 0); ">};</span></div>
<p>嘿嘿，这下你该满足了吧，NO!，还是有问题的，具体啥问题，参见<a href="http://www.oaklib.org/docs/oak/singleton.html">这里</a> 和 <a href="http://en.wikipedia.org/wiki/Singleton_pattern#C.2B.2B">那里</a>，代码已经贴太多了。</p>
<hr />
进行到这里，你应该已经体会到，Singleton是很变态的，Design Pattern是很淫荡的。。。</p>
<p>Singleton最淫荡的地方在于：真正需要它的机会太少太少了，更多讨论参见：<br />
[1] <a href="http://stackoverflow.com/questions/228164/on-design-patterns-when-to-use-the-singleton">Singleton，你坏。。。在哪里？</a><br />
[2] <a href="http://stackoverflow.com/questions/11831/singletons-good-design-or-a-crutch">Singleton，银弹还是狗屎</a><br />
[3] <a href="http://stackoverflow.com/questions/228164/on-design-patterns-when-to-use-the-singleton">Singleton，何日才能用到你</a></p>
<hr />
<p>路人甲：OMG，这是什么代码格式啊！<br />
好吧，肯定有人不喜欢这个缩进，但是我敢肯定，肯定有人知道我喜欢Python了 <img src='http://www.2maomao.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fwhen-cplusplus-meet-singleton%2F&amp;linkname=%E5%85%B3%E4%BA%8ESingleton%20%28%E5%8D%95%E4%BB%B6%29%EF%BC%8C%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/when-cplusplus-meet-singleton/feed/</wfw:commentRss>
		</item>
		<item>
		<title>众里寻它千百度 - Windows XP时间栏自定义工具Tclock</title>
		<link>http://www.2maomao.com/blog/tclock-windows-xp-clock-customize/</link>
		<comments>http://www.2maomao.com/blog/tclock-windows-xp-clock-customize/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 08:00:25 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[小小工具]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1346</guid>
		<description><![CDATA[今天无意间看到Tclock2，爱死了
WindowsXP原有的时间显示有些呆板，特别是我用了双层的任务栏以后，原有的时间显示内容还是那么些，有时候我需要知道今天是哪天，还需要鼠标停留在上面一会... ]]></description>
			<content:encoded><![CDATA[<p>今天无意间看到<a href="http://shii.org/tclock/">Tclock2</a>，爱死了</p>
<p>WindowsXP原有的时间显示有些呆板，特别是我用了双层的任务栏以后，原有的时间显示内容还是那么些，有时候我需要知道今天是哪天，还需要鼠标停留在上面一会儿，还有的时候，可能是bug，我在每台用过的WindowsXP上都遇到过：鼠标停留再久都不显示那个日期提示框</p>
<p>Tclock2可以：</p>
<p>1. 自定义WindowsXP右下角的那个时间显示框，格式，字体<br />
　（可惜没有背景色，虽然可以用自定义图片做皮肤，但是没那工夫）<br />
2. 一键复制时间日期到剪贴板，我现在用的是鼠标左键单击的方式复制，很爽<br />
3. 我设置了开机自动启动</p>
<p>不多说了，放个截图如下</p>
<p><img src="http://www.2maomao.com/blog/wp-content/uploads/tclock.png" alt="tclock" title="tclock" width="257" height="64" class="alignnone size-full wp-image-1347" /></p>
<p>另外，鉴于原官方站挂掉（上面的链接是unofficial的），以及方便自己下载，我把我的定制版压成一个zip包</p>
<p>下载地址：<br />
<a href="http://www.2maomao.com/blog/wp-content/uploads/tclock21.zip">http://www.2maomao.com/blog/wp-content/uploads/tclock21.zip</a></p>
<p>另外，如果你想用跟我一样的配置，又担心从这里下载的有问题，可以：<br />
1. 到<a href="http://shii.org/tclock/">这里</a>下载<br />
2. 然后在Tclock2.exe所在目录下，建立一个Tclock2.ini的文件<br />
3. Tclock2.ini的内容参见这里：<a href="http://fayaa.com/code/view/9493/">http://fayaa.com/code/view/9493/</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftclock-windows-xp-clock-customize%2F&amp;linkname=%E4%BC%97%E9%87%8C%E5%AF%BB%E5%AE%83%E5%8D%83%E7%99%BE%E5%BA%A6%20-%20Windows%20XP%E6%97%B6%E9%97%B4%E6%A0%8F%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B7%A5%E5%85%B7Tclock"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/tclock-windows-xp-clock-customize/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2010-02-07</title>
		<link>http://www.2maomao.com/blog/twitter-week-2010-02-07/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2010-02-07/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2010-02-07/</guid>
		<description><![CDATA[
Keso说的很对：“中国几乎注定不可能出现一个真正的Hulu，因为那些声称要做中国的Hulu：的，根本没有历史；中国更不可能出现一个YouTube，因为在我们这里打破控制是不被允许的。最终，中国... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>Keso说的很对：“中国几乎注定不可能出现一个真正的Hulu，因为那些声称要做中国的Hulu：的，根本没有历史；中国更不可能出现一个YouTube，因为在我们这里打破控制是不被允许的。最终，中国� <a href="http://twitter.com/realfun/statuses/8486661466" class="aktt_tweet_time">#</a></li>
<li>《象之背》，很生活很感人的短片：http://www.u148.net/article/17502.html <a href="http://twitter.com/realfun/statuses/8525656805" class="aktt_tweet_time">#</a></li>
<li>:: 玩具知识小讲-宝儿宝 品牌玩具/婴儿玩具大全/北京5元不限重/多视频-淘宝网 <a href="http://bit.ly/bFgAaz" rel="nofollow">http://bit.ly/bFgAaz</a> <a href="http://twitter.com/realfun/statuses/8534175658" class="aktt_tweet_time">#</a></li>
<li>韩寒：所谓文化大国zz: zz来自： <a href="http://htxt.it/Hj3U" rel="nofollow">http://htxt.it/Hj3U</a> 韩寒：所谓文化大国 第二次来到厦门，然后这里的空气很好，难怪大家都喜欢散步啊。嗯，刚才我听邓老.. <a href="http://bit.ly/dCWtX3" rel="nofollow">http://bit.ly/dCWtX3</a> <a href="http://twitter.com/realfun/statuses/8546697704" class="aktt_tweet_time">#</a></li>
<li>:: Sketchpad - Online Paint/Drawing application: 很不错的HTML5画图板 <a href="http://bit.ly/8F7pOM" rel="nofollow">http://bit.ly/8F7pOM</a> <a href="http://twitter.com/realfun/statuses/8615135806" class="aktt_tweet_time">#</a></li>
<li>:: 教你汽车快速停车入位 新手老手都适用: 呵呵不错 <a href="http://bit.ly/9LNfI3" rel="nofollow">http://bit.ly/9LNfI3</a> <a href="http://twitter.com/realfun/statuses/8669676157" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2010-02-07%2F&amp;linkname=Twitter%20Week%20%40%202010-02-07"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2010-02-07/feed/</wfw:commentRss>
		</item>
		<item>
		<title>韩寒：所谓文化大国zz</title>
		<link>http://www.2maomao.com/blog/twocold-so-called-big-country-of-culture-zz/</link>
		<comments>http://www.2maomao.com/blog/twocold-so-called-big-country-of-culture-zz/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 11:18:44 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[一些链接]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1340</guid>
		<description><![CDATA[zz来自： http://www.voyagewe.com/blog/post/2080.html
韩寒：所谓文化大国
第二次来到厦门，然后这里的空气很好，难怪大家都喜欢散步啊。嗯，刚才我听邓老师说了一些关于爱国主义的一些东西，那我... ]]></description>
			<content:encoded><![CDATA[<p>zz来自： <a href="http://www.voyagewe.com/blog/post/2080.html">http://www.voyagewe.com/blog/post/2080.html</a></p>
<p>韩寒：所谓文化大国</p>
<p>第二次来到厦门，然后这里的空气很好，难怪大家都喜欢散步啊。嗯，刚才我听邓老师说了一些关于爱国主义的一些东西，那我想到了两句话，我是之前看到的,那是别人说的不是我说的。第一句话是——爱国主义是流氓最后的庇护所；第二句话是——真正的爱国主义就是要保护这个国家,让这个国家不受到政府的迫害。</p>
<p>呃，然后今天我准备了一些说的内容带了一个稿纸，这是为了约束我自己。主要让大家不要受到什么迫害,怕我满嘴跑火车,开始了啊：</p>
<p>各位领导,各位老师,各位同学大家好,大家知道中国为什么成为不了文化大国吗？因为在我们大部分讲话的时候,各位领导永远都是放在第一位的,而各位领导都是没有文化的。不光是这样，他们还是惧怕文化的，是审查文化的，但是呢,他们又能够控制文化,所以说这个国家怎么够成为文化大国呢?各位领导你们说呢？</p>
<p>其实中国是有成为一个文化大国的潜力的。我给大家讲个故事。我要主编一本杂志,到现在都没有出版。然后呢，咱们宪法上有规定啊，每个公民都拥有出版的自由，但是呢我们的王法又有规定，就是领导有不让你出版的自由。</p>
<p>这个杂志呢很多地方在审查上遇到了一些问题，里面有一副漫画。漫画是一张图，主人公是个男的，他没有穿衣服。当然这是不可以了。因为相关的法律法规规定不能露出那个阴部在公开的出版物上。但这是我认可了，我觉得没有问题。所以把那个杂志特别大的一个LOGO就挡在它那个不合法的部位，然后后来这些出版社的审查人员就告诉我说 这个不可以，你把这个人的中间这个地方啊挡住了，你这是在暗喻“党中央”。</p>
<p>我的反应和大家一样啊，我被雷到了。我当时脑子里就在想,有时候把你这个惊天地泣鬼神的想象力，用在文艺创作上，而不是用在文艺审查上那该有多好。通过这个故事我想告诉大家，其实大家都是很有想象力的啊，但是很多事情我们只能想，我们不能去做,不能写,甚至很多场合不能说啊。呃&#8230;我们的限制太多了，这是一个限制级的国家。在限制级的国家里怎么可能产生非常丰富的文化呢？我已经算是一个自我限制很少的一个同志了，但是在我落笔的时候呢，我就会情不自禁的想，警察不能写，领导不能写，政策不能写，制度不能写,司法不能写，很多历史不能写，西藏不能写，新疆不能写，集会不能写，游行不能写，黄色不能写，焚烧不能写，低俗不能写，艺术不能写，高雅我又写不出。抱歉啊，我真的写不出甚么高雅的东西，我又不是余秋雨。</p>
<p>在网路上发表的一些文章啊,尺度已经算是比较大的。有很多写剧本的朋友,我一些写剧本的朋友,包括宁财神啊写一些话剧,还有电影剧本编剧,他们非常的痛苦。在这样的一个文化环境下,我就开始想，如何成为一个文化大国？除非全世界就剩下中国,朝鲜还有阿富汗。朝鲜是文化禁地，大家都知道。然后阿富汗是因为国内的局势正在搞不清楚，他们还顾不上文化。但纵然这样,他们都有作家写出了《追风筝的人》。当然比较遗憾的是这不是阿富汗出版的。我想,一旦阿富汗搞清楚了，也不是没有可能去超过中国。</p>
<p>呃&#8230;我们所谓的在国际交流上不能再拿那些四大名著和孔孟之道来说事，这样就像相亲的时候女方问你有没有钱，你说你祖宗十八辈上有钱，这是没用的。这个就悲剧的造成，这个和大家没有任何的关系,虽然说,通往朝鲜的道路，是由每一个沉默的人铺就的。但是,某一方面我们当然要比朝鲜强很多啊，因为大家也都知道朝鲜是什么样子的。另外一方面呢,我相信在座的大家,其实很多人,大家并不沉默啊,大家只是被和谐了。</p>
<p>呃&#8230; 在中国的这个扫黄史上,可能很多同学，我想大家应该都知道，毕竟是大学生，大家都知道虽然现在的一些教材上并没有具体内容，就是邓丽君和刘文正都是黄色的，下流淫秽，但是呢因为听的人多了他们就变成了黄色和下流，他们就不淫秽了，但是呢到最后全国人民都在听，所以他们既不黄色也不下流了。</p>
<p>如果我们都能够来反对文化的审查，让我们的屏蔽词里除了那些反人类的词汇不再有其他词汇，那我们才有可能去创造出一个文化大国，哪怕是在这个过程当中你我的名字都会进入这个屏蔽词库，但我相信一个屏蔽词库是有它的最大载重量的，每一个新增加的词汇都是在加速它的灭亡。</p>
<p>我希望我们的新闻媒体的从业者，我们的学生老师，每一个文化的从业者爱好者，包括我们的管理者，可以努力让我们的屏蔽和审查越来越少。我们的领导们，因为这个领导是和大家分开的啊，所以我们的领导我们的政府可以有足够的自信让文化更加的开放。我知道我们的领导很喜欢向国外输出我们的文化，觉得这是一个强国的象征，但是以现有的文化我觉得实在是输不出去的。我们在创造文化作品的时候，每一个作者每一个从业人员，他们在时刻进行着自我的审查，在这样一个创作环境下，我觉得怎么能产生像样的文化作品呢？在全世界范围内，你把文艺作品阉割得像新闻联播一样给外国人看，然后企图输出中国的文化，你当外国人是外星人啊。</p>
<p>中国是不是在经济上真正的崛起了，这个呢要等我们的房地产业崩盘了以后再看，现在一切都不好说，但是如果一个国家在文化上真正的崛起了，那它真的是一个强国，而且我想应该永远不会有崩盘的危险。</p>
<p>最后说回到我们的屏蔽词库，一个屏蔽词库里的词越势多，我们这个国家的文化就会越势弱。当然我们的政府会给大家很多的解释，他们会告诉你，我们这么做是为了保护青少年，是为了社会的稳定，文化是自由的。所以他们有权屏蔽任何危害青少年，破坏社会稳定的资讯和文化。但是如果你认同了,迟早有一天你会发现，你在控诉你的遭遇的时候，他们会将你屏蔽，罪名是破坏社会稳定。到了最后，凡是不利于统治阶层的，不利于他们获得利益的言论，都是破坏社会的稳定，都是危害青少年。如果我们当时容忍了绿霸花季护航的话，那么我们就会看到绿霸花甲护航，到那个时候就不光光是文化的东西了,所以同学们,我们不能让这一天的到来。否则，在以后，在若干年以后，在你的孙子们，通过卫星接收到的电子课本的历史书上,我们都会是笑料。</p>
<p>所以…谢谢大家。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwocold-so-called-big-country-of-culture-zz%2F&amp;linkname=%E9%9F%A9%E5%AF%92%EF%BC%9A%E6%89%80%E8%B0%93%E6%96%87%E5%8C%96%E5%A4%A7%E5%9B%BDzz"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twocold-so-called-big-country-of-culture-zz/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2010-01-31</title>
		<link>http://www.2maomao.com/blog/twitter-week-2010-01-31/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2010-01-31/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2010-01-31/</guid>
		<description><![CDATA[
:: Project SIKULI: 有意思的东东，自动化做一些小事情，有时比Autohotkey方便 http://bit.ly/80XGS3 #
:: 自绘Dialog窗体(非Hook Api的方式) http://bit.ly/bvaFw2 #
搞笑的图片: http://bit.ly/bcZCcz #
:: ★为狮子添加人工... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>:: Project SIKULI: 有意思的东东，自动化做一些小事情，有时比Autohotkey方便 <a href="http://bit.ly/80XGS3" rel="nofollow">http://bit.ly/80XGS3</a> <a href="http://twitter.com/realfun/statuses/8216118832" class="aktt_tweet_time">#</a></li>
<li>:: 自绘Dialog窗体(非Hook Api的方式) <a href="http://bit.ly/bvaFw2" rel="nofollow">http://bit.ly/bvaFw2</a> <a href="http://twitter.com/realfun/statuses/8257950638" class="aktt_tweet_time">#</a></li>
<li>搞笑的图片: <a href="http://bit.ly/bcZCcz" rel="nofollow">http://bit.ly/bcZCcz</a> <a href="http://twitter.com/realfun/statuses/8271131528" class="aktt_tweet_time">#</a></li>
<li>:: ★为狮子添加人工智能神经系统(TPMS作业)★_标致307 <a href="http://bit.ly/chHR0J" rel="nofollow">http://bit.ly/chHR0J</a> <a href="http://twitter.com/realfun/statuses/8313183358" class="aktt_tweet_time">#</a></li>
<li>楼下一坨警察,封锁了所有电梯,让我们都从货梯上,也不知道是哪坨人物来了。妈的,那谁谁谁,别当自己是个人物了,每天不干别的专门堵电梯怎么地? <a href="http://twitter.com/realfun/statuses/8347925531" class="aktt_tweet_time">#</a></li>
<li>好几个同事停在路边的车都被拖走或者主动换地方了,北京大人物真多,每隔几天就有人出来霍霍 <a href="http://twitter.com/realfun/statuses/8348022032" class="aktt_tweet_time">#</a></li>
<li>申通慢递,有的选就不选,两天了,才从扬州转到泰州,正在转到南京的途中。。。 <a href="http://twitter.com/realfun/statuses/8349102314" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2010-01-31%2F&amp;linkname=Twitter%20Week%20%40%202010-01-31"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2010-01-31/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2010-01-24</title>
		<link>http://www.2maomao.com/blog/twitter-week-2010-01-24/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2010-01-24/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2010-01-24/</guid>
		<description><![CDATA[
妈的,随意开枪打人都不让报道,也太黑涩会了 #
韩寒:政府就是这样,他永远给你一个动词和名词,然后永远不解释这个名词,比如说,不能反革命,但从来不告诉你什么是反革命,不能犯流氓罪,但从来... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>妈的,随意开枪打人都不让报道,也太黑涩会了 <a href="http://twitter.com/realfun/statuses/7971336903" class="aktt_tweet_time">#</a></li>
<li>韩寒:政府就是这样,他永远给你一个动词和名词,然后永远不解释这个名词,比如说,不能反革命,但从来不告诉你什么是反革命,不能犯流氓罪,但从来不告诉你什么是流氓罪,这次是不能发黄段子,但� <a href="http://twitter.com/realfun/statuses/7971416660" class="aktt_tweet_time">#</a></li>
<li>甲醛导致呼吸道不爽,准备再租个房子住到夏天 <a href="http://twitter.com/realfun/statuses/7971441928" class="aktt_tweet_time">#</a></li>
<li>淘宝在线交流强制下载淘宝旺旺，是淘宝最近做出的最愚蠢的举动，把买家推向其他平台 <a href="http://twitter.com/realfun/statuses/7980565685" class="aktt_tweet_time">#</a></li>
<li>:: Debugging Tools for Windows - Overview <a href="http://bit.ly/4p4zN7" rel="nofollow">http://bit.ly/4p4zN7</a> <a href="http://twitter.com/realfun/statuses/8017982918" class="aktt_tweet_time">#</a></li>
<li>华西村啊，我去看过，感觉大多数村民都是被绑架的。。。 <a href="http://twitter.com/realfun/statuses/8049448581" class="aktt_tweet_time">#</a></li>
<li>对于贵州警察枪杀村民案，张艺谋表示：说是三枪拍案惊奇，误差两枪也在容许范围内。 <a href="http://twitter.com/realfun/statuses/8050713976" class="aktt_tweet_time">#</a></li>
<li><a href="http://comment.news.163.com/news_guonei4_bbs/5TL52E4K0001124J.html" rel="nofollow">http://comment.news.163.com/news_guonei4_bbs/5TL52E4K0001124J.html</a> 五毛党已经歇斯底里了 <a href="http://twitter.com/realfun/statuses/8096157351" class="aktt_tweet_time">#</a></li>
<li>广东一名男童接种甲流疫苗引发脑脊髓炎，专家认为，接种甲流疫苗是防控甲流的有效措施，接种甲流疫苗是安全可靠有效，可放心接种。CNMB <a href="http://twitter.com/realfun/statuses/8096639514" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2010-01-24%2F&amp;linkname=Twitter%20Week%20%40%202010-01-24"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2010-01-24/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2010-01-10</title>
		<link>http://www.2maomao.com/blog/twitter-week-2010-01-10/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2010-01-10/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2010-01-10/</guid>
		<description><![CDATA[
哈维尔：
1、对话的目的是寻求真理，不是为了斗争。
2、不做人身攻击。
3、保持主题。
4、辩论时要用证据。
5、不要坚持错误不改。
6、要分清对话与只准自己讲话的区别。
7、对话要有� #... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>哈维尔：<br />
1、对话的目的是寻求真理，不是为了斗争。<br />
2、不做人身攻击。<br />
3、保持主题。<br />
4、辩论时要用证据。<br />
5、不要坚持错误不改。<br />
6、要分清对话与只准自己讲话的区别。<br />
7、对话要有� <a href="http://twitter.com/realfun/statuses/7358899299" class="aktt_tweet_time">#</a></li>
<li>刚才4s店电话回访,问我是基本满意还是非常满意?我说不满意,她说哦,那就是基本满意,奶奶个腿,装模作样 <a href="http://twitter.com/realfun/statuses/7433628195" class="aktt_tweet_time">#</a></li>
<li>医疗报销实在是太繁琐了,存了心思黑你的钱 <a href="http://twitter.com/realfun/statuses/7433632659" class="aktt_tweet_time">#</a></li>
<li>:: 2009年度北京市基本医疗保险A类定点医疗机构名单 <a href="http://bit.ly/8wq92P" rel="nofollow">http://bit.ly/8wq92P</a> <a href="http://twitter.com/realfun/statuses/7434287440" class="aktt_tweet_time">#</a></li>
<li>:: Defend Your Code: Top Ten Security Tips Every Developer Must Know <a href="http://bit.ly/7CppN4" rel="nofollow">http://bit.ly/7CppN4</a> <a href="http://twitter.com/realfun/statuses/7516101281" class="aktt_tweet_time">#</a></li>
<li>被Google的语言设置烦的不行，发现很多人抱怨这个问题：http://www.google.com/support/forum/p/Web+Search/thread?tid=3818ae383c3ccfed ，现在每次都得加上“&#38;hl=en”才行 <a href="http://twitter.com/realfun/statuses/7521924097" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2010-01-10%2F&amp;linkname=Twitter%20Week%20%40%202010-01-10"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2010-01-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2009-12-27</title>
		<link>http://www.2maomao.com/blog/twitter-week-2009-12-27/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2009-12-27/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2009-12-27/</guid>
		<description><![CDATA[
Twitter Week @ 2009-12-20: Twitter Week @ 2009-12-13: Twitter Week @ 2009-12-06: 以前浪费在兴趣上的时间大多值回票价了,不错的感觉 # Ye.. http://bit.ly/6TjdoQ #
就跟化学反应一样,越激烈越快完成 #
对于互联网的封... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>Twitter Week @ 2009-12-20: Twitter Week @ 2009-12-13: Twitter Week @ 2009-12-06: 以前浪费在兴趣上的时间大多值回票价了,不错的感觉 # Ye.. <a href="http://bit.ly/6TjdoQ" rel="nofollow">http://bit.ly/6TjdoQ</a> <a href="http://twitter.com/realfun/statuses/6866317644" class="aktt_tweet_time">#</a></li>
<li>就跟化学反应一样,越激烈越快完成 <a href="http://twitter.com/realfun/statuses/6885162291" class="aktt_tweet_time">#</a></li>
<li>对于互联网的封锁只会让对抗活动转往线下,从而加快中国的民主进程 <a href="http://twitter.com/realfun/statuses/6885183982" class="aktt_tweet_time">#</a></li>
<li>:: 律师不是政客，无需顾大局_财经_凤凰网 <a href="http://bit.ly/4o6YFm" rel="nofollow">http://bit.ly/4o6YFm</a> <a href="http://twitter.com/realfun/statuses/6886423571" class="aktt_tweet_time">#</a></li>
<li>2008年之前,在淘宝上花了五百多,2008年一年花了4484.3元,2009年直到现在,花了4809.2元 <a href="http://twitter.com/realfun/statuses/6951513314" class="aktt_tweet_time">#</a></li>
<li>nnd,淘宝金币兑换太无耻了,700多金币就可以兑换两种:1. 兑换一个打折机会,结果打折商品实际上别的店就卖这个价。 2.  兑换一个10元的红包机会,要在指定店购买50元以上的商品,然后会充值到淘宝 <a href="http://twitter.com/realfun/statuses/6983854028" class="aktt_tweet_time">#</a></li>
<li>圣诞节快乐！&#8212;日人民报 <a href="http://twitter.com/realfun/statuses/7029908376" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2009-12-27%2F&amp;linkname=Twitter%20Week%20%40%202009-12-27"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2009-12-27/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2009-12-20</title>
		<link>http://www.2maomao.com/blog/twitter-week-2009-12-20/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2009-12-20/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2009-12-20/</guid>
		<description><![CDATA[
:: Wave Editor » Free Sound Editor http://bit.ly/6onWSt #
人肉spammer真多 #
这是谁写的？ “夺泥燕口，削铁针头，刮金佛面细搜求，何处觅有。蚊子腹内剜脂油，鹭鸶脚上劈精肉&#8212;亏老先生下手！” #
... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>:: Wave Editor » Free Sound Editor <a href="http://bit.ly/6onWSt" rel="nofollow">http://bit.ly/6onWSt</a> <a href="http://twitter.com/realfun/statuses/6646034711" class="aktt_tweet_time">#</a></li>
<li>人肉spammer真多 <a href="http://twitter.com/realfun/statuses/6688240651" class="aktt_tweet_time">#</a></li>
<li>这是谁写的？ “夺泥燕口，削铁针头，刮金佛面细搜求，何处觅有。蚊子腹内剜脂油，鹭鸶脚上劈精肉&#8212;亏老先生下手！” <a href="http://twitter.com/realfun/statuses/6695558918" class="aktt_tweet_time">#</a></li>
<li>乐乐看图识物: 这次回家，乐乐宝宝显得很乖巧，腻在我身边转悠，哈哈，真是高兴啊，每次送点小礼物原来真的很管用 乐乐现在会唱几个简单儿歌的片段，偶尔自己高兴的时候，就哼哼几句， <a href="http://twitter.com/realfun/statuses/6719400208" class="aktt_tweet_time">#</a></li>
<li>:: 国外早已禁止或限制汽车贴膜: 如今的汽车玻璃隔热和防爆的水平早已今非昔比，贴膜带来的效果微乎其微，而且明显的负面效果就摆在那里，无论多么高级的太阳膜，贴上以后都会造成车内� <a href="http://twitter.com/realfun/statuses/6786161949" class="aktt_tweet_time">#</a></li>
<li>中国现行的经济、政治、文化、道德、环境，都在崩溃的边缘挣扎 <a href="http://twitter.com/realfun/statuses/6805582949" class="aktt_tweet_time">#</a></li>
<li>“重庆司法局长要求律师在打黑中顾大局” : <a href="http://news.163.com/09/1219/05/5QSDVPD4000120GU.html" rel="nofollow">http://news.163.com/09/1219/05/5QSDVPD4000120GU.html</a> 日啊，猛一看还以为是个段子呢，中国的“法制”真他妈的有戏剧性 <a href="http://twitter.com/realfun/statuses/6834409800" class="aktt_tweet_time">#</a></li>
<li>最近zf的一些疯狂举动，告诉我们宪法就是用来让执政者践踏的。。。有种黎明前的黑暗的错觉 <a href="http://twitter.com/realfun/statuses/6852123428" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2009-12-20%2F&amp;linkname=Twitter%20Week%20%40%202009-12-20"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2009-12-20/feed/</wfw:commentRss>
		</item>
		<item>
		<title>乐乐看图识物</title>
		<link>http://www.2maomao.com/blog/drawings-for-lele/</link>
		<comments>http://www.2maomao.com/blog/drawings-for-lele/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 00:53:02 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[宝宝我爱你]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1313</guid>
		<description><![CDATA[这次回家，乐乐宝宝显得很乖巧，腻在我身边转悠，哈哈，真是高兴啊，每次送点小礼物原来真的很管用
乐乐现在会唱几个简单儿歌的片段，偶尔自己高兴的时候，就哼哼几句，她妈妈很开心... ]]></description>
			<content:encoded><![CDATA[<p>这次回家，乐乐宝宝显得很乖巧，腻在我身边转悠，哈哈，真是高兴啊，每次送点小礼物原来真的很管用</p>
<p>乐乐现在会唱几个简单儿歌的片段，偶尔自己高兴的时候，就哼哼几句，她妈妈很开心，觉得音乐天赋不错，我这回回去就着重培养了一下，小家伙果然又记住了几个</p>
<p>闲来无事，拿着她的儿童画板画了几个简单的家庭用品，有些是简单的线条构成的，想看看宝宝能不能从线条抽象出实物来，结果大部分都行，有些立体的复杂一些的就不容易看出来了。</p>
<p>选登几个如下：</p>
<p>喜羊羊，这个画的不像，但是乐乐对喜羊羊很熟悉：<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/draw_for_lele_xiyangyang.jpg" /></p>
<p>斑马<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/draw_for_lele_banma.jpg" /></p>
<p>杯子<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/draw_for_lele_beizi.jpg" /></p>
<p>碗和筷子，画得不是很像，乐乐说是“吃饭饭的”<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/draw_for_lele_chifanfande.jpg" /></p>
<p>乐乐的小尿桶<br />
<img src="http://www.2maomao.com/blog/wp-content/uploads/draw_for_lele_niaotong.jpg" /></p>
<p>哦，对了，乐乐说话现在奶声奶气的，我给录了一个来电铃声，效果不错。</p>
<p>来电铃声-乐乐版: (28k，音“爸爸来电话啦”)<br />
<embed src="http://www.2maomao.com/blog/wp-content/uploads/laidian_edit1.wav" width=400 height=45 type=audio/mpeg loop=”true” autostart=”false”></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fdrawings-for-lele%2F&amp;linkname=%E4%B9%90%E4%B9%90%E7%9C%8B%E5%9B%BE%E8%AF%86%E7%89%A9"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/drawings-for-lele/feed/</wfw:commentRss>
<enclosure url="http://www.2maomao.com/blog/wp-content/uploads/laidian_edit1.wav" length="28346" type="audio/x-wav" />
		</item>
		<item>
		<title>Twitter Week @ 2009-12-06</title>
		<link>http://www.2maomao.com/blog/twitter-week-2009-12-06/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2009-12-06/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2009-12-06/</guid>
		<description><![CDATA[
以前浪费在兴趣上的时间大多值回票价了,不错的感觉 #
Yet Another Hierarchical Officious Oracle #
Twitter Week @ 2009-11-29: 关于25马问题的思考: 题酷发芽网上的一个题目 “25匹赛马血拼Top5”： 有25匹马，... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>以前浪费在兴趣上的时间大多值回票价了,不错的感觉 <a href="http://twitter.com/realfun/statuses/6186723841" class="aktt_tweet_time">#</a></li>
<li>Yet Another Hierarchical Officious Oracle <a href="http://twitter.com/realfun/statuses/6186725731" class="aktt_tweet_time">#</a></li>
<li>Twitter Week @ 2009-11-29: 关于25马问题的思考: 题酷发芽网上的一个题目 “25匹赛马血拼Top5”： 有25匹马，共5个跑道，不用任何工具，请问 用几场比赛可分出前3名？ 几场比赛可以分出前.. <a href="http://bit.l" rel="nofollow">http://bit.l</a> <a href="http://twitter.com/realfun/statuses/6189448313" class="aktt_tweet_time">#</a></li>
<li>小娟版的《绿岛小夜曲》听起来很爽,那个男歌手沙哑的嗓子听起来跟我差不多,嘿嘿 <a href="http://twitter.com/realfun/statuses/6195075471" class="aktt_tweet_time">#</a></li>
<li>CoDec = Code &#38; Decode? <a href="http://twitter.com/realfun/statuses/6195076236" class="aktt_tweet_time">#</a></li>
<li>:: GraphicsMagick Image Processing System <a href="http://bit.ly/YT7DW" rel="nofollow">http://bit.ly/YT7DW</a> <a href="http://twitter.com/realfun/statuses/6233002124" class="aktt_tweet_time">#</a></li>
<li>所有为GFW做出卓越贡献的人,我衷心的问候你们全家,并发誓当GFW倒掉的时候,踊跃的参加对你们的审判! <a href="http://twitter.com/realfun/statuses/6260949418" class="aktt_tweet_time">#</a></li>
<li>:: The Expat XML Parser <a href="http://bit.ly/4CkMMz" rel="nofollow">http://bit.ly/4CkMMz</a> <a href="http://twitter.com/realfun/statuses/6295660538" class="aktt_tweet_time">#</a></li>
<li>:: CMake - Cross Platform Make <a href="http://www.cmake.org/" rel="nofollow">http://www.cmake.org/</a> <a href="http://twitter.com/realfun/statuses/6296743394" class="aktt_tweet_time">#</a></li>
<li>:: GIPS: Global IP Solutions: The world&#8217;s most widely deployed technology for processing real-time voice .. <a href="http://www.gipscorp.com/" rel="nofollow">http://www.gipscorp.com/</a> <a href="http://twitter.com/realfun/statuses/6330227569" class="aktt_tweet_time">#</a></li>
<li>最近写的几个Python脚本: 最近太忙，忙的过程中写了七八个小脚本，其中一些比较通用的，贴在了代码发芽网上： Python语言: 简单的几句Python语句，模拟《骇客帝国》中的滚屏 #<a href="http://search.twitter.com/search?q=%23coding" class="aktt_hashtag">coding</a>:utf-8 #.. http:/ <a href="http://twitter.com/realfun/statuses/6342494096" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2009-12-06%2F&amp;linkname=Twitter%20Week%20%40%202009-12-06"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2009-12-06/feed/</wfw:commentRss>
		</item>
		<item>
		<title>最近写的几个Python脚本</title>
		<link>http://www.2maomao.com/blog/several-python-scripts-wrote-recently/</link>
		<comments>http://www.2maomao.com/blog/several-python-scripts-wrote-recently/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 12:56:12 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1304</guid>
		<description><![CDATA[最近太忙，忙的过程中写了七八个小脚本，其中一些比较通用的，贴在了代码发芽网上：
模拟《骇客帝国》中的滚屏效果，只需要几行简单的Python语句哦，以下是效果图：

Python语言: 简单的几... ]]></description>
			<content:encoded><![CDATA[<p>最近太忙，忙的过程中写了七八个小脚本，其中一些比较通用的，贴在了<a href="http://fayaa.com/code/">代码发芽网</a>上：</p>
<p><strong>模拟《骇客帝国》中的滚屏效果，只需要几行简单的Python语句哦，以下是效果图：</strong></p>
<p><img src="http://www.2maomao.com/blog/wp-content/uploads/matrix.jpg" alt="matrix" title="matrix" width="400" height="300" class="alignnone size-full wp-image-1315" /></p>
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/8218/">简单的几句Python语句，模拟《骇客帝国》中的滚屏</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#coding:utf-8</span></p>
<p> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#简单的几句Python语句，模拟滚动的Matrix屏保</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); "># 1. 打开Windows命令行(运行-》输入“cmd”然后回车）</span><br /> <span style="color: rgb(136, 136, 136); "># 2. 打开命令行属性设置，设置背景为黑色，前景为绿色</span><br /> <span style="color: rgb(136, 136, 136); "># 3. 执行这个脚本，就可以看到类似电影《骇客帝国》中的经典滚屏了 - 不过是反着的。。。</span><br /> <span style="color: rgb(136, 136, 136); ">#</span><br /> <span style="color: rgb(136, 136, 136); ">#呵呵，无聊之作。。。Alt+Enter全屏观看效果更好</span></p>
<p> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">random</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">string</span><br /> <span style="color: rgb(0, 0, 0); ">a</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot; &quot;</span> <span style="color: rgb(0, 0, 0); ">*</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">100</span> <span style="color: rgb(0, 0, 0); ">+</span> <span style="color: rgb(0, 0, 0); ">string</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">printable</span><br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">while</span> <span style="color: rgb(0, 51, 136); ">True</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(0, 0, 0); ">a</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">random</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">randint</span>(<span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">a</span>)<span style="color: rgb(0, 0, 0); ">-</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">)],</span></div>
<hr />
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/8160/">命令行小工具:输出系统Path中的符合条件的文件全路径，Python脚本</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#What&nbsp; : a small tool to locate files in system &quot;PATH&quot; variable</span></p>
<p> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">sys</span></p>
<p> <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span>) <span style="color: rgb(0, 0, 0); ">&lt;</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">2</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&nbsp; Usage:&quot;</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&nbsp;&nbsp;&nbsp; where.py test&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; normal&nbsp; search&quot;</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&nbsp;&nbsp;&nbsp; where.py te*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; blurred search&quot;</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;&nbsp;&nbsp;&nbsp; where.py -x te*.cmd&nbsp;&nbsp; #&nbsp; regular expression search&quot;</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">exit</span>()<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">elif</span> <span style="color: rgb(0, 51, 136); ">len</span>(<span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span>) <span style="color: rgb(0, 0, 0); ">==</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">2</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">pattern</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">1</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">replace</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;.&quot;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">.&quot;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">replace</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;*&quot;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">*&quot;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">replace</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;?&quot;</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;.?&quot;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">lower</span>()<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">else</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">pattern</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">sys</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">argv</span><span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 221); font-weight: bold; ">2</span><span style="color: rgb(0, 0, 0); ">]</span><span style="color: rgb(136, 136, 136); ">#tricky, no &quot;-x&quot; checking here</span></p>
<p> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">os</span><br /> <span style="color: rgb(0, 0, 0); ">paths</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[</span>p <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> p <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">getenv</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;PATH&#39;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">split</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;;&quot;</span>) <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> p<span style="color: rgb(0, 0, 0); ">]</span><br /> <span style="color: rgb(0, 0, 0); ">exts</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">ext</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">lower</span>() <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">ext</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">getenv</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&#39;PATHEXT&#39;</span>)<span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">split</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;;&quot;</span>) <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">ext</span><span style="color: rgb(0, 0, 0); ">]</span><br /> <span style="color: rgb(0, 0, 0); ">paths</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">append</span>(<span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;.</span><span style="color: rgb(0, 68, 221); background-color: rgb(255, 240, 240); ">\\</span><span style="color: rgb(221, 34, 0); background-color: rgb(255, 240, 240); ">&quot;</span>)<br /> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">re</span><br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> p <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">paths</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 136, 0); ">not</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">path</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">isdir</span>(p<span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">continue</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">f</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">listdir</span>(p<span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">re</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">search</span>(<span style="color: rgb(0, 0, 0); ">pattern</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">lower</span><span style="color: rgb(0, 0, 0); ">()):</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">is_exe</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">False</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">ext</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">exts</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">f</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">endswith</span>(<span style="color: rgb(0, 0, 0); ">ext</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">is_exe</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">True</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">break</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">is_exe</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(0, 0, 0); ">os</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">path</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">join</span>(p<span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 0); ">f</span>)</div>
<hr />
<div style="background:#fdfdfd;color:black;"><u>Python语言</u>: <a href="http://fayaa.com/code/view/8215/">Python脚本获取Windows窗口标题，输出到命令行</a></div>
<div class="source" style="font-family: Consolas, 'Lucida Console', 'Courier New'; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); "> <span style="color: rgb(136, 136, 136); ">#! /usr/bin/env python</span><br /> <span style="color: rgb(136, 136, 136); "># -*- coding: utf-8 -*-</span></p>
<p> <span style="color: rgb(0, 0, 0); ">from</span> <span style="color: rgb(187, 0, 102); font-weight: bold; ">win32gui</span> <span style="color: rgb(0, 0, 0); ">import</span> <span style="color: rgb(0, 0, 0); ">*</span><br /> <span style="color: rgb(0, 0, 0); ">titles</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 51, 136); ">set</span>()<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">def</span> <span style="color: rgb(0, 102, 187); font-weight: bold; ">foo</span>(<span style="color: rgb(0, 0, 0); ">hwnd</span><span style="color: rgb(0, 0, 0); ">,</span><span style="color: rgb(0, 0, 0); ">nouse</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp; <span style="color: rgb(136, 136, 136); ">#去掉下面这句就所有都输出了，但是我不需要那么多</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">IsWindow</span>(<span style="color: rgb(0, 0, 0); ">hwnd</span>) <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(0, 0, 0); ">IsWindowEnabled</span>(<span style="color: rgb(0, 0, 0); ">hwnd</span>) <span style="color: rgb(0, 136, 0); ">and</span> <span style="color: rgb(0, 0, 0); ">IsWindowVisible</span>(<span style="color: rgb(0, 0, 0); ">hwnd</span><span style="color: rgb(0, 0, 0); ">):</span><br /> &nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 0); ">titles</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">add</span>(<span style="color: rgb(0, 0, 0); ">GetWindowText</span>(<span style="color: rgb(0, 0, 0); ">hwnd</span>))</p>
<p> <span style="color: rgb(0, 0, 0); ">EnumWindows</span>(<span style="color: rgb(0, 0, 0); ">foo</span><span style="color: rgb(0, 0, 0); ">,</span> <span style="color: rgb(0, 0, 221); font-weight: bold; ">0</span>)<br /> <span style="color: rgb(0, 0, 0); ">lt</span> <span style="color: rgb(0, 0, 0); ">=</span> <span style="color: rgb(0, 0, 0); ">[</span><span style="color: rgb(0, 0, 0); ">t</span> <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">t</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">titles</span> <span style="color: rgb(0, 136, 0); font-weight: bold; ">if</span> <span style="color: rgb(0, 0, 0); ">t</span><span style="color: rgb(0, 0, 0); ">]</span><br /> <span style="color: rgb(0, 0, 0); ">lt</span><span style="color: rgb(0, 0, 0); ">.</span><span style="color: rgb(0, 0, 0); ">sort</span>()<br /> <span style="color: rgb(0, 136, 0); font-weight: bold; ">for</span> <span style="color: rgb(0, 0, 0); ">t</span> <span style="color: rgb(0, 136, 0); ">in</span> <span style="color: rgb(0, 0, 0); ">lt</span><span style="color: rgb(0, 0, 0); ">:</span><br /> &nbsp; <span style="color: rgb(0, 136, 0); font-weight: bold; ">print</span> <span style="color: rgb(0, 0, 0); ">t</span></div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fseveral-python-scripts-wrote-recently%2F&amp;linkname=%E6%9C%80%E8%BF%91%E5%86%99%E7%9A%84%E5%87%A0%E4%B8%AAPython%E8%84%9A%E6%9C%AC"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/several-python-scripts-wrote-recently/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Twitter Week @ 2009-11-29</title>
		<link>http://www.2maomao.com/blog/twitter-week-2009-11-29/</link>
		<comments>http://www.2maomao.com/blog/twitter-week-2009-11-29/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 00:32:00 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[胡言乱语]]></category>

		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/twitter-week-2009-11-29/</guid>
		<description><![CDATA[
关于25马问题的思考: 题酷发芽网上的一个题目 “25匹赛马血拼Top5”： 有25匹马，共5个跑道，不用任何工具，请问 用几场比赛可分出前3名？ 几场比赛可以分出前5名？ 几场比赛可以给所有赛... ]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
<li>关于25马问题的思考: 题酷发芽网上的一个题目 “25匹赛马血拼Top5”： 有25匹马，共5个跑道，不用任何工具，请问 用几场比赛可分出前3名？ 几场比赛可以分出前5名？ 几场比赛可以给所有赛马� <a href="http://twitter.com/realfun/statuses/5949103800" class="aktt_tweet_time">#</a></li>
<li>:: TWiki - the Open Source Enterprise Wiki and Web 2.0 Application Platform <a href="http://twiki.org/" rel="nofollow">http://twiki.org/</a> <a href="http://twitter.com/realfun/statuses/5971577611" class="aktt_tweet_time">#</a></li>
<li>:: Hard Drive Data Recovery Software. Disk Recovery &#38; Data Recovery Tools to Recover Deleted Files - EASEUS Data.. <a href="http://www.easeus.com/" rel="nofollow">http://www.easeus.com/</a> <a href="http://twitter.com/realfun/statuses/5973033377" class="aktt_tweet_time">#</a></li>
<li>HP笔记本键盘排列太极品了&#8230; <a href="http://twitter.com/realfun/statuses/6001687233" class="aktt_tweet_time">#</a></li>
<li>:: Windows Search 4.0: 微软的本地搜索4.0版本还不错，XP下需要先安装这个：http://htxt.it/2xdr <a href="http://bit.ly/6U45P7" rel="nofollow">http://bit.ly/6U45P7</a> <a href="http://twitter.com/realfun/statuses/6003464513" class="aktt_tweet_time">#</a></li>
<li>:: 曹安路轻纺市场购买&#8212;&#8211;窗帘攻克记录 家具软装 篱笆网 － 篱笆论坛 <a href="http://bit.ly/8u6roF" rel="nofollow">http://bit.ly/8u6roF</a> <a href="http://twitter.com/realfun/statuses/6037073219" class="aktt_tweet_time">#</a></li>
<li>小明明买了Kindle DX,啥时候借过来蹂躏一番? <a href="http://twitter.com/realfun/statuses/6038699922" class="aktt_tweet_time">#</a></li>
<li>:: www 2009 Madrid <a href="http://bit.ly/5GfzZc" rel="nofollow">http://bit.ly/5GfzZc</a> <a href="http://twitter.com/realfun/statuses/6039985714" class="aktt_tweet_time">#</a></li>
<li>:: Remove ads from Live Messenger without patches: MSN广告有时候是挺烦人的，让人看着就想拿板砖拍该feature的PM那丫挺的 <a href="http://bit.ly/5nbmsb" rel="nofollow">http://bit.ly/5nbmsb</a> <a href="http://twitter.com/realfun/statuses/6043468944" class="aktt_tweet_time">#</a></li>
<li>:: YUI Graded Browser Support <a href="http://bit.ly/23DSMj" rel="nofollow">http://bit.ly/23DSMj</a> <a href="http://twitter.com/realfun/statuses/6048869536" class="aktt_tweet_time">#</a></li>
<li>:: How to remove duplicate words from a plain text file using linux command - Stack Overflow: uniq工具不错 <a href="http://bit.ly/5RYUfu" rel="nofollow">http://bit.ly/5RYUfu</a> <a href="http://twitter.com/realfun/statuses/6072863834" class="aktt_tweet_time">#</a></li>
<li>:: Windows 7 Shortcuts Enables the Best Win7 Shortcuts in XP or Vista: 在XP/Vista下模拟Windows7窗口快捷键(Win Left/Ri.. <a href="http://bit.ly/8esixP" rel="nofollow">http://bit.ly/8esixP</a> <a href="http://twitter.com/realfun/statuses/6073976084" class="aktt_tweet_time">#</a></li>
<li>:: OldVersion.com: 有许多软件的旧版本下载 - 因为升级版不总是比旧版好 <a href="http://www.oldversion.com/" rel="nofollow">http://www.oldversion.com/</a> <a href="http://twitter.com/realfun/statuses/6077767172" class="aktt_tweet_time">#</a></li>
<li>:: Haskell in 5 steps - HaskellWiki <a href="http://bit.ly/4UPAmT" rel="nofollow">http://bit.ly/4UPAmT</a> <a href="http://twitter.com/realfun/statuses/6098091205" class="aktt_tweet_time">#</a></li>
<li>:: Why won&#8217;t checkboxes show up for me? - Google Chrome Help: 不知道为啥，Google这个臭名昭著的Checkbox隐形的bug，存在了这么久，而且到处都.. <a href="http://bit.ly/6OSnJX" rel="nofollow">http://bit.ly/6OSnJX</a> <a href="http://twitter.com/realfun/statuses/6106564015" class="aktt_tweet_time">#</a></li>
<li>我的推测是：房价继续涨下去，因为根本停不下来，这原来很好用的刀子，现在已经失控了。但长远来看，或许不是坏事，中国的民主如果一定会进步，那么一定是房地产导致了广泛的群众基础 <a href="http://twitter.com/realfun/statuses/6144223551" class="aktt_tweet_time">#</a></li>
<li>接上一条 - 房地产，是目前最有可能的那“最后一根稻草”。 <a href="http://twitter.com/realfun/statuses/6144251593" class="aktt_tweet_time">#</a></li>
<li>吃人的社会主义优越性！三鹿破产 结石患儿获赔无望： <a href="http://news.163.com/09/1129/04/5P8RKC2M0001124J.html" rel="nofollow">http://news.163.com/09/1129/04/5P8RKC2M0001124J.html</a> <a href="http://twitter.com/realfun/statuses/6160297047" class="aktt_tweet_time">#</a></li>
<li>五毛真多： <a href="http://comment.news.163.com/news_guonei4_bbs/5P15EUDA0001124J.html" rel="nofollow">http://comment.news.163.com/news_guonei4_bbs/5P15EUDA0001124J.html</a> <a href="http://twitter.com/realfun/statuses/6160347048" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Ftwitter-week-2009-11-29%2F&amp;linkname=Twitter%20Week%20%40%202009-11-29"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/twitter-week-2009-11-29/feed/</wfw:commentRss>
		</item>
		<item>
		<title>关于25马问题的思考</title>
		<link>http://www.2maomao.com/blog/puzzle-of-25-horses/</link>
		<comments>http://www.2maomao.com/blog/puzzle-of-25-horses/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 13:11:44 +0000</pubDate>
		<dc:creator>半瓶墨水</dc:creator>
		
		<category><![CDATA[原创精选]]></category>

		<category><![CDATA[编程随笔]]></category>

		<guid isPermaLink="false">http://www.2maomao.com/blog/?p=1299</guid>
		<description><![CDATA[题酷发芽网上的一个题目 “25匹赛马血拼Top5”：
有25匹马，共5个跑道，不用任何工具，请问

用几场比赛可分出前3名？
几场比赛可以分出前5名？
几场比赛可以给所有赛马排名？


Solrex Yang同... ]]></description>
			<content:encoded><![CDATA[<p><a href="http://fayaa.com/tiku/">题酷发芽网</a>上的一个题目 “<strong><a href="http://fayaa.com/tiku/view/91/">25匹赛马血拼Top5</a></strong>”：</p>
<blockquote><p>有25匹马，共5个跑道，不用任何工具，请问</p>
<ol>
<li>用几场比赛可分出前3名？</li>
<li>几场比赛可以分出前5名？</li>
<li>几场比赛可以给所有赛马排名？</li>
</ol>
</blockquote>
<p><a href="http://blog.solrex.cn/">Solrex Yang</a>同学写了<a href="http://blog.solrex.cn/articles/25-horses-problem.html">一篇文章</a>比较全面的分析了这个问题，虽然后面有人指出其推理过程中的问题，但是可以看出主要的思想还是正确的，那就是尽量利用已经存在的信息。</p>
<p>今天无意间翻信翻到这个问题，突然想到，这其实是个<strong>可以编程求解的问题</strong>，而且跟我已经搞定的猜数字游戏求解过程很像</p>
<p>几点<a href="http://fayaa.com/tiku/view/91/#ans298">零星的想法</a>，等到有时间再来细化：</p>
<p> 1. 几次赛马以后，实际上生成了一个逻辑排序的图，每一次赛马，都要尽可能的把这个图变成一条**线**<br />
 2. 贪心的标准可以是：消除尽量多的分支<br />
 3. 每一步采用贪心算法，不一定能做到全盘最优 - 我求解猜数字游戏的时候就遇到过，贪心总是会有3、4个需要8步的，而全局最优却可以做到都在7步以内<br />
 4. 如果只是前三名，或许贪心算法得到的结果跟全局最优是一致的<br />
 5. 全局最优的算法，粗略一想，需要25!的计算量。要尽量减少计算的话，就要考虑做一些cache，滤掉重复性的计算，或许需要用到动态规划<br />
 6. 如果只是要求前三名，全盘最优应该很容易做到</p>
<p>先写这么多，等有时间再来写程序验证。。。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.2maomao.com%2Fblog%2Fpuzzle-of-25-horses%2F&amp;linkname=%E5%85%B3%E4%BA%8E25%E9%A9%AC%E9%97%AE%E9%A2%98%E7%9A%84%E6%80%9D%E8%80%83"><img src="http://www.2maomao.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.2maomao.com/blog/puzzle-of-25-horses/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

