<?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.gracecode.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0">
<channel>
<title><![CDATA[Gracecode.com]]></title>
<link>http://www.gracecode.com/feed/</link>
<language>zh-cn</language>
<description><![CDATA[精于心、简于形]]></description>
<pubDate>Sun, 14 Mar 2010 05:16:45 +0800</pubDate>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.gracecode.com/gracecode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="gracecode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.gracecode.com/gracecode" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.gracecode.com%2Fgracecode" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
<title><![CDATA[Re:新手虚心求教]]></title>
<link>http://www.gracecode.com/archives/3016/</link>
<pubDate>Wed, 10 Mar 2010 03:47:31 +0000</pubDate>
<category><![CDATA[JavaScript]]></category>
<description><![CDATA[经常有朋友邮件过来咨询技术问题，本人不才经常不是忘记回复就是回复的比较迟。原因是一来本人比较懒（或者可以托词为忙），二来是怕“误人子弟”。

当回复这位仁兄的邮件时，不觉得就发现回复的字数越来越长...]]></description>
<guid>http://www.gracecode.com/archives/3016/</guid>
<slash:comments>6</slash:comments>
<comments>http://www.gracecode.com/archives/3016/#comments</comments>
<content:encoded><![CDATA[<p>经常有朋友邮件过来咨询技术问题，本人不才经常不是忘记回复就是回复的比较迟。原因是一来本人比较懒（或者可以托词为忙），二来是怕“误人子弟”。</p>

<p>当回复这位仁兄的邮件时，不觉得就发现回复的字数越来越长，于是就将其整理为篇 Blog。我的意图是不仅仅帮忙解决问题，而且能提供个解决类似问题的思路。</p>

<h2>邮件原文</h2><pre>来自: Captain
时间: 2010-02-28 20:41
话题: 新手虚心求教

　　你好，我是刚刚入门学习Javascript的新手。我想向你请教一下我在学习过程中所
遇到的一个问题。恕我愚昧，但是我一直无法理解,恳请赐教。 
　　我在学习中碰到过一条这样的声明： var !myVariable != variableValue, 因为在
以前的学习中知道双重否定等于可定，那这则声明是否可以理解成 var myVariable = 
variableValue ?
       若非如此解释，恳求正解。冒昧打扰请多多包涵。</pre><h2>我的回复</h2><p>不好意思，收到你的来信到现在才回复。第一眼看见您提供的代码，个人觉得它不合乎语法规则</p>

<pre>var !myVariable != variableValue</pre><p>根据 ECMA 相关的文档，var 关键字的定义在 12.2 章节（我看的是第五版），它的语法定义是：</p>

<pre>var VariableDeclarationList ;</pre><p>而 VariableDeclarationList 包括</p>

<pre>VariableDeclarationList , VariableDeclaration</pre><p>上述两个定义又包含多种情况，说起来有些复杂，所以我画了张草图（可能不准确，以文档为准）：</p>

<p><img src="http://files.gracecode.com/2010_03_10/1268192678.png" alt="http://files.gracecode.com/2010_03_10/1268192678.png" title="http://files.gracecode.com/2010_03_10/1268192678.png" /></p>

<p>所以，上面的表达式不符合 var 语句的定义要求，因此 Javascript 解析器会报语法错误。</p>

<p>如果是非赋值定义语句，也就是</p>

<pre>!myVariable != variableValue</pre><p>那么就是个条件判断语句，其中有两个条件判断操作符“非（!）”以及“不等于（!=）”，那么我们就要了解它们的结合优先级。</p>

<p><a href="http://www.codehouse.com/javascript/precedence/" title="http://www.codehouse.com/javascript/precedence/">根据相关的参考文档</a>，我们可以得知“非”操作符的优先级比“不等于”要高，因此语句先计算 !myVariable 这块，然后再计算“不等于”后的值。</p>

<p>至于能否改成其他等同的逻辑情况，这里还有个问题就是<a href="http://www.c-point.com/javascript_tutorial/jsoprNot.htm" title="http://www.c-point.com/javascript_tutorial/jsoprNot.htm">值取“非”的时候会有多种情况</a>，这里有个讨论：</p>

<pre>明城: 
问: !a != b 是否等于 b == !!a

崇厚: 
这个还要看数据类型吧？
比较运算符的优先级是最低的

渔隐: 
照这样推理就是a == b 了

崇厚: 
a = ''
b = 0
console.log(!a != b)
console.log(b == !!a)
true true

明城: 
关键还有个“非”操作符，所以 B 始终是和布尔值对比的

崇厚: 
我试出来三个结果
t t 
t f
f f

痴灵: 
var a = 0;
console.log(!a);console.log(typeof(!a),typeof(a));
true boolean number
类型发生了变化了

渔隐: 
用!== 和===吧

明城: 
不纠结了，以后记得逻辑表达式里千万不要加一元操作符
或者加括号

沉鱼: 
有个比较有效的做法，不太记得操作符的优先级时，我都
加（），这样虽然比较挫，不过保险

崇厚: 
不管记得不记得优先级，表达式比较复杂时最好都加括号
这样看起来清晰一些</pre><p>举一反三，以后如果再碰到类似的问题，我们可以：</p>

<ol>
    <li>查文档。<a href="http://en.wikipedia.org/wiki/ECMAScript" title="http://en.wikipedia.org/wiki/ECMAScript">ECMAScript 规范</a>、<a href="https://developer.mozilla.org/en/JavaScript" title="https://developer.mozilla.org/en/JavaScript">MDC 中的文档</a>、甚至 Google 都是我们的好帮手</li>
    <li>如果还是无法理解，可以“偷懒”先看运行结果，然后逆向推断</li>
    <li>团队的力量胜过一个人闭门造车</li>
</ol>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3016/</wfw:commentRss>
</item>
<item>
<title><![CDATA[gdb 命令摘录]]></title>
<link>http://www.gracecode.com/archives/3015/</link>
<pubDate>Tue, 09 Mar 2010 03:29:08 +0000</pubDate>
<category><![CDATA[软件]]></category>
<description><![CDATA[http://pic.yupoo.com/feelinglucky/560328f80804/medium.png

最近在了解 Mac 下的 ObjC 开发，所以不可避免的会用到 [[http:...]]></description>
<guid>http://www.gracecode.com/archives/3015/</guid>
<slash:comments>3</slash:comments>
<comments>http://www.gracecode.com/archives/3015/#comments</comments>
<content:encoded><![CDATA[<p><img src="http://pic.yupoo.com/feelinglucky/560328f80804/medium.png" alt="http://pic.yupoo.com/feelinglucky/560328f80804/medium.png" title="http://pic.yupoo.com/feelinglucky/560328f80804/medium.png" /></p>

<p>最近在了解 Mac 下的 ObjC 开发，所以不可避免的会用到 <a href="http://www.gnu.org/software/gdb/" title="http://www.gnu.org/software/gdb/">gdb</a>。gdb 的命令很多，因此自己便学习边做笔记，然后就有了这份摘录。</p>

<p>总体来讲，Mac OS X 是个很好的开发平台，以前用到的 Linux 下的技术几乎都可以“无痛”得在 Mac 下延续（<a href="http://en.wikipedia.org/wiki/Mac_OS_X" title="http://en.wikipedia.org/wiki/Mac_OS_X">了解 Mac 系统到兄弟自然知道其中的原因</a>）。</p>

<p>所以，<a href="http://blog.youxu.info/2010/02/28/why-mac-os-x-for-programmers/" title="http://blog.youxu.info/2010/02/28/why-mac-os-x-for-programmers/">建议开发人员都来尝试熟悉下 Mac OS X 系统</a>。</p>

<p>这份摘录可以到这里<a href="http://www.yupoo.com/photos/feelinglucky/72082507/zoom/" title="http://www.yupoo.com/photos/feelinglucky/72082507/zoom/">下载大图</a>或者<a href="http://files.gracecode.com/2010_03_08/1268027682.zip" title="http://files.gracecode.com/2010_03_08/1268027682.zip">下载包括原文件的压缩包</a>。</p>

<p><img src="http://pic.yupoo.com/feelinglucky/816798f7ef51/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/816798f7ef51/medium.jpg" title="http://pic.yupoo.com/feelinglucky/816798f7ef51/medium.jpg" /></p>

<p>顺便推荐下 <a href="http://www.novamind.com/" title="http://www.novamind.com/">NovaMind</a> 这个思维导图软件，虽然是商业版本的但界面以及功能方面的确比同类版本要丰富很多。</p>

<p><tt> -- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3015/</wfw:commentRss>
</item>
<item>
<title><![CDATA[摄影 - 淘宝年会，成长]]></title>
<link>http://www.gracecode.com/archives/3014/</link>
<pubDate>Sun, 07 Mar 2010 15:43:10 +0000</pubDate>
<category><![CDATA[我的生活]]></category>
<description><![CDATA[从来都是觉得自己不是位能轻易被打动的人，而当看到公司年会上[[http://is.gd/9TlJ8|麦包包的节目]]后，我确定当时我的掌声是有史以来最由衷的。

麦包包，从依靠淘宝成长起来的业余卖...]]></description>
<guid>http://www.gracecode.com/archives/3014/</guid>
<slash:comments>3</slash:comments>
<comments>http://www.gracecode.com/archives/3014/#comments</comments>
<content:encoded><![CDATA[<p>从来都是觉得自己不是位能轻易被打动的人，而当看到公司年会上<a href="http://is.gd/9TlJ8" title="http://is.gd/9TlJ8">麦包包的节目</a>后，我确定当时我的掌声是有史以来最由衷的。</p>

<p>麦包包，从依靠淘宝成长起来的业余卖家，到具有六十多位成员的专业团队，让人活生生得看到了成长的历程。</p>

<p>年会的前几天，同时也刚好是本人淘宝两周年纪念日。回过头来<a href="http://www.gracecode.com/archives/2876/" title="http://www.gracecode.com/archives/2876/">对比一年前写的文字</a>，感觉像是在和过去的我交谈。</p>

<p>当然，一如既往的，我还是给我自己定了今年的计划。每个人都会成长，当然我希望我也会。</p>

<p>回到年会，其实拍照的是我的同事 <a href="http://www.xintend.com/" title="http://www.xintend.com/">龙藏</a>，我只是从其中挑选了几张我中意的：</p>

<p><img src="http://farm5.static.flickr.com/4025/4411502742_60134b7e37.jpg" alt="http://farm5.static.flickr.com/4025/4411502742_60134b7e37.jpg" title="http://farm5.static.flickr.com/4025/4411502742_60134b7e37.jpg" /></p>

<p><img src="http://farm3.static.flickr.com/2763/4411503188_66bae2b620.jpg" alt="http://farm3.static.flickr.com/2763/4411503188_66bae2b620.jpg" title="http://farm3.static.flickr.com/2763/4411503188_66bae2b620.jpg" /></p>

<p><img src="http://farm5.static.flickr.com/4065/4410734963_7ddea31b1b.jpg" alt="http://farm5.static.flickr.com/4065/4410734963_7ddea31b1b.jpg" title="http://farm5.static.flickr.com/4065/4410734963_7ddea31b1b.jpg" /></p>

<p><img src="http://farm5.static.flickr.com/4006/4410733975_b1186d3108.jpg" alt="http://farm5.static.flickr.com/4006/4410733975_b1186d3108.jpg" title="http://farm5.static.flickr.com/4006/4410733975_b1186d3108.jpg" /></p>

<p>…</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3014/</wfw:commentRss>
</item>
<item>
<title><![CDATA[一些被忽视的 PHP 函数（整理）]]></title>
<link>http://www.gracecode.com/archives/3013/</link>
<pubDate>Wed, 10 Feb 2010 09:10:49 +0000</pubDate>
<category><![CDATA[PHP]]></category>
<description><![CDATA[真的是不用不知道，其实我们熟悉的 PHP 还有很多好东西没有发掘。[[http://infinity-infinity.com/2009/07/10-php-functions-you-probabl...]]></description>
<guid>http://www.gracecode.com/archives/3013/</guid>
<slash:comments>15</slash:comments>
<comments>http://www.gracecode.com/archives/3013/#comments</comments>
<content:encoded><![CDATA[<p>真的是不用不知道，其实我们熟悉的 PHP 还有很多好东西没有发掘。<a href="http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/" title="http://infinity-infinity.com/2009/07/10-php-functions-you-probably-never-use/">看到这篇文章</a>，当时就泪奔了好几回，重点推荐下，顺便我自己也做个整理。</p>

<h2>sys_getloadavg()</h2><p><a href="http://cn.php.net/sys_getloadavg" title="http://cn.php.net/sys_getloadavg">这个函数</a>返回当前<a href="http://www.gracecode.com/archives/2973/" title="http://www.gracecode.com/archives/2973/">系统的负载均值信息</a>（当然 Windows 下不适用），详细文档可以翻阅 PHP 的相关文档。文档中有段示例代码，基本上也就能看出它的用途了。</p>

<pre>&lt;?php
$load = sys_getloadavg();
if ($load[0] &gt; 80) {
    header('HTTP/1.1 503 Too busy, try again later');
    die('Server too busy. Please try again later.');
}</pre><p>PS，如果“很不幸”得你的 PHP 环境中没有这个函数，可以考虑使用下面这段代码 <a href="http://cn.php.net/manual/en/function.sys-getloadavg.php#67928" title="http://cn.php.net/manual/en/function.sys-getloadavg.php#67928">via</a></p>

<pre>if (!function_exists('sys_getloadavg')) {
    function sys_getloadavg()
    {
        $loadavg_file = '/proc/loadavg';
        if (file_exists($loadavg_file)) {
            return explode(chr(32),file_get_contents($loadavg_file));
        }
        return array(0,0,0);
    }
}</pre><p>这一特性如果使用得当，能减轻服务器部分压力。</p>

<h2>pack()</h2><p><a href="http://cn.php.net/pack" title="http://cn.php.net/pack">pack</a> 对应的还有个函数为 <a href="http://cn.php.net/unpack" title="http://cn.php.net/unpack">unpack</a>，用于压缩二进制串，文中的作者的示例非常清楚</p>

<pre>$pass_hash = pack(&quot;H*&quot;, md5(&quot;my-password&quot;));</pre><p>如果你使用 PHP5，那么可以直接这样子</p>

<pre>$pass_hash = md5(&quot;my-password&quot;, true); // PHP 5+</pre><p>这样做的好处之一是能减少串存储空间（能节省多少呢？可能又会是另篇文章了）。</p>

<p>这里还有个示例代码可以 pack 数组 <a href="http://cn.php.net/manual/en/function.pack.php#84258" title="http://cn.php.net/manual/en/function.pack.php#84258">via</a></p>

<pre>&lt;?php
function pack_array($v,$a) {
 return call_user_func_array(pack,array_merge(array($v),(array)$a));
}</pre><h2>cal_days_in_month()</h2><p><a href="http://cn.php.net/manual/en/function.cal-days-in-month.php" title="http://cn.php.net/manual/en/function.cal-days-in-month.php">该函数</a>可以直接返回指定月份中的天数，例如</p>

<pre>$days = cal_days_in_month(CAL_GREGORIAN, date(&quot;m&quot;), date(&quot;Y&quot;)); // 31</pre><p>我敢保证，<a href="http://cn.php.net/manual/en/function.cal-days-in-month.php#38666" title="http://cn.php.net/manual/en/function.cal-days-in-month.php#38666">你自己实现过类似功能的函数</a> :^)</p>

<h2>_()</h2><p>呃，<a href="http://cn.php.net/manual/en/function.gettext.php" title="http://cn.php.net/manual/en/function.gettext.php">这的确也是个 PHP 函数</a>（也有可能是最短的 PHP 内置函数）。<tt>_()</tt> 是它的“小名”，它的大名是 <tt>gettext()</tt>。</p>

<p>写过 Wordpress 皮肤的朋友会了解 <tt>__()</tt> 以及 <tt>_e()</tt> 这些函数，其实 PHP 早已经自带了相关的功能。</p>

<pre>// Set language to German
setlocale(LC_ALL, 'de_DE');
 
// Specify location of translation tables
bindtextdomain(&quot;myPHPApp&quot;, &quot;./locale&quot;);
 
// Choose domain
textdomain(&quot;myPHPApp&quot;);
 
echo _(&quot;Have a nice day&quot;);</pre><p>利用 <a href="http://cn.php.net/manual/en/ref.gettext.php" title="http://cn.php.net/manual/en/ref.gettext.php">gettext</a> 可以编写多语言的应用，现在您感兴趣的可能就是如何编写 locale 文件，这但已经不是此文涉及的重点，<a href="http://cn.php.net/manual/en/ref.gettext.php" title="http://cn.php.net/manual/en/ref.gettext.php">更多信息可以移步到这里</a>。</p>

<h2>get_browser()</h2><p>坦白讲，见到<a href="http://cn.php.net/get_browser" title="http://cn.php.net/get_browser">这个函数</a>我当时就彻底泪奔。有了这个函数，再也不用自己去分析 <tt>$_SERVER['HTTP_USER_AGENT']</tt> 这个字符串了。</p>

<p>更多的信息可以参考这里。在使用此函数前，<a href="http://browsers.garykeith.com/downloads.asp" title="http://browsers.garykeith.com/downloads.asp">你可能需要个 browscap.ini 配置文件</a>，相信你可以搞定的。</p>

<h2>debug_print_backtrace()</h2><p>以前查看函数调用堆栈，我会使用 <a href="http://xdebug.org/" title="http://xdebug.org/">xdebug</a> 等的扩展，其实 PHP5 版本以后已经<a href="http://cn.php.net/debug_print_backtrace" title="http://cn.php.net/debug_print_backtrace">内置了相关的函数</a>。</p>

<p><a href="http://cn.php.net/manual/en/function.debug-print-backtrace.php#92542" title="http://cn.php.net/manual/en/function.debug-print-backtrace.php#92542">顺便再分享个“蛋疼”的小技巧</a>，如果你记不住这个函数的名字，可以用这段代码同样能达到目的（看起来还是记住那个函数靠谱）：</p>

<pre>&lt;?php
$e = new Exception();
print_r(str_replace('/path/to/code/', '', $e-&gt;getTraceAsString()));</pre><h2>natsort()</h2><p>这个函数用于<a href="http://cn.php.net/natsort" title="http://cn.php.net/natsort">自然排序</a>，这个大家可能都要用到。贴下相关的文档链接以及示例代码</p>

<pre>$items = array(&quot;100 apples&quot;, &quot;5 apples&quot;, &quot;110 apples&quot;, &quot;55 apples&quot;);
 
// normal sorting:
sort($items);
print_r($items);
    # Outputs:
    # Array
    # (
    #     [0] =&gt; 100 apples
    #     [1] =&gt; 110 apples
    #     [2] =&gt; 5 apples
    #     [3] =&gt; 55 apples
    # )

natsort($items);
print_r($items);
    # Outputs:
    # Array
    # (
    #     [2] =&gt; 5 apples
    #     [3] =&gt; 55 apples
    #     [0] =&gt; 100 apples
    #     [1] =&gt; 110 apples
    # )</pre><p>有关自然排序的算法规则，可以<a href="http://sourcefrog.net/projects/natsort/" title="http://sourcefrog.net/projects/natsort/">参考这里的文档</a>。</p>

<h2>glob()</h2><p>这个<a href="http://cn.php.net/manual/en/function.glob.php" title="http://cn.php.net/manual/en/function.glob.php">函数的功能</a>同样让人感到泪奔，先不说功能直接上示例代码</p>

<pre>foreach (glob(&quot;*.php&quot;) as $file) {
    echo &quot;$file\n&quot;;
}</pre><p>相比你已经了解该函数的用途了，那么我们就可以有更多的“玩法”，例如就显示目录（<a href="http://cn.php.net/manual/en/function.glob.php#95972" title="http://cn.php.net/manual/en/function.glob.php#95972">via</a>）：</p>

<pre>$dirs = array_filter(glob($path.'*'), 'is_dir');</pre><p>当然，文件递归你也可以<a href="http://www.gracecode.com/archives/2965/" title="http://www.gracecode.com/archives/2965/">考虑使用下 SPL 扩展</a>。</p>

<p>补充 by <a href="http://syre.blogbus.com/" title="http://syre.blogbus.com/">神仙</a>：</p>

<pre>glob 有个参数选项 GLOB_ONLYDIR 就可以只列目录</pre><h2>PHP Filter</h2><p>如果你还在正则验证字符串，那么就真的“Out”了。自 PHP5.2 版本以后，<a href="http://php.net/manual/en/book.filter.php" title="http://php.net/manual/en/book.filter.php">内置了 PHP Fliter 模块</a>用于专门验证 电子邮件、URL 等是否合法，示例代码：</p>

<pre>var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));</pre><p>由于是新生的模块，因此还有很多的陷阱，例如</p>

<pre>filter_var('abc', FILTER_VALIDATE_BOOLEAN); // bool(false)
filter_var('0', FILTER_VALIDATE_BOOLEAN);   // bool(false)</pre><p>但这不影响我们去尝试。有关 PHP Filter 的更多信息，相信能拎出来另外写篇文章了。</p>

<p><tt>-- Split --</tt></p>

<p>最后，感叹 PHP 其实是个历久弥新的工具，不小心我们就会悲剧性得重复造了只轮子。因此，时常看看 PHP 文档每次都会有新的收获。</p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3013/</wfw:commentRss>
</item>
<item>
<title><![CDATA[acookie 改进心得]]></title>
<link>http://www.gracecode.com/archives/3012/</link>
<pubDate>Thu, 04 Feb 2010 05:50:34 +0000</pubDate>
<category><![CDATA[JavaScript]]></category>
<description><![CDATA[这是工作记录，慢慢的不知不觉就形成篇文章了，就发在这里吧。

{{{-- Split --}}}

acookie 就是段统计代码，它的原理就是发送个 GET 请求到统计服务器，并附上本地用户...]]></description>
<guid>http://www.gracecode.com/archives/3012/</guid>
<slash:comments>4</slash:comments>
<comments>http://www.gracecode.com/archives/3012/#comments</comments>
<content:encoded><![CDATA[<p>这是工作记录，慢慢的不知不觉就形成篇文章了，就发在这里吧。</p>

<p><tt>-- Split --</tt></p>

<p>acookie 就是段统计代码，它的原理就是发送个 GET 请求到统计服务器，并附上本地用户的浏览器类型、分辨率等其他信息。</p>

<h2>问题</h2><p>有人报告 acookie 的代码出现 <a href="http://www.gracecode.com/archives/2491/" title="http://www.gracecode.com/archives/2491/">XSS</a>，原理是利用某 GET 参数 <a href="http://en.wikipedia.org/wiki/Bypass" title="http://en.wikipedia.org/wiki/Bypass">bypass</a> 未过滤完全的字符。这里是原先的代码摘录：</p>

<pre>(function() {
    function akrand(num) {
        return Math.floor(Math.random() * num) + 1
    }
    var P = location.pathname;
    if ((parent === self) || P.indexOf('{...}') != - 1 || P.indexOf('{...}') != - 1) {
        var R = escape(document.referrer);
        var id = &quot;&quot; + akrand(9999999) + akrand(9999999);
        var title = escape(document.title);
                document.write('&lt;img src=&quot;http://foo/1.gif?acookie_load_id=' + id + '&amp;title=' + title + '&amp;pre=' + R 
                       + '&amp;param0={...}&amp;param1={...}&amp;param2={...}&quot;  width=&quot;0&quot; height=&quot;0&quot; style=&quot;display:none;&quot; /&gt;');
    }
})();</pre><p>这段代码“年事已高”每次的修修补补都是治标不治本，于是干脆考虑重写这段统计代码。</p>

<h2>目标</h2><p>在开始重写之前，为将要写的代码列了几条目标：</p>

<ol>
    <li>流量方面的考虑，代码要尽可能的简短</li>
    <li>尽可能的优化性能</li>
    <li>“绿色”，不干扰页面的其他脚本</li>
    <li>脚本尽可能得做到安全</li>
</ol>

<h2>思考</h2><ol>
    <li>使用原先的 document.write 会在页面中加入 DOM，直接使用 new Image 更好</li>
    <li>原先的判断条件很冗余，完全可以考虑个函数搞定</li>
    <li>安全方面虽然可以写个简短的过滤函数，但这样代码又会很长</li>
</ol>

<h2>解决</h2><p>下面是反复修改后的最终代码：</p>

<pre>(function(){
    var M = function(n) {
        return Math.floor(Math.random() * n) + 1;
    },
    I = function() {
        for (var i = 0, P = location.pathname, args = arguments, len = args.length; i &lt; len; i++) {
            if (P &amp;&amp; P.indexOf(args[i]) !== -1) {
                return 1;
            }
        }
        return 0;
    },
    D = document, R = escape(D.referrer), S = screen, T = escape(D.title);

    if (parent === self || I('{...}') || I('{...}')) {
        try {
            return new Image().src = [
                &quot;http://foo/1.gif?cache=&quot; + M(9999999),
                '&amp;pre='+ R +'&amp;scr='+ S.width +'x'+ S.height + '&amp;title=' + T,
                '&amp;param0=' + '{...}',
                '&amp;param1=' + '{...}',
                '&amp;param2=' + '{...}'
            ].join('');
        } catch (e) {}
    }
})();</pre><p>本来想使用 <tt>~</tt>function() {}; 这样的闭包，<a href="http://www.gracecode.com/archives/3004/" title="http://www.gracecode.com/archives/3004/">结果发现效率方面还是原先的理想</a>（当然不会差很多），加之可能以后阅读的同事会有困扰，还是采用原先的吧。</p>

<p>在这个案例中，其实返回 0 和 1 同比返回 false 和 true 是同样的道理，处于节省代码量考虑，直接使用整型值。</p>

<p>安全方面出于简单原则考虑，没有考虑使用转义函数，而是采用数组拼贴的方式，这样就算有注入也会造成语法报错而不能指定此段脚本，前面加 <tt>return</tt> 也是这样考虑。</p>

<h2>后记</h2><p>考虑以后的代码可维护性很重要，这个例子中代码虽然简单，当然还会有更极端的写法，不过处于以后同事的合作考虑，尽量不要写得过于的“专业”。</p>

<p>采用 document.write 的考虑是想直接使用脚本在页面上输出，因此在本案例中不是很适用，同时才用这一方法在安全的角度上考虑需要过滤的字符太多，因此如果了解需求（比如仅仅是生成个带参数的 URL）还是避免使用它</p>

<p>XSS 和 <a href="http://www.gracecode.com/archives/2821/" title="http://www.gracecode.com/archives/2821/">CSRF</a> 等虽说后台处理是治本的，但如果使用不当前后台考虑不周全就算加入了对应的过滤函数，也有可能造成注入。也从另个角度考虑，有时候完善的代码也能从一定程度上加大注入的难度，尤其是 Javascript 等这种“每个人都可以看见得脚本”。</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3012/</wfw:commentRss>
</item>
<item>
<title><![CDATA[Mac 下禁用 CNNIC CA 证书]]></title>
<link>http://www.gracecode.com/archives/3011/</link>
<pubDate>Tue, 02 Feb 2010 03:25:51 +0000</pubDate>
<category><![CDATA[奇技淫巧]]></category>
<description><![CDATA[有关 CNNIC 的警告这里有个[[http://autoproxy.org/zh-CN/node/66|详细的说明]]，不多做解释。对于 Mac 用户，这里有个简单的办法禁用 CNNIC CA 证书...]]></description>
<guid>http://www.gracecode.com/archives/3011/</guid>
<slash:comments>7</slash:comments>
<comments>http://www.gracecode.com/archives/3011/#comments</comments>
<content:encoded><![CDATA[<p>有关 CNNIC 的警告这里有个<a href="http://autoproxy.org/zh-CN/node/66" title="http://autoproxy.org/zh-CN/node/66">详细的说明</a>，不多做解释。对于 Mac 用户，这里有个简单的办法禁用 CNNIC CA 证书。</p>

<p><img src="http://files.gracecode.com/2010_02_01/1265080937.png" alt="http://files.gracecode.com/2010_02_01/1265080937.png" title="http://files.gracecode.com/2010_02_01/1265080937.png" /></p>

<p>打开“钥匙串访问”，搜索 “CNNIC ”即可看到对应的证书。双击该证书</p>

<p><img src="http://files.gracecode.com/2010_02_01/1265080978.png" alt="http://files.gracecode.com/2010_02_01/1265080978.png" title="http://files.gracecode.com/2010_02_01/1265080978.png" /></p>

<p>下拉“信任”选择“永不信任”即可。</p>

<p>根据上述文中的提醒，同时把有“entrust.net”关键字的证书也禁用掉，这样就没有上述文中的风险了。</p>

<p>先不讨论文中有关证书的风险，但 <a href="http://www.booto.net/?p=1517" title="http://www.booto.net/?p=1517">CNNIC 的流氓</a>已经众人皆知，这的确让人感到很不安。因此，个人对于这件事的态度，也是“宁可信其有，不可信其无”。</p>

<p>个人信息安全这块，有时候往往会忽视。<a href="http://uicom.net/blog/?p=862" title="http://uicom.net/blog/?p=862">国内的大环境如此</a>，也只能是人人自危。</p>

<p>PS，这里有个投票号召众浏览器厂商移除 CNNIC 证书，<a href="https://spreadsheets.google.com/viewform?formkey=dGctTVY0Y3VxX3lrXzZoeG90WDFBVXc6MA" title="https://spreadsheets.google.com/viewform?formkey=dGctTVY0Y3VxX3lrXzZoeG90WDFBVXc6MA">有兴趣可以看下</a>（<a href="https://spreadsheets.google.com/pub?key=tg-MV4cuq_yk_6hxotX1AUw&amp;output=html" title="https://spreadsheets.google.com/pub?key=tg-MV4cuq_yk_6hxotX1AUw&amp;output=html">查看结果</a>）。</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3011/</wfw:commentRss>
</item>
<item>
<title><![CDATA[看不透 iPad]]></title>
<link>http://www.gracecode.com/archives/3010/</link>
<pubDate>Fri, 29 Jan 2010 04:17:34 +0000</pubDate>
<category><![CDATA[观点]]></category>
<description><![CDATA[[[http://twitter.com/feelinglucky/status/8283751730|就如我期前所说的]]，[[http://www.apple.com/ipad/|Apple 新的...]]></description>
<guid>http://www.gracecode.com/archives/3010/</guid>
<slash:comments>5</slash:comments>
<comments>http://www.gracecode.com/archives/3010/#comments</comments>
<content:encoded><![CDATA[<p><a href="http://twitter.com/feelinglucky/status/8283751730" title="http://twitter.com/feelinglucky/status/8283751730">就如我期前所说的</a>，<a href="http://www.apple.com/ipad/" title="http://www.apple.com/ipad/">Apple 新的平板出来后</a>，Google Reader 中有关 iPad 的消息铺天盖地的过来。</p>

<p>总体看来，发现负面的消息多于正面消息，既然已经有那么多有关 iPad 的文章了，那么我也跟个风来说说我对 iPad 的看法。</p>

<h2>我们为何失望</h2><p>发布会后的几个小时，就看到老外就很不客气的这样评价 iPad：</p>

<pre>As always, Apple's posted a full video of the iPad event, 
so you can pretend you were right there as Steve Jobs 
unveiled the world's most incredible digital photo frame.</pre><p>我几乎熬夜看完了苹果的发布会。上述用户的言论虽有偏激之处但也不无道理，我和此用户一样，心里也有点小小的遗憾。</p>

<p><img src="http://files.gracecode.com/2010_01_28/1264734559.jpg" alt="http://files.gracecode.com/2010_01_28/1264734559.jpg" title="http://files.gracecode.com/2010_01_28/1264734559.jpg" /></p>

<p><a href="http://www.wired.com/gadgetlab/2010/01/ten-things-missing-from-the-ipad/" title="http://www.wired.com/gadgetlab/2010/01/ten-things-missing-from-the-ipad/">对于 iPad 最多的抱怨大多都是在硬件上</a>，有关硬件上的问题又集中在了扩展性、性能等方面 -- 对于用户来看说 iPad 是个大号的 iPod Touch 一点也不为过。</p>

<p>iPad 让用户失望的点太多，让我失望的是我期待的 Apple 平板电脑系统会是精简版的 Mac OS，而事实上 iPad 取而代之的是“增强版”的 iPhone OS，这无疑个人对于 iPad 而言诱惑程度降低了不少。</p>

<p>不过，采用了精简版的 Mac OS，那么可能硬件的改动会比目前的大得多，硬件成本（包括耗电量）可能不会是目前的售价。</p>

<p>另外个可能的可能，就是 iPad 会为 iPhone OS 4.0 开路，种种的现象说明 iPhone OS 的触手会越来越长。iPhone OS 上的应用一点也不比 Mac OS 少（甚至更多），Apple 当然不会放弃这张牌。</p>

<p>Apple 要和 Google 干，那么 iPhone OS 之于 Android 会是很好的竞争对手。iPad 的出现无疑会让 Apple 巩固 iPhone OS 的地位。但换个角度考虑，iPad 可能会成为这场仗中的陪嫁品。</p>

<p>因此总体而言，iPad 在 Apple 产品线中的位置在 Macbook 和 iPhone 之间。我期望 iPad 使用 Mac OS 只是更希望它能更靠近 MacBook 那边些。</p>

<h2>不仅仅是硬件</h2><p>回到 iPad 硬件的这个话题，这次改动最大的可能就是整体的系统架构。Apple 采用自家的 A4 处理器让开发人员们充满了好奇。</p>

<p><img src="http://pic.yupoo.com/feelinglucky/960478c5cb18/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/960478c5cb18/medium.jpg" title="http://pic.yupoo.com/feelinglucky/960478c5cb18/medium.jpg" /></p>

<p>有关 A4 处理器的资料并不多，但值得肯定的是 iPad 肯定不会是简单地更换块处理器那么简单。如果正如<a href="http://www.meirendaddy.com/blog/?p=750" title="http://www.meirendaddy.com/blog/?p=750">这篇文中所言</a>，那么 A4 高达 1g 的处理的<a href="http://www.gracecode.com/archives/3007/" title="http://www.gracecode.com/archives/3007/">可玩程度可比 iPod Touch 高得多</a>（这是肯定的）。</p>

<p>扩展性方面，iPad 在夹缝中也是非常的难受，它注定会和 iPhone 和 Mac 不同，因此它没有摄像头和语音输入，同时它也会没有 USB、火线等接口。</p>

<p>其实，我更愿意将 iPad 和 Macbook Air 归为同一条产品线。</p>

<p>iPad 屏幕方面的争议也相当得多，例如为何不用 OLED 以及 16:9 的宽屏等。可能苹果的对于 iPad 屏幕的搭配是出于成本方面的考虑。除此之外，我怎么也想不通 Apple 为何会这样干。</p>

<p>同时，iPad 的 9 寸触摸屏对于设计人员而言也是个挑战。iPhone 和 iPod Touch 的 3 寸“金莲”完全可以搬抄手机设备的设计，想象的空间也相对较小，但 iPad 的“大饼脸”则会不同。</p>

<p>硬件方面还有个可能，<a href="http://www.tomsguide.com/us/iPod-Touch-Bluetooth,news-3642.html" title="http://www.tomsguide.com/us/iPod-Touch-Bluetooth,news-3642.html">就是 iPad 会不会如当年的 iPod Touch 2g 一样给用户个“惊喜”呢</a>？相信我，其实 Apple 很擅长做这样的事情。</p>

<p>注定的，硬件方面从一开始 Apple 就满足的不了用户的 100% 需求。</p>

<h2>好戏还在后头</h2><p>犹如运动员在起跑之前都会将屁股翘起来一样，目前我们看到和听到的有关 iPad 的消息都是它的“屁股”。</p>

<p>我们对于 iPad 的了解也仅仅停留在 Apple 的发布会、几张产品图、网友的评论等。</p>

<p>结论应该在两三月后，看到 iPad 的真机并拆解、SDK 、iPhone OS 4.0 以及 App Store 的应用丰富程度等，再做定论。</p>

<p>论 Apple 功底，绝对不会让 iPad 那么简单，而我们现在能做的也只能是等待。</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3010/</wfw:commentRss>
</item>
<item>
<title><![CDATA[Python 脚本：自动从豆瓣获取专辑封面]]></title>
<link>http://www.gracecode.com/archives/3009/</link>
<pubDate>Sat, 23 Jan 2010 09:01:27 +0000</pubDate>
<category><![CDATA[Mac]]></category>
<description><![CDATA[iTunes 下的显示专辑封面往往被看作是鸡肋，到不是因为它的功能不好用，而是因为很多时候它都找不到中文歌曲的专辑封面。

http://pic.yupoo.com/feelinglucky/73...]]></description>
<guid>http://www.gracecode.com/archives/3009/</guid>
<slash:comments>22</slash:comments>
<comments>http://www.gracecode.com/archives/3009/#comments</comments>
<content:encoded><![CDATA[<p>iTunes 下的显示专辑封面往往被看作是鸡肋，到不是因为它的功能不好用，而是因为很多时候它都找不到中文歌曲的专辑封面。</p>

<p><img src="http://pic.yupoo.com/feelinglucky/738948bd156f/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/738948bd156f/medium.jpg" title="http://pic.yupoo.com/feelinglucky/738948bd156f/medium.jpg" /></p>

<p>于是乎，就利用周末的时间用 Python 写了这样的一个脚本，用于自动从豆瓣找专辑封面并嵌入至 mp3 文件中。使用方法相对简单，<a href="http://gracecode.googlecode.com/files/getCover_20100123.zip" title="http://gracecode.googlecode.com/files/getCover_20100123.zip">下载压缩包以后</a>，命令行</p>

<pre>python getCover.py *.mp3 </pre><p>即可。</p>

<p>这里要说面下</p>

<ol>
    <li>脚本是 Python 2.x 的版本，3.1 下测试过没法用，Mac 下自带的默认就是 2.x 版本的，懒得转换了。</li>
    <li>ID3 的信息必须清楚，因为搜索 豆瓣 上的专辑插图是以此为依据的（当然，你也可以改下源代码）</li>
    <li>mp3  的 ID3 标签必须是 id3v2 和 utf-8 编码（详细有关 id3 方面的问题，<a href="http://blog.wuxinan.net/archives/507" title="http://blog.wuxinan.net/archives/507">可以参考这里</a>）</li>
    <li>对应的 mp3 文件可写</li>
</ol>

<p>Windows 下可以用 千千静听 批量转换 mp3 文件的 id3，如果在 Mac 平台下，可以考虑使用 <a href="http://www.sinomac.com/ID3Mod/index.php" title="http://www.sinomac.com/ID3Mod/index.php">ID3Mod</a> 这个工具。</p>

<p>脚本在 Mac 下测试通过，理论上说 Windows 以及其他平台都可以正常使用。如果在使用过程中碰到问题，欢迎联系我。</p>

<p>最后，感谢 <a href="http://www.fuchaoqun.com/2010/01/python-mp3-id3v2-lyrics-attached_picture/" title="http://www.fuchaoqun.com/2010/01/python-mp3-id3v2-lyrics-attached_picture/">付超群 推荐那么好的库</a>。</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3009/</wfw:commentRss>
</item>
<item>
<title><![CDATA[摄影 - 毛玻璃外的世界]]></title>
<link>http://www.gracecode.com/archives/3008/</link>
<pubDate>Fri, 22 Jan 2010 04:06:52 +0000</pubDate>
<category><![CDATA[摄影]]></category>
<description><![CDATA[上个周末回了趟家，参加同学的婚礼。其实与其说是同学的婚礼，到不如是老同学的聚会。同学多年不见，在席上自然少不了话语。

看着那对新人幸福的样子，在旁的同学也跟着调侃说到，现在基本上我们见面是聊“你...]]></description>
<guid>http://www.gracecode.com/archives/3008/</guid>
<slash:comments>5</slash:comments>
<comments>http://www.gracecode.com/archives/3008/#comments</comments>
<content:encoded><![CDATA[<p>上个周末回了趟家，参加同学的婚礼。其实与其说是同学的婚礼，到不如是老同学的聚会。同学多年不见，在席上自然少不了话语。</p>

<p>看着那对新人幸福的样子，在旁的同学也跟着调侃说到，现在基本上我们见面是聊“你结婚了没”，或许过几年就要问“你儿子、女儿生了没”，再过几年就是“你儿子、女儿读书了没”…</p>

<p>是呀，我们的确又是“老”了一岁，在坐的各位都已经过了生命中的第二个本命年了。</p>

<p>…</p>

<p>“很不幸的是”，在座的有位兄弟也和我一样，是搞 IT 的。同学加上同行，自然话语就更加的多。当聊到现在的网络环境，他只是说了一句”娘个西撇“，其中的意思自然不言而喻。</p>

<p>我说你总比我好，自己有家小公司爱怎么折腾就怎么折腾。他又说了句，现在是某群人折腾我都来不及，我哪有时间折腾自己的事业。</p>

<p>按照他说的计划，他说占领国内市场你是<a href="http://www.5gme.com/space-111-do-blog-id-89680.html" title="http://www.5gme.com/space-111-do-blog-id-89680.html">抗不过国家队的</a>，还不如找个小国家重点发展那里的产业。那里钱多人傻，咱赚的还是美元。</p>

<p>想想也是，比如澳洲的总人口加起来差不多也就是个上海。开个玩笑的话，在国内拼死拼活占领了某个城市，换个环境就能占领整个国家了。</p>

<p>在这里我也只能祝福这位仁兄能够实现他的计划，不过我不是很希望下次的同学聚会他从国外赶回来。那这样就不是业界交流，而是国际间交流了…</p>

<p>现在的国内网络环境，好比透过毛玻璃看外面的世界，虽然光亮但仍然朦胧。外面的世界之所以看起来很光亮，只是因为室内的光线实在是太昏暗。</p>

<p>本来是篇摄影的文章，结果一下就废话那么多，实在是压抑得太久。和谐点，还是看照片吧</p>

<p><img src="http://pic.yupoo.com/feelinglucky/613448b6a185/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/613448b6a185/medium.jpg" title="http://pic.yupoo.com/feelinglucky/613448b6a185/medium.jpg" /></p>

<p><img src="http://pic.yupoo.com/feelinglucky/481228b6a2ee/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/481228b6a2ee/medium.jpg" title="http://pic.yupoo.com/feelinglucky/481228b6a2ee/medium.jpg" /></p>

<p><img src="http://pic.yupoo.com/feelinglucky/852008b6a253/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/852008b6a253/medium.jpg" title="http://pic.yupoo.com/feelinglucky/852008b6a253/medium.jpg" /></p>

<p><img src="http://pic.yupoo.com/feelinglucky/161408b6a209/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/161408b6a209/medium.jpg" title="http://pic.yupoo.com/feelinglucky/161408b6a209/medium.jpg" /></p>

<p>PS，还得重点感谢下 <a href="http://xuchao.org" title="http://xuchao.org">wiLdGoose 兄</a>，没有他相信我们的域名也不会那么容易得就迁移到国外。</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3008/</wfw:commentRss>
</item>
<item>
<title><![CDATA[将 iPod Touch 改造为“服务器”]]></title>
<link>http://www.gracecode.com/archives/3007/</link>
<pubDate>Mon, 11 Jan 2010 06:00:21 +0000</pubDate>
<category><![CDATA[Mac]]></category>
<description><![CDATA[http://pic.yupoo.com/feelinglucky/244708ae2eaa/medium.jpg

下面是 周末“闲着蛋疼”科技频道 为您报道

介于国内目前残酷的网络环境，...]]></description>
<guid>http://www.gracecode.com/archives/3007/</guid>
<slash:comments>25</slash:comments>
<comments>http://www.gracecode.com/archives/3007/#comments</comments>
<content:encoded><![CDATA[<p><img src="http://pic.yupoo.com/feelinglucky/244708ae2eaa/medium.jpg" alt="http://pic.yupoo.com/feelinglucky/244708ae2eaa/medium.jpg" title="http://pic.yupoo.com/feelinglucky/244708ae2eaa/medium.jpg" /></p>

<p>下面是 周末“闲着蛋疼”科技频道 为您报道</p>

<p>介于国内目前残酷的网络环境，秉承发挥科学发展观、实现可持续发展的态度，不给国家负担，经过两个小时的艰苦奋斗，终于研发出具有世界领先水平、国际不靠谱产权的无网线、可放在口袋里即可搬离 IDC 的微型服务器。</p>

<p><tt>-- Split--</tt></p>

<p>说正题，周末将我的 iPod <a href="http://www.felixbruns.de/iPod/firmware/" title="http://www.felixbruns.de/iPod/firmware/">版本升级</a>，破解以后里面没有数据，于是折腾装了个 <a href="http://www.lighttpd.net/" title="http://www.lighttpd.net/">lighttpd</a> 和 PHP，配合起来就可以跑个小型的 HTTP 服务器了。</p>

<p>如果你也有 iPod Touch 的话，也可以试试装个 HTTP 服务器玩玩。围观跳转链接：</p>

<p><a href="http://lab.gracecode.com/dwarf/" title="http://lab.gracecode.com/dwarf/">http://lab.gracecode.com/dwarf/</a></p>

<p>PS，如果上面的链接打不开，那可能我在用“服务器”听歌 :^D</p>

<p>当心软文：在这里重点赞下 <a href="http://typecho.org/" title="http://typecho.org/">Typecho</a>。Typecho + <a href="http://www.sqlite.org/" title="http://www.sqlite.org/">Sqlite</a> 的组合在 iPod 下跑得很流畅，对性能要求很高的朋友，您也可以尝试下。</p>

<p>简单的说下架设过程</p>

<ol>
    <li>iPod 当然需要破解掉</li>
    <li>在 iPod 上装 lighttpd 和 PHP（这些在 Cydia 上都有）</li>
    <li>让你的 iPod 一直开着（电源线是这台服务器唯一的物理连接线）</li>
    <li>配置家里的路由器的 DMZ 主机（如果觉得不放心，端口映射也可以）</li>
    <li>如果不想记 IP，那么找个动态域名服务商（可选）</li>
</ol>

<p>注意事项</p>

<ol>
    <li>iPod 的磁盘性能不好，lighttpd 记得关闭 access_log</li>
    <li>虽然没那么夸张，但 iPod 在跑大型程序中，会发烫</li>
</ol>

<p>想想看，这台两千不到的“服务器”能干啥 :^)</p>

<p>万一哪天有“相关人士”来机房拔网线，结果发现你的“服务器”没网线，他会不会泪奔？而且，迁移 IDC 从此不再是脏活累活，你可以装逼的将“服务器”放进口袋里，直接跳上公交车走人（途中还可以听歌）。</p>

<p>要跳墙的话更方便，直接邮寄个 iPod 到老外的家，让他插上电源即可…</p>

<p>……</p>

<p>呃，或许在不远的将来就有新闻说，“宫刑部”禁止在市场上流通 iPod 了…</p>

<p><tt>-- EOF --</tt></p>

]]></content:encoded>
<author><![CDATA[手气不错]]></author>
<dc:creator><![CDATA[手气不错]]></dc:creator>
<wfw:commentRss>http://www.gracecode.com/feed/archives/3007/</wfw:commentRss>
</item>
</channel>
</rss>
