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

<channel>
	<title>Cai Feng's Blog</title>
	<atom:link href="http://blog.caifeng.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caifeng.me</link>
	<description>Paw trace ...</description>
	<lastBuildDate>Thu, 12 Aug 2010 14:47:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>快要安定下来了</title>
		<link>http://blog.caifeng.me/2010/08/12/%e5%bf%ab%e8%a6%81%e5%ae%89%e5%ae%9a%e4%b8%8b%e6%9d%a5%e4%ba%86/</link>
		<comments>http://blog.caifeng.me/2010/08/12/%e5%bf%ab%e8%a6%81%e5%ae%89%e5%ae%9a%e4%b8%8b%e6%9d%a5%e4%ba%86/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 14:45:56 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[live]]></category>

		<guid isPermaLink="false">http://blog.caifeng.me/?p=86</guid>
		<description><![CDATA[很久没写blog了,折腾了快一年,终于安定下来了.一年之内换了三家公司,我想估计很少会有人像我这样了.
这一年中加入的各个公司都是非常棒的,有着很好的leader,很好的同事,良好的工作环境.之所以选择放弃,主要还是由于自己那颗爱折腾的心在作怪,向往做一些有挑战性的工作.
非常感谢这一年来一起共事过的同事(很多已经成为了朋友),与你们一起工作我真的很开心,希望你们一切都好.也祝愿这些公司能有很好的发展.
]]></description>
			<content:encoded><![CDATA[<p>很久没写blog了,折腾了快一年,终于安定下来了.一年之内换了三家公司,我想估计很少会有人像我这样了.<br />
这一年中加入的各个公司都是非常棒的,有着很好的leader,很好的同事,良好的工作环境.之所以选择放弃,主要还是由于自己那颗爱折腾的心在作怪,向往做一些有挑战性的工作.<br />
非常感谢这一年来一起共事过的同事(很多已经成为了朋友),与你们一起工作我真的很开心,希望你们一切都好.也祝愿这些公司能有很好的发展.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2010/08/12/%e5%bf%ab%e8%a6%81%e5%ae%89%e5%ae%9a%e4%b8%8b%e6%9d%a5%e4%ba%86/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to use google form as a simple survey system</title>
		<link>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/</link>
		<comments>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 06:35:22 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=67</guid>
		<description><![CDATA[Preview

A google form is a simple generally form system. You can use it to generate a form to ask your user some questions and collect the answers into a google spreadsheet automatically. And then you can do farther data analytics with that spreadsheet.
Actually, the google form can be used directly. But in some cases, the [...]]]></description>
			<content:encoded><![CDATA[<h4 id="Preview">Preview</h4>
<ul>
<li>A google form is a simple generally form system. You can use it to generate a form to ask your user some questions and collect the answers into a google spreadsheet automatically. And then you can do farther data analytics with that spreadsheet.</li>
<li>Actually, the google form can be used directly. But in some cases, the user want to change the google form&#8217;s default behavior to meet their requirements, such as they don&#8217;t want it to be redirected to google&#8217;s response page which have google&#8217;s logo there, they want to customize the design of the google form, etc</li>
<li>This scripts is used to focus on these special cases, also it can&#8217;t cover all of these cases, but it&#8217;s a beginning.</li>
</ul>
<h4>Design</h4>
<ul>
<li>I used a iframe to handle the google form&#8217;s default response.</li>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;color: #FCFFBA;">  &lt;form target=&quot;gsurvey_result&quot;&gt;&lt;/form&gt;
  &lt;iframe name=&quot;gsurvey_result&quot; height=&quot;1&quot; style=&quot;display:none;&quot;&gt;&lt;/iframe&gt;</pre></div></div>

<li>I used javascript to replace all of the radio button with a image, when the user clicks the image, the value of the radio will be synced directly. The image can be changed with css.</li>
<li>I used the javascript to check if the required field has a value. But now there&#8217;s nothing to do with the required field without a value.</li>
<li>User can define the response text by themselves.</li>
</ul>
<h4 id="Anexample">An example</h4>
<ul>
<li>Generate a google form with your own google account.</li>
<li>Create a new html file, load the script gsurvey.js, gsurvey.css in the html file.</li>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;color: #FCFFBA;">&lt;html&gt;
&lt;head&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;link rel=&quot;stylesheet&quot; media=&quot;screen&quot; href=&quot;/static/css/gsurvey.css&quot; /&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;/static/js/jquery.gsurvey.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<li>Insert the html code of the google form. You can also define a element holds response text. You can check the code in the attachments.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/07/20/how-to-use-google-form-as-a-simple-survey-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance of str+str and ‘‘.join()</title>
		<link>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/</link>
		<comments>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 02:00:32 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Developer]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=60</guid>
		<description><![CDATA[
&#62;&#62;&#62; a = 'a' * 100000
&#62;&#62;&#62; def t&#40;a&#41;:
&#62;&#62;&#62;     b = ''
&#62;&#62;&#62;     for i in a:
&#62;&#62;&#62;         b = b + '&#124;' + i
&#62;&#62;&#62;     return b
&#62;&#62;&#62; 
&#62;&#62;&#62; time c = t&#40;a&#41;
&#62;&#62;&#62; time c = '&#124;'.join&#40;a&#41;

In my notebook [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span> a = <span style="color: #483d8b;color: #666666;">'a'</span> <span style="color: #66cc66;color: #CCC;">*</span> <span style="color: #ff4500;color: #DDD;">100000</span>
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> t<span style="color: black;color: #CCC;">&#40;</span>a<span style="color: black;color: #CCC;">&#41;</span>:
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span>     b = <span style="color: #483d8b;color: #666666;">''</span>
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span>     <span style="color: #ff7700;font-weight:bold;color: #B83A24;">for</span> i <span style="color: #ff7700;font-weight:bold;color: #B83A24;">in</span> a:
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span>         b = b + <span style="color: #483d8b;color: #666666;">'|'</span> + i
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span>     <span style="color: #ff7700;font-weight:bold;color: #B83A24;">return</span> b
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span> 
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span> <span style="color: #dc143c;color: #8FB394;">time</span> c = t<span style="color: black;color: #CCC;">&#40;</span>a<span style="color: black;color: #CCC;">&#41;</span>
<span style="color: #66cc66;color: #CCC;">&gt;&gt;&gt;</span> <span style="color: #dc143c;color: #8FB394;">time</span> c = <span style="color: #483d8b;color: #666666;">'|'</span>.<span style="color: black;">join</span><span style="color: black;color: #CCC;">&#40;</span>a<span style="color: black;color: #CCC;">&#41;</span></pre></div></div>

<p>In my notebook ( Intel(R) Core(TM)2 CPU T5200  @ 1.60GHz, 1.5G Mem):</p>
<p>The result of time c=t(a):<br />
CPU times: user 2.90 s, sys: 0.00 s, total: 2.90 s<br />
Wall time: 3.07 s</p>
<p>The result of time c = &#8216;|&#8217;.join(a):<br />
CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s<br />
Wall time: 0.01 s</p>
<p>If I changed a from 100000 to 1000000, c=t(a) can&#8217;t give me a result in more than 5 minutes while the other one give me the result in 0.09s.</p>
<p>join is much faster than str + str. str + str need to create new strings all the time, but join doesn&#8217;t. I guess &#8220;join&#8221; maybe do something on the memory level.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/04/28/performance-of-strstr-and-%e2%80%98%e2%80%98join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Resource temporarily unavailable&#8221; on the whm host</title>
		<link>http://blog.caifeng.me/2009/04/04/resource-temporarily-unavailable-on-the-whm-host/</link>
		<comments>http://blog.caifeng.me/2009/04/04/resource-temporarily-unavailable-on-the-whm-host/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 18:30:29 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=58</guid>
		<description><![CDATA[Today, following a document to tune the security of our whm hosting, I enabled &#8220;Shell fork bomb protection&#8221; in &#8220;Security Center&#8221;. But I&#8217;m 100% sure what I did. Then when I try to run the apache process of the user, the exception &#8220;bash: fork Resource temporarily unavailable&#8221; raised. It took me a lot of time [...]]]></description>
			<content:encoded><![CDATA[<p>Today, following a document to tune the security of our whm hosting, I enabled &#8220;Shell fork bomb protection&#8221; in &#8220;Security Center&#8221;. But I&#8217;m 100% sure what I did. Then when I try to run the apache process of the user, the exception &#8220;bash: fork Resource temporarily unavailable&#8221; raised. It took me a lot of time to find why this happen. Finally I got this document: http://www.eddieoneverything.com/linux/linux-whm-cpanel-resource-temporarily-unavailable.php</p>
<p>It&#8217;s because &#8220;Shell fork bomb protection&#8221; will enable the limitation for each user, the limitation is defined with ulimit command. The default limitation is 100 open files with 20 processes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/04/04/resource-temporarily-unavailable-on-the-whm-host/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>来自 &#8220;The Federated States of Micronesia&#8221; 的顾客</title>
		<link>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/</link>
		<comments>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 08:06:12 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=55</guid>
		<description><![CDATA[今天我们站点上出现了个跟国名有关的错误。一个来自&#8221;The Federated States of Micronesia&#8221;的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称&#8221;MICRONESIA, FEDERATED STATES OF&#8221;。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易，这样也能被拒绝，我估计这老兄一定这么想。)
这让我想起了个问题，不知道世界上最长的国家名称能有多少个字符？
写个blog纪念一下这位老兄的国家吧，也算长见识了。
http://en.wikipedia.org/wiki/Federated_States_of_Micronesia
]]></description>
			<content:encoded><![CDATA[<p>今天我们站点上出现了个跟国名有关的错误。一个来自&#8221;The Federated States of Micronesia&#8221;的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称&#8221;MICRONESIA, FEDERATED STATES OF&#8221;。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易，这样也能被拒绝，我估计这老兄一定这么想。)</p>
<p>这让我想起了个问题，不知道世界上最长的国家名称能有多少个字符？<br />
写个blog纪念一下这位老兄的国家吧，也算长见识了。</p>
<p>http://en.wikipedia.org/wiki/Federated_States_of_Micronesia</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/04/01/%e6%9d%a5%e8%87%aa-the-federated-states-of-micronesia-%e7%9a%84%e9%a1%be%e5%ae%a2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分析日志常用到的几个shell工具</title>
		<link>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/</link>
		<comments>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 03:03:40 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/</guid>
		<description><![CDATA[一个不错的例子: http://nunojob.wordpress.com/2008/04/12/history-awk-print-2-sort-uniq-c-sort-rn-head/

httpd.log &#124; awk '{print $2}' \  &#124; sort &#124; uniq -c &#124; sort -rn &#124; head

解释:
httpd.log : 要分析的日志
awk : 用来取出某一特定的列。简单的也可以用cut来代替
sort : 用来排序(第一次排序是用来为后面的uniq服务的。uniq对于没有排序的内容工作不正确)
uniq : 用来uniq有序的内容，-c参数会把重复次数带上
sort -rn : 用来安重复次数倒序排列
head : 用来去前几条数据，默认是10.
]]></description>
			<content:encoded><![CDATA[<p>一个不错的例子: http://nunojob.wordpress.com/2008/04/12/history-awk-print-2-sort-uniq-c-sort-rn-head/</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;">httpd.log <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> \  <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sort</span> <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sort</span> <span style="color: #660033;">-rn</span> <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">head</span></pre></div></div>

<p>解释:<br />
httpd.log : 要分析的日志<br />
awk : 用来取出某一特定的列。简单的也可以用cut来代替<br />
sort : 用来排序(第一次排序是用来为后面的uniq服务的。uniq对于没有排序的内容工作不正确)<br />
uniq : 用来uniq有序的内容，-c参数会把重复次数带上<br />
sort -rn : 用来安重复次数倒序排列<br />
head : 用来去前几条数据，默认是10.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/31/%e5%88%86%e6%9e%90%e6%97%a5%e5%bf%97%e5%b8%b8%e7%94%a8%e5%88%b0%e7%9a%84%e5%87%a0%e4%b8%aashell%e5%b7%a5%e5%85%b7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Satchmo 新体验</title>
		<link>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/</link>
		<comments>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 15:55:27 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[satchmo]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/</guid>
		<description><![CDATA[今天checkout最新的satchmo看了一下，发现变化还是很大的。看样子我们的BE是没法升级到最新的satchmo了&#8230;
还没有时间仔细研究，不过发现有几个satchmo用到的第三方的app值得注意一下：
1. django-registration
http://code.google.com/p/django-registration/
这个已经用过几次，感觉不错，而且感觉它的生命力很强。
2. django-values
http://code.google.com/p/django-values/
satchmo用这个替换了原来自己写的configuration模块。我一直认为satchmo的configuration模块有设计上的缺陷，结果这次被彻底换掉了，不错。有时间研究一下这个。
3. threaded_multihost
http://gosatchmo.com/apps/django-threaded-multihost/
multi-site aware features， 不是很懂，还得看看代码。
]]></description>
			<content:encoded><![CDATA[<p>今天checkout最新的satchmo看了一下，发现变化还是很大的。看样子我们的BE是没法升级到最新的satchmo了&#8230;</p>
<p>还没有时间仔细研究，不过发现有几个satchmo用到的第三方的app值得注意一下：<br />
1. django-registration</p>
<p>http://code.google.com/p/django-registration/</p>
<p>这个已经用过几次，感觉不错，而且感觉它的生命力很强。<br />
2. django-values</p>
<p>http://code.google.com/p/django-values/</p>
<p>satchmo用这个替换了原来自己写的configuration模块。我一直认为satchmo的configuration模块有设计上的缺陷，结果这次被彻底换掉了，不错。有时间研究一下这个。<br />
3. threaded_multihost</p>
<p>http://gosatchmo.com/apps/django-threaded-multihost/</p>
<p>multi-site aware features， 不是很懂，还得看看代码。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/30/satchmo-%e6%96%b0%e4%bd%93%e9%aa%8c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[八卦] google music, 爽！</title>
		<link>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/</link>
		<comments>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 15:43:47 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/</guid>
		<description><![CDATA[今天看新闻发现google出了music搜索，于是试用了一把。 （http://www.google.cn/music/homepage)
搜歌，听歌，下载，一应俱全。
尤其是它的web播放器，用起来很舒服。
对于google的music搜索，有几个疑问:
1. 歌曲的下载地址不是链接到其他网站，而是统一链接到top100.cn
2. 上面可以下载的歌曲很新，不知道版权问题是如何解决的？
]]></description>
			<content:encoded><![CDATA[<p>今天看新闻发现google出了music搜索，于是试用了一把。 （http://www.google.cn/music/homepage)</p>
<p>搜歌，听歌，下载，一应俱全。<br />
尤其是它的web播放器，用起来很舒服。</p>
<p>对于google的music搜索，有几个疑问:<br />
1. 歌曲的下载地址不是链接到其他网站，而是统一链接到top100.cn<br />
2. 上面可以下载的歌曲很新，不知道版权问题是如何解决的？</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/30/%e5%85%ab%e5%8d%a6-google-music-%e7%88%bd%ef%bc%81/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Normal method, @staticmethod, @classmethod of python</title>
		<link>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/</link>
		<comments>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 09:46:51 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=46</guid>
		<description><![CDATA[Reference:
http://snippets.dzone.com/posts/show/1679
http://www.geocities.com/foetsch/python/new_style_classes.htm
Check the doctest in these code bottom.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
&#34;&#34;&#34;
Test the variable methods in class
&#34;&#34;&#34;
&#160;
class K&#40;object&#41;:
    &#34;&#34;&#34;
    Test the variable methods in class
    &#62;&#62;&#62; k_obj = K()
    &#62;&#62;&#62; k_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &#62;&#62;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Reference:<br />
<a href="http://snippets.dzone.com/posts/show/1679">http://snippets.dzone.com/posts/show/1679</a><br />
<a href="http://www.geocities.com/foetsch/python/new_style_classes.htm">http://www.geocities.com/foetsch/python/new_style_classes.htm</a></p>
<p>Check the doctest in these code bottom.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;color: #FCFFBA;"><span style="color: #808080; font-style: italic;color: #CDC;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;color: #CDC;"># -*- coding: utf-8 -*-</span>
<span style="color: #483d8b;color: #666666;">&quot;&quot;&quot;
Test the variable methods in class
&quot;&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">class</span> K<span style="color: black;color: #CCC;">&#40;</span><span style="color: #008000;color: #577A61;">object</span><span style="color: black;color: #CCC;">&#41;</span>:
    <span style="color: #483d8b;color: #666666;">&quot;&quot;&quot;
    Test the variable methods in class
    &gt;&gt;&gt; k_obj = K()
    &gt;&gt;&gt; k_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &gt;&gt;&gt; K.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.K'&gt;)
    &gt;&gt;&gt; k_obj.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.K'&gt;)
    &gt;&gt;&gt; K.method3()
    staticmethod: K.method3() become just method3(None)
    &gt;&gt;&gt; k_obj.method3()
    staticmethod: K.method3() become just method3(None)
    &quot;&quot;&quot;</span>
    <span style="color: #808080; font-style: italic;color: #CDC;"># normal method (instance method)</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> method1<span style="color: black;color: #CCC;">&#40;</span><span style="color: #008000;color: #577A61;">self</span><span style="color: black;color: #CCC;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'Normal method: obj.method1() becomes method1(obj)'</span>
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># class method</span>
    @<span style="color: #008000;color: #577A61;">classmethod</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> method2<span style="color: black;color: #CCC;">&#40;</span>cls<span style="color: black;color: #CCC;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'classmethod: K.method2() becomes method2(klass: %s)'</span> <span style="color: #66cc66;color: #CCC;">%</span> cls
&nbsp;
    <span style="color: #808080; font-style: italic;color: #CDC;"># static method</span>
    @<span style="color: #008000;color: #577A61;">staticmethod</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">def</span> method3<span style="color: black;color: #CCC;">&#40;</span><span style="color: black;color: #CCC;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;color: #B83A24;">print</span> <span style="color: #483d8b;color: #666666;">'staticmethod: K.method3() become just method3(None)'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">class</span> KK<span style="color: black;color: #CCC;">&#40;</span>K<span style="color: black;color: #CCC;">&#41;</span>:
    <span style="color: #483d8b;color: #666666;">&quot;&quot;&quot;
    Test the variable methods' behavior in the subclass.
    &gt;&gt;&gt; kk_obj = KK()
    &gt;&gt;&gt; kk_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    &gt;&gt;&gt; KK.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.KK'&gt;)
    &gt;&gt;&gt; kk_obj.method2()
    classmethod: K.method2() becomes method2(klass: &lt;class '__main__.KK'&gt;)
    &gt;&gt;&gt; KK.method3()
    staticmethod: K.method3() become just method3(None)
    &gt;&gt;&gt; kk_obj.method3()
    staticmethod: K.method3() become just method3(None)
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">pass</span> 
&nbsp;
<span style="color: #ff7700;font-weight:bold;color: #B83A24;">if</span> __name__ == <span style="color: #483d8b;color: #666666;">&quot;__main__&quot;</span>:
    <span style="color: #ff7700;font-weight:bold;color: #B83A24;">import</span> <span style="color: #dc143c;color: #8FB394;">doctest</span>
    <span style="color: #dc143c;color: #8FB394;">doctest</span>.<span style="color: black;">testmod</span><span style="color: black;color: #CCC;">&#40;</span><span style="color: black;color: #CCC;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/18/normal-method-staticmethod-classmethod-of-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert MP3 Id3 tag encoding</title>
		<link>http://blog.caifeng.me/2009/03/12/convert-mp3-id3-tag-encoding/</link>
		<comments>http://blog.caifeng.me/2009/03/12/convert-mp3-id3-tag-encoding/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 07:41:12 +0000</pubDate>
		<dc:creator>ljpsfree</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[id3]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.caifeng.me/blog/?p=43</guid>
		<description><![CDATA[It&#8217;s a long time pain for my mp3 files. I tried a lot of kinds way to convert my mp3 files&#8217; id3 tag encoding. But every time when I need to convert the tag, I can&#8217;t remembered what I did last time. Now I&#8217;m going to record some way to do this.
I used amarok. Since [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a long time pain for my mp3 files. I tried a lot of kinds way to convert my mp3 files&#8217; id3 tag encoding. But every time when I need to convert the tag, I can&#8217;t remembered what I did last time. Now I&#8217;m going to record some way to do this.</p>
<p>I used amarok. Since the developers os amarok hate to deal with various kinds of encoding, they determined to use unicode which required id3v2.4 tag. This decision makes a lot of Chinese music displayed like a mess in the amarok because most of Chinese music used old version, different encode id3 tags.</p>
<p>I found some good ways to convert your music id3 tags here: <a href="http://wiki.linuxmce.org/index.php/Converting_MP3_Tags_To_UTF-8">http://wiki.linuxmce.org/index.php/Converting_MP3_Tags_To_UTF-8</a></p>
<p>The most way I like is mid3iconv</p>
<p>I used it like this:</p>
<p>For a single file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;"><span style="color: #007800;color: blue;">$mid3iconv</span> <span style="color: #660033;">-e</span> gb2312 a.mp3 <span style="color: #660033;">--remove-v1</span> <span style="color: #660033;">-dp</span></pre></div></div>

<p>For a directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;color: #FCFFBA;"><span style="color: #007800;color: blue;">$find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;color: #666666;">&quot;*.mp3&quot;</span> <span style="color: #660033;">-exec</span> mid3iconv <span style="color: #660033;">-e</span> gb2312 <span style="color: #660033;">--remove-v1</span> <span style="color: #660033;">-dp</span> <span style="color: #ff0000;color: #666666;">&quot;{}&quot;</span> \;</pre></div></div>

</pre>
<p>-p option means dry-run, so if you really want to convert, remove this option.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.caifeng.me/2009/03/12/convert-mp3-id3-tag-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
