<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet href='http://feed.feedsky.com/styles/temp01.xsl' type='text/xsl' ?><!--这是一个由Feedsy提供技术支持的Feed，为了提高读者阅读的体验，以及满足用户美化自己Feed的需要，我们设计了多种精美的Feed模板，提供给大家选择，所有最终呈现出来的样式，皆由用户自愿选择使用，未经许可，任何团体和个人，请不要擅自修改样式或者盗用，这是对于用户选择权的尊重。--><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://www.feedsky.com/namespace/feed" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link href="http://feed.feedsky.com/heikezhi" type="application/rss+xml" rel="self"></atom:link><fs:self_link href="http://feed.feedsky.com/heikezhi" type="application/rss+xml"></fs:self_link><lastBuildDate>Tue, 01 May 2012 09:24:50 GMT</lastBuildDate><title>黑客志</title><description>当你决定出发，最大的困难已不复存在</description><link>http://heikezhi.com</link><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>1</sy:updateFrequency><language>en</language><pubDate>Tue, 01 May 2012 09:24:50 GMT</pubDate><item><title>那些应该时刻牢记的事</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492398/6713895/1/item.html</link><content:encoded>&lt;p&gt;&lt;a href=&quot;http://bronnieware.com/&quot;&gt;Bronnie Ware&lt;/a&gt;是澳大利亚的一位做过多年临终护理的护士，她的病人都是那些不久于人世，并选择在家中度过他们最后岁月的人，这让她能够有机会和他们共度人生最后两三个月的这段特殊时光。&lt;/p&gt;
&lt;p&gt;几乎每个病人都会经历这样的感情波动，拒绝接受，恐惧，生气，懊悔，仍然拒绝，直到最终平静接受，无一例外，每个病人在临终之前都寻找到了属于他们的平静。&lt;/p&gt;
&lt;p&gt;但是当被问及是否有什么事情让他们感到后悔或者是想要从头来过一次时，她发现她得到的回答具有高度的重合，&lt;a href=&quot;http://www.inspirationandchai.com/Regrets-of-the-Dying.html&quot;&gt;下面是排在前5位的回答&lt;/a&gt;（注：基于这段经历，Bronnie Ware写了一本回忆录&quot;The Top Five Regrets of the Dying - A Life Transformed by the Dearly Departing&quot;，在书中讲述了这些临终遗言如何改变了她的生活)：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;我希望我能够有勇气按照自己想要的方式生活，而不是活在他人对我的期望中&lt;/li&gt;
&lt;li&gt;我希望我没有花这么多的时间玩命工作&lt;/li&gt;
&lt;li&gt;我希望我能够有勇气说出自己的真实感受&lt;/li&gt;
&lt;li&gt;我希望我能够多花一些时间同朋友们保持联系&lt;/li&gt;
&lt;li&gt;我希望我能够让自己过得更开心一些&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;这5句话可能你在别的地方都有看到过，如果它们是来自于成功学的教材或是某名人的语录，恐怕顶多也就是一份还凑合的心灵鸡汤，但是当他们来自于临终之人的遗言，它们的份量一下就重了许多，或许我们每个人都应该想一想，如果换做自己，在你离开这个世界之前，你会为这些事情感到后悔吗？&lt;/p&gt;
&lt;p&gt;然而人终归是懒惰的动物，不管多么激励人心的话语，恐怕都难以在脑海中停留太长的时间，对此，&lt;a href=&quot;http://paulgraham.com/todo.html&quot;&gt;Paul Graham的办法&lt;/a&gt;值得借鉴，他发现自己犯了其中的4个错误，因此他将这5句话做了简化，并将他们放在了他的TODO list的顶部，以此时刻提醒自己，下面是他简化后的版本：&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;不要忘记梦想，别太拼命工作，忠于自己，珍惜友情，保持开心&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;如果这5句话也对你有所触动，并且担心自己会犯同样的错误，那么你也应该将它们放到一个你每天都能看到的地方时刻提醒自己。&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;一个绝对新手的绘画和素描学习之旅&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F10%2F10%2Fjourney-of-an-absolute-rookie-paintings-and-sketches%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F05%2F01%2F5-things-you-should-always-remember%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/10/11/8941925.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;一个绝对新手的绘画和素描学习之旅&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;社会化中信息组织问题&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2012%2F03%2F18%2F%25E7%25A4%25BE%25E4%25BC%259A%25E5%258C%2596%25E4%25B8%25AD%25E4%25BF%25A1%25E6%2581%25AF%25E7%25BB%2584%25E7%25BB%2587%25E9%2597%25AE%25E9%25A2%2598%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F05%2F01%2F5-things-you-should-always-remember%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2012/03/19/17581483.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;社会化中信息组织问题&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;Chess@home: 打造最厉害的国际象棋AI&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F09%2F08%2Fchessathome-building-largest-chess-ai%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F05%2F01%2F5-things-you-should-always-remember%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/09/09/29490732.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;Chess@home: 打造最厉害的国际象棋AI&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;HTML5少有人知的酷特性&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F20%2Fhtml5-whats-new%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F05%2F01%2F5-things-you-should-always-remember%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/07/23/18613388.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;HTML5少有人知的酷特性&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492398/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492398/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2012/05/01/5-things-you-should-always-remember/feed/</wfw:commentRss><slash:comments>0</slash:comments><description>&lt;a href=&quot;http://bronnieware.com/&quot;&gt;Bronnie Ware&lt;/a&gt;是澳大利亚的一位做过多年临终护理的护士，她的病人都是那些不久于人世，并选择在家中度过他们最后岁月的人，这让她能够有机会和他们共度人生最后两三个月的这段特殊时光。

几乎每个病人都会经历这样的感情波动，拒绝接受，恐惧，生气，懊悔，仍然拒绝，直到最终平静接受，无一例外，每个病人在临终之前都寻找到了属于他们的平静。

但是当被问及是否有什么事情让他们感到后悔或者是想要从头来过一次时，她发现她得到的回答具有高度的重合，&lt;a href=&quot;http://www.inspirationandchai.com/Regrets-of-the-Dying.html&quot;&gt;下面是排在前5位的回答&lt;/a&gt;（注：基于这段经历，Bronnie Ware写了一本回忆录&quot;The Top Five Regrets of the Dying - A Life Transformed by the Dearly Departing&quot;，在书中讲述了这些临终遗言如何改变了她的生活)：

&lt;ol&gt;
	&lt;li&gt;我希望我能够有勇气按照自己想要的方式生活，而不是活在他人对我的期望中&lt;/li&gt;
	&lt;li&gt;我希望我没有花这么多的时间玩命工作&lt;/li&gt;
	&lt;li&gt;我希望我能够有勇气说出自己的真实感受&lt;/li&gt;
	&lt;li&gt;我希望我能够多花一些时间同朋友们保持联系&lt;/li&gt;
	&lt;li&gt;我希望我能够让自己过得更开心一些&lt;/li&gt;
&lt;/ol&gt;

这5句话可能你在别的地方都有看到过，如果它们是来自于成功学的教材或是某名人的语录，恐怕顶多也就是一份还凑合的心灵鸡汤，但是当他们来自于临终之人的遗言，它们的份量一下就重了许多，或许我们每个人都应该想一想，如果换做自己，在你离开这个世界之前，你会为这些事情感到后悔吗？

然而人终归是懒惰的动物，不管多么激励人心的话语，恐怕都难以在脑海中停留太长的时间，对此，&lt;a href=&quot;http://paulgraham.com/todo.html&quot;&gt;Paul Graham的办法&lt;/a&gt;值得借鉴，他发现自己犯了其中的4个错误，因此他将这5句话做了简化，并将他们放在了他的TODO list的顶部，以此时刻提醒自己，下面是他简化后的版本：

&lt;blockquote&gt;不要忘记梦想，别太拼命工作，忠于自己，珍惜友情，保持开心&lt;/blockquote&gt;

如果这5句话也对你有所触动，并且担心自己会犯同样的错误，那么你也应该将它们放到一个你每天都能看到的地方时刻提醒自己。&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492398/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492398/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Tue, 01 May 2012 17:24:50 +0800</pubDate><author>yuanyi</author><comments>http://heikezhi.com/2012/05/01/5-things-you-should-always-remember/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=2564</guid><dc:creator>yuanyi</dc:creator><fs:srclink>http://heikezhi.com/2012/05/01/5-things-you-should-always-remember/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492398/6713895</fs:itemid></item><item><title>社会化中信息组织问题</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492399/6713895/1/item.html</link><content:encoded>&lt;h1&gt;&lt;a href=&quot;http://www.tributemedia.com/blog/kelsey-bates/enable-social-media-meet-your-customer%E2%80%99s-needs&quot;&gt;&lt;img style=&quot;font-size: 13px;font-weight: normal&quot; src=&quot;http://www.tributemedia.com/sites/tributemedia.com/files/imce/What%20is%20Social%20Media%20to%20you.jpg&quot; alt=&quot;Talk too much&quot; width=&quot;578&quot; height=&quot;576&quot; /&gt;&lt;/a&gt;&lt;/h1&gt;
&lt;h2&gt;问题&lt;/h2&gt;
&lt;p&gt;在社交网站的兴起，信息的组织也与以往有很多不同，也就多了许多新问题，最突出的问题就是：&lt;strong&gt;信息分散&lt;/strong&gt;。&lt;/p&gt;
&lt;p&gt;人们往往有多个账户，Facebook、Google+、Twitter、Tumblr还有X博，你怎么管理这些账户？一般都是用FaWave这样&lt;em&gt;一对多&lt;/em&gt;的工具吧？但是，1条信息，被用户发到Facebook、Google+、Twitter上后，就变成了3条信息，假设每个网站用户都有30个粉丝，每个粉丝给了用户回复。于是，用户一共收到了90条回复，这90条回复都针对同一条信息，但却分散在了3个网站上。这就意味着：如果用户想看看他人对这条信息的看法，就需要上3个网站、登陆3次、看3此评论。&lt;/p&gt;
&lt;p&gt;看出来了吗？&lt;strong&gt;信息的组织是分散的。&lt;/strong&gt;在其他国家，这种情况还好一点，因为他们每个部分都有像Facebook、Twitter、Tumblr一样的龙头。但，在天朝，光微博就有X博、疼殉、163、sohu、饭否、做啥……而且每个人都有不同喜好，情况麻烦多了。&lt;/p&gt;
&lt;h2&gt;解决之道&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;多合一&lt;/strong&gt;&lt;br /&gt;
我们可以利用像FaWave这样的&lt;em&gt;多合一&lt;/em&gt;工具将信息&lt;em&gt;聚合&lt;/em&gt;。但，&lt;strong&gt;这样的工具只是在信息传递的最末端——接受信息时，才将信息集中。&lt;/strong&gt;这样，虽然能使信息集中体现，却只是治标不治本。&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;社会化评论&lt;/strong&gt;&lt;br /&gt;
像Disqus这样的社会化评论可以&lt;em&gt;关联账号&lt;/em&gt;的方式将针对某篇文章的评论汇总在一起，&lt;strong&gt;从根本上解决问题。&lt;/strong&gt;但这有赖于用户的配合，比如个别用户不关联账号，在原网站评论后，再上Twitter上发一条评论……另外，这里是天朝，据我所知，目前功能类似Disqus的网站已经有评论啦、有言等。有理由相信，过不了多久，新浪、疼殉、度娘都会强势登陆这片土地的。到时候，&lt;strong&gt;这样的服务就会丧失本来的意义。&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;小结&lt;/h2&gt;
&lt;p&gt;社会化暴露出最大的问题就是信息分散。目前，此问题还没有特别好的解决办法。更何况在国情特殊的天朝，&lt;strong&gt;只有加强对知识产权的保护，尊重他人的智力成果，才是最根本的解决方法&lt;/strong&gt;。&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
  
&lt;div class=&quot;wp_license&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-nc-sa/3.0/&quot;&gt;&lt;img src=&quot;http://i.creativecommons.org/l/by-nc-sa/3.0//88x31.png&quot; alt=&quot;Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported&quot; class=&quot;alignleft&quot; style=&quot;margin-top:4px;&quot; /&gt;
&lt;/a&gt;此作品采用 &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-nc-sa/3.0/&quot;&gt;Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;你在解决错误的问题&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F06%2F01%2Fyou-are-solving-the-wrong-problem%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F03%2F18%2F%25E7%25A4%25BE%25E4%25BC%259A%25E5%258C%2596%25E4%25B8%25AD%25E4%25BF%25A1%25E6%2581%25AF%25E7%25BB%2584%25E7%25BB%2587%25E9%2597%25AE%25E9%25A2%2598%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/02/10605827.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;你在解决错误的问题&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;GNU/Linux中有多少GNU的代码？&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F06%2F02%2Fhow-much-gnu-in-gnu-linux%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F03%2F18%2F%25E7%25A4%25BE%25E4%25BC%259A%25E5%258C%2596%25E4%25B8%25AD%25E4%25BF%25A1%25E6%2581%25AF%25E7%25BB%2584%25E7%25BB%2587%25E9%2597%25AE%25E9%25A2%2598%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/03/10756654.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;GNU/Linux中有多少GNU的代码？&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;CoffeeTable: 在浏览器中执行CoffeeScript&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F08%2F08%2Fcoffeetable-web-console-for-coffeescript%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F03%2F18%2F%25E7%25A4%25BE%25E4%25BC%259A%25E5%258C%2596%25E4%25B8%25AD%25E4%25BF%25A1%25E6%2581%25AF%25E7%25BB%2584%25E7%25BB%2587%25E9%2597%25AE%25E9%25A2%2598%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/08/09/21783832.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;CoffeeTable: 在浏览器中执行CoffeeScript&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;移动App，原生还是Web？这是个问题&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F05%2F08%2Fwhats-the-future-native-apps-or-mobile-web-apps%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F03%2F18%2F%25E7%25A4%25BE%25E4%25BC%259A%25E5%258C%2596%25E4%25B8%25AD%25E4%25BF%25A1%25E6%2581%25AF%25E7%25BB%2584%25E7%25BB%2587%25E9%2597%25AE%25E9%25A2%2598%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/05/09/8025745.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;移动App，原生还是Web？这是个问题&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492399/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492399/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2012/03/18/%e7%a4%be%e4%bc%9a%e5%8c%96%e4%b8%ad%e4%bf%a1%e6%81%af%e7%bb%84%e7%bb%87%e9%97%ae%e9%a2%98/feed/</wfw:commentRss><slash:comments>4</slash:comments><description>&lt;a href=&quot;http://heikezhi.com/2012/03/18/%e7%a4%be%e4%bc%9a%e5%8c%96%e4%b8%ad%e4%bf%a1%e6%81%af%e7%bb%84%e7%bb%87%e9%97%ae%e9%a2%98/&quot;&gt;&lt;img align=&quot;left&quot; hspace=&quot;5&quot; width=&quot;150&quot; src=&quot;http://www.tributemedia.com/sites/tributemedia.com/files/imce/What%20is%20Social%20Media%20to%20you.jpg&quot; class=&quot;alignleft wp-post-image tfe&quot; alt=&quot;Talk too much&quot; title=&quot;&quot; /&gt;&lt;/a&gt;&lt;h1&gt;&lt;a href=&quot;http://www.tributemedia.com/blog/kelsey-bates/enable-social-media-meet-your-customer%E2%80%99s-needs&quot;&gt;&lt;img style=&quot;font-size: 13px;font-weight: normal&quot; src=&quot;http://www.tributemedia.com/sites/tributemedia.com/files/imce/What%20is%20Social%20Media%20to%20you.jpg&quot; alt=&quot;Talk too much&quot; width=&quot;578&quot; height=&quot;576&quot; /&gt;&lt;/a&gt;&lt;/h1&gt;
&lt;h2&gt;问题&lt;/h2&gt;
在社交网站的兴起，信息的组织也与以往有很多不同，也就多了许多新问题，最突出的问题就是：&lt;strong&gt;信息分散&lt;/strong&gt;。

人们往往有多个账户，Facebook、Google+、Twitter、Tumblr还有X博，你怎么管理这些账户？一般都是用FaWave这样&lt;em&gt;一对多&lt;/em&gt;的工具吧？但是，1条信息，被用户发到Facebook、Google+、Twitter上后，就变成了3条信息，假设每个网站用户都有30个粉丝，每个粉丝给了用户回复。于是，用户一共收到了90条回复，这90条回复都针对同一条信息，但却分散在了3个网站上。这就意味着：如果用户想看看他人对这条信息的看法，就需要上3个网站、登陆3次、看3此评论。

看出来了吗？&lt;strong&gt;信息的组织是分散的。&lt;/strong&gt;在其他国家，这种情况还好一点，因为他们每个部分都有像Facebook、Twitter、Tumblr一样的龙头。但，在天朝，光微博就有X博、疼殉、163、sohu、饭否、做啥……而且每个人都有不同喜好，情况麻烦多了。
&lt;h2&gt;解决之道&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;多合一&lt;/strong&gt;
我们可以利用像FaWave这样的&lt;em&gt;多合一&lt;/em&gt;工具将信息&lt;em&gt;聚合&lt;/em&gt;。但，&lt;strong&gt;这样的工具只是在信息传递的最末端——接受信息时，才将信息集中。&lt;/strong&gt;这样，虽然能使信息集中体现，却只是治标不治本。&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;社会化评论&lt;/strong&gt;
像Disqus这样的社会化评论可以&lt;em&gt;关联账号&lt;/em&gt;的方式将针对某篇文章的评论汇总在一起，&lt;strong&gt;从根本上解决问题。&lt;/strong&gt;但这有赖于用户的配合，比如个别用户不关联账号，在原网站评论后，再上Twitter上发一条评论……另外，这里是天朝，据我所知，目前功能类似Disqus的网站已经有评论啦、有言等。有理由相信，过不了多久，新浪、疼殉、度娘都会强势登陆这片土地的。到时候，&lt;strong&gt;这样的服务就会丧失本来的意义。&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;小结&lt;/h2&gt;
社会化暴露出最大的问题就是信息分散。目前，此问题还没有特别好的解决办法。更何况在国情特殊的天朝，&lt;strong&gt;只有加强对知识产权的保护，尊重他人的智力成果，才是最根本的解决方法&lt;/strong&gt;。&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492399/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492399/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Mon, 19 Mar 2012 12:19:06 +0800</pubDate><author>fenprace</author><comments>http://heikezhi.com/2012/03/18/%e7%a4%be%e4%bc%9a%e5%8c%96%e4%b8%ad%e4%bf%a1%e6%81%af%e7%bb%84%e7%bb%87%e9%97%ae%e9%a2%98/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1926</guid><dc:creator>fenprace</dc:creator><fs:srclink>http://heikezhi.com/2012/03/18/%e7%a4%be%e4%bc%9a%e5%8c%96%e4%b8%ad%e4%bf%a1%e6%81%af%e7%bb%84%e7%bb%87%e9%97%ae%e9%a2%98/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492399/6713895</fs:itemid></item><item><title>你好Rack!</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492400/6713895/1/item.html</link><content:encoded>&lt;p&gt;差不多每个礼拜Ruby社区都会涌现一些新框架，但其中Rack没有得到其应得的重视。况且，下一个Rails稳定发布版本2.2(译者按:这篇文章发布于大约3年前)将充分利用Rack提供更好的对外接口。&lt;br /&gt;
Rack脱胎于pythons中的wsgi，并迅速成为ruby社区中web应用服务器的无冕之王,这皆得益于它的简单和严谨。在读这篇帖子前，我建议你先看一看Rack之父Christian Neukirchen对于Rack的介绍。&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Rack是什么?&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Rack为Ruby web应用提供一个最小化、模块化并可配置的接口。通过包装HTTP请求并尽可能以最简单的方式予以响应,Rack抽象了web服务器、web框架及中间件的API,并统一到一个方法--call.&lt;br /&gt;
--Rack API文档&lt;br /&gt;
准确的说，你可以把Rack一分为二:&lt;br /&gt;
Rack规范&lt;br /&gt;
Rack规范规定了Rack应用和web服务器究竟是如何通信的:&lt;br /&gt;
Rack应用程序是一个能够相应web请求的Ruby对象(没错!不是一个类)。它只接受一个参数，环境变量返回一个含有三个元素的数组:状态、消息报头和响应正文。&lt;br /&gt;
--Rack规范&lt;br /&gt;
Rack规范可以此一言以蔽之，要知其详尽请君自便。&lt;/p&gt;
&lt;p&gt;Rack Gem&lt;br /&gt;
Rack gem 是一个实用程序和实现类的集合，用来为开发Rack应用开发者减负。它包含了请求、响应、cookies和session的基本实现，还有大量好用的中间件。借用巴黎欧莱雅的广告语，Rack Gem 你值得拥有:&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ sudo gem install rack&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;综上所 述&lt;br /&gt;
Rack是可以让你创造ruby(web)框架的框架。&lt;br /&gt;
Rack提供了不同web服务器与你的框(或应用)间的接口。这就使你的框架(或应用)易于兼容各色支持Rack的web服务器:Phusion Passenger、 Litespeed、 Mongrel、 Thin、 Ebb、 Webrick等等。&lt;/p&gt;
&lt;p&gt;Rack开门见山。得到请求, 响应, cookies, 请求参数和sessions如探囊取物。&lt;br /&gt;
它使得应用程序跨平台成为可能，前提是没有类名冲突。Rails和sinatra的集成就是一个好例子。&lt;/p&gt;
&lt;p&gt;赞美你中间件!多亏了它Rails的前后置过滤器才能在(rack支持的)其他框架里发挥余热。譬如,你可以在Rails、Sinatra和自创的Rack应用中使用一模一样的Anti-spamming中间件。&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;例子&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;让我们尽可能从一个最简单的rack应用下手，用mongrel(译者:我不知道现在还有没有&quot;落水杂种狗&quot;的市场了，它在08年的时候救过我)。&lt;/p&gt;
&lt;pre&gt;require 'rubygems'
require 'rack'

class HelloWorld
  def call(env)
    [200, {&quot;Content-Type&quot; =&amp;gt; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]
  end
end

Rack::Handler::Mongrel.run HelloWorld.new, :Port =&amp;gt; 9292&lt;/pre&gt;
&lt;p&gt;以上代码传一个HelloWorld对象给mongrel的rack句柄，并且在9292端口上启动服务器。&lt;/p&gt;
&lt;p&gt;HelloWorld对象遵从Rack规范，就像这样:&lt;/p&gt;
&lt;p&gt;以call()作为响应，传一个参数 环境变量&lt;br /&gt;
call()返回一个数组形如:[http_status_code,response_headers_hash,body]&lt;/p&gt;
&lt;p&gt;这就是一切了!如果你运行这个脚本并浏览http://localhost:9292，会赫然见到本文标题&quot;Hello Rack!&quot;。&lt;/p&gt;
&lt;p&gt;等一下，ruby的proc对象不是正好可以调用(responds to)call()方法吗?何故不用proc实例呢?恩，没道理不用:&lt;/p&gt;
&lt;pre&gt;  
require 'rubygems'
require 'rack'

Rack::Handler::Mongrel.run proc {|env| [200, {&quot;Content-Type&quot; =&amp;gt; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]}, :Port =&amp;gt; 9292&lt;/pre&gt;
&lt;p&gt;另一种常见的模式是用method(:something)方法，可以返回一个方法类实例(Method):&lt;/p&gt;
&lt;pre&gt;  
require 'rubygems'
require 'rack'

def application(env)
  [200, {&quot;Content-Type&quot; =&amp;gt; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]
end

Rack::Handler::Mongrel.run method(:application), :Port =&amp;gt; 9292&lt;/pre&gt;
&lt;h2&gt;&lt;strong&gt;Rack起来&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
就像我先前说过的，rack gem包含了一堆有益身心的好东东(对rack应用开发者来说)。rackup就是其中之一。在前面的例子中，我已经直接用过mongrel句柄 Rack::Handler::Mongrel了,硬编码了端口号。&lt;br /&gt;
用rackup，这些事儿都变得可配置了!但是用rackup，你就要提供给它一个rackup配置文件。我们下边这个例子中的配置文件看上去就像这样:&lt;/p&gt;
&lt;pre&gt;  
# config.ru
run Proc.new {|env| [200, {&quot;Content-Type&quot; =&amp;gt; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]}&lt;/pre&gt;
&lt;p&gt;就这么一行。一般来说，rackup配置文件的扩展名应该用.ru。给它一个RackObject就齐活儿了:&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ rackup config.ru&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;默认情况下，rackup将在9292端口上开启服务器。但是你可以通过选项-p修改端口号。更多帮助，看这该死的简介(RTFM):&lt;/p&gt;
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ rackup --help&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;本文译自:&lt;a title=&quot;Ruby on Rack #1 - Hello Rack!&quot; href=&quot;http://m.onkey.org/ruby-on-rack-1-hello-rack&quot; target=&quot;_blank&quot;&gt;Ruby on Rack #1 - Hello Rack!&lt;/a&gt; 原作者: Pratik Naik 译者：wade xing&lt;/pre&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
  
&lt;div class=&quot;wp_license&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;&lt;img src=&quot;http://i.creativecommons.org/l/by/3.0//88x31.png&quot; alt=&quot;Creative Commons Attribution 3.0 Unported&quot; class=&quot;alignleft&quot; style=&quot;margin-top:4px;&quot; /&gt;
&lt;/a&gt;此作品采用 &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;Creative Commons Attribution 3.0 Unported&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;关于Ruby 2.0: 我们的计划&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F12%2Fwhat-we-want-to-accomplish-in-the-near-future%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F14%2F%25E4%25BD%25A0%25E5%25A5%25BDrack%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;关于Ruby 2.0: 我们的计划&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;GNU/Linux中有多少GNU的代码？&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F06%2F02%2Fgnulinux%25E4%25B8%25AD%25E6%259C%2589%25E5%25A4%259A%25E5%25B0%2591gnu%25E7%259A%2584%25E4%25BB%25A3%25E7%25A0%2581%25EF%25BC%259F%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F14%2F%25E4%25BD%25A0%25E5%25A5%25BDrack%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/03/10756654.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;GNU/Linux中有多少GNU的代码？&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;Chess@home: 打造最厉害的国际象棋AI&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F09%2F08%2Fchessathome-building-largest-chess-ai%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F14%2F%25E4%25BD%25A0%25E5%25A5%25BDrack%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/09/09/29490732.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;Chess@home: 打造最厉害的国际象棋AI&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;使用Wolfram Alpha证明1=0&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F22%2Fusing-wolfram-alpha-to-prove-10%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F14%2F%25E4%25BD%25A0%25E5%25A5%25BDrack%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/04/23/6278923.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;使用Wolfram Alpha证明1=0&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492400/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492400/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2012/02/14/%e4%bd%a0%e5%a5%bdrack/feed/</wfw:commentRss><slash:comments>0</slash:comments><description>差不多每个礼拜Ruby社区都会涌现一些新框架，但其中Rack没有得到其应得的重视。况且，下一个Rails稳定发布版本2.2(译者按:这篇文章发布于大约3年前)将充分利用Rack提供更好的对外接口。
Rack脱胎于pythons中的wsgi，并迅速成为ruby社区中web应用服务器的无冕之王,这皆得益于它的简单和严谨。在读这篇帖子前，我建议你先看一看Rack之父Christian Neukirchen对于Rack的介绍。
&lt;strong&gt;&lt;/strong&gt;
&lt;h2&gt;&lt;strong&gt;Rack是什么?&lt;/strong&gt;&lt;/h2&gt;
Rack为Ruby web应用提供一个最小化、模块化并可配置的接口。通过包装HTTP请求并尽可能以最简单的方式予以响应,Rack抽象了web服务器、web框架及中间件的API,并统一到一个方法--call.
--Rack API文档
准确的说，你可以把Rack一分为二:
Rack规范
Rack规范规定了Rack应用和web服务器究竟是如何通信的:
Rack应用程序是一个能够相应web请求的Ruby对象(没错!不是一个类)。它只接受一个参数，环境变量返回一个含有三个元素的数组:状态、消息报头和响应正文。
--Rack规范
Rack规范可以此一言以蔽之，要知其详尽请君自便。

Rack Gem
Rack gem 是一个实用程序和实现类的集合，用来为开发Rack应用开发者减负。它包含了请求、响应、cookies和session的基本实现，还有大量好用的中间件。借用巴黎欧莱雅的广告语，Rack Gem 你值得拥有:
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ sudo gem install rack&lt;/span&gt;&lt;/pre&gt;
综上所 述
Rack是可以让你创造ruby(web)框架的框架。
Rack提供了不同web服务器与你的框(或应用)间的接口。这就使你的框架(或应用)易于兼容各色支持Rack的web服务器:Phusion Passenger、 Litespeed、 Mongrel、 Thin、 Ebb、 Webrick等等。

Rack开门见山。得到请求, 响应, cookies, 请求参数和sessions如探囊取物。
它使得应用程序跨平台成为可能，前提是没有类名冲突。Rails和sinatra的集成就是一个好例子。

赞美你中间件!多亏了它Rails的前后置过滤器才能在(rack支持的)其他框架里发挥余热。譬如,你可以在Rails、Sinatra和自创的Rack应用中使用一模一样的Anti-spamming中间件。
&lt;h2&gt;&lt;strong&gt;例子&lt;/strong&gt;&lt;/h2&gt;
让我们尽可能从一个最简单的rack应用下手，用mongrel(译者:我不知道现在还有没有&quot;落水杂种狗&quot;的市场了，它在08年的时候救过我)。
&lt;pre&gt;require 'rubygems'
require 'rack'

class HelloWorld
  def call(env)
    [200, {&quot;Content-Type&quot; =&amp;#62; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]
  end
end

Rack::Handler::Mongrel.run HelloWorld.new, :Port =&amp;#62; 9292&lt;/pre&gt;
以上代码传一个HelloWorld对象给mongrel的rack句柄，并且在9292端口上启动服务器。

HelloWorld对象遵从Rack规范，就像这样:

以call()作为响应，传一个参数 环境变量
call()返回一个数组形如:[http_status_code,response_headers_hash,body]

这就是一切了!如果你运行这个脚本并浏览http://localhost:9292，会赫然见到本文标题&quot;Hello Rack!&quot;。

等一下，ruby的proc对象不是正好可以调用(responds to)call()方法吗?何故不用proc实例呢?恩，没道理不用:
&lt;pre&gt;  
require 'rubygems'
require 'rack'

Rack::Handler::Mongrel.run proc {&amp;#124;env&amp;#124; [200, {&quot;Content-Type&quot; =&amp;#62; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]}, :Port =&amp;#62; 9292&lt;/pre&gt;
另一种常见的模式是用method(:something)方法，可以返回一个方法类实例(Method):
&lt;pre&gt;  
require 'rubygems'
require 'rack'

def application(env)
  [200, {&quot;Content-Type&quot; =&amp;#62; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]
end

Rack::Handler::Mongrel.run method(:application), :Port =&amp;#62; 9292&lt;/pre&gt;
&lt;h2&gt;&lt;strong&gt;Rack起来&lt;/strong&gt;&lt;/h2&gt;
&lt;strong&gt;&lt;/strong&gt;
就像我先前说过的，rack gem包含了一堆有益身心的好东东(对rack应用开发者来说)。rackup就是其中之一。在前面的例子中，我已经直接用过mongrel句柄 Rack::Handler::Mongrel了,硬编码了端口号。
用rackup，这些事儿都变得可配置了!但是用rackup，你就要提供给它一个rackup配置文件。我们下边这个例子中的配置文件看上去就像这样:
&lt;pre&gt;  
# config.ru
run Proc.new {&amp;#124;env&amp;#124; [200, {&quot;Content-Type&quot; =&amp;#62; &quot;text/html&quot;}, &quot;Hello Rack!&quot;]}&lt;/pre&gt;
就这么一行。一般来说，rackup配置文件的扩展名应该用.ru。给它一个RackObject就齐活儿了:
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ rackup config.ru&lt;/span&gt;&lt;/pre&gt;
默认情况下，rackup将在9292端口上开启服务器。但是你可以通过选项-p修改端口号。更多帮助，看这该死的简介(RTFM):
&lt;pre&gt;&lt;span style=&quot;color: #ff9900&quot;&gt;$ rackup --help&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;本文译自:&lt;a title=&quot;Ruby on Rack #1 - Hello Rack!&quot; href=&quot;http://m.onkey.org/ruby-on-rack-1-hello-rack&quot; target=&quot;_blank&quot;&gt;Ruby on Rack #1 - Hello Rack!&lt;/a&gt; 原作者: Pratik Naik 译者：wade xing&lt;/pre&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492400/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492400/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>rack</category><category>编程</category><category>ruby</category><pubDate>Wed, 15 Feb 2012 14:55:57 +0800</pubDate><author>wade xing</author><comments>http://heikezhi.com/2012/02/14/%e4%bd%a0%e5%a5%bdrack/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1960</guid><dc:creator>wade xing</dc:creator><fs:srclink>http://heikezhi.com/2012/02/14/%e4%bd%a0%e5%a5%bdrack/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492400/6713895</fs:itemid></item><item><title>我厌烦的5种创业想法</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492401/6713895/1/item.html</link><content:encoded>&lt;p&gt;我听到许多人新的创业想法，尽管这很不错，然而我开始反复听到一些相同的创意。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;发现你周围的人的应用&lt;/strong&gt; - 没人想找到他们周围的人并和他们见面。相信我。这很奇怪，并且早就有这样的应用了。我不知道为什么人们会认为这是一个需求。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;优惠券/每日交易&lt;/strong&gt; - 如果你现在正有这个想法，相信我，成千上万的人都有相同想法，并且正在实现它。这个市场已经饱和了，应该用你的时间做更有意义的事。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;线上约会网站&lt;/strong&gt; - 除非你的应用基于现有大型约会网站，否则你几乎不可能进入这个市场。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;校园书籍交换&lt;/strong&gt; - 我们基于一定目的使用Craiglist（注：一个网上大型免费分类广告网站），而且它很有效。是的，我知道书很贵，人们很难把钱换回来，但这始终是一个问题。一个书籍交换网站也不能解决这个问题。并且市场已经饱和了，所以应当避免这种情况。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;生成应用的应用&lt;/strong&gt; - 这种创意大多来自技术人员，但基于一些原因我很难容忍这种类型的解决方案。是的，这种应用对于不懂技术的人很有用，但我不确定最终它究竟能创造多大价值。&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;----------------------&lt;/p&gt;
&lt;p&gt;本文译自 &lt;a href=&quot;http://robbieabed.com/5-startup-ideas-that-im-sick-of-hearing-about/&quot;&gt;5 startup idea’s that I’m sick of hearing about&lt;/a&gt; ，Hacker News的评论在&lt;a href=&quot;https://news.ycombinator.com/item?id=3536472&quot;&gt;这里&lt;/a&gt;。译者：&lt;a href=&quot;http://www.creatist.cn/&quot;&gt;Slacken&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td &gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
            &lt;tr&gt;
                &lt;td style=&quot;margin: 0 !important; padding: 0 !important; line-height: 20px !important;&quot;&gt;
                    &lt;img border=&quot;0&quot; src=&quot;http://static.wumii.com/images/widget/widget_solidPoint.gif&quot;&gt;
                    &lt;a target=&quot;_blank&quot; style=&quot;text-decoration: none !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F03%2F22%2Flaunchrock-launch-startup-by-yourself%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F02%2F5-startup-ideas-that-im-sick-of-hearing-about%2F&quot;&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;line-height: 1.65em; font-size: 12px !important;&quot;&gt;LaunchRock: 自己发布你的创业项目&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;margin: 0 !important; padding: 0 !important; line-height: 20px !important;&quot;&gt;
                    &lt;img border=&quot;0&quot; src=&quot;http://static.wumii.com/images/widget/widget_solidPoint.gif&quot;&gt;
                    &lt;a target=&quot;_blank&quot; style=&quot;text-decoration: none !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F03%2F29%2Fhow-to-evaluate-a-non-technical-co-founder%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F02%2F5-startup-ideas-that-im-sick-of-hearing-about%2F&quot;&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;line-height: 1.65em; font-size: 12px !important;&quot;&gt;如何评估非技术的创业伙伴&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;margin: 0 !important; padding: 0 !important; line-height: 20px !important;&quot;&gt;
                    &lt;img border=&quot;0&quot; src=&quot;http://static.wumii.com/images/widget/widget_solidPoint.gif&quot;&gt;
                    &lt;a target=&quot;_blank&quot; style=&quot;text-decoration: none !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F14%2Fwhy-you-shouldnt-keep-your-startup-idea-secret%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F02%2F5-startup-ideas-that-im-sick-of-hearing-about%2F&quot;&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;line-height: 1.65em; font-size: 12px !important;&quot;&gt;为什么不应该对你的创业想法保密？&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td style=&quot;margin: 0 !important; padding: 0 !important; line-height: 20px !important;&quot;&gt;
                    &lt;img border=&quot;0&quot; src=&quot;http://static.wumii.com/images/widget/widget_solidPoint.gif&quot;&gt;
                    &lt;a target=&quot;_blank&quot; style=&quot;text-decoration: none !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F17%2F%25E5%2588%259B%25E4%25B8%259A%25E5%2585%25AC%25E5%258F%25B8%25E5%258A%259E%25E5%2585%25AC%25E5%25AE%25A4%25E6%2597%25B6%25E9%2597%25B4%25EF%25BC%259F%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2012%2F02%2F02%2F5-startup-ideas-that-im-sick-of-hearing-about%2F&quot;&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;line-height: 1.65em; font-size: 12px !important;&quot;&gt;创业公司办公室时间？&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td  align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492401/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492401/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2012/02/02/5-startup-ideas-that-im-sick-of-hearing-about/feed/</wfw:commentRss><slash:comments>0</slash:comments><description>我听到许多人新的创业想法，尽管这很不错，然而我开始反复听到一些相同的创意。
&lt;ul&gt;
	&lt;li&gt;&lt;p&gt;&lt;strong&gt;发现你周围的人的应用&lt;/strong&gt; - 没人想找到他们周围的人并和他们见面。相信我。这很奇怪，并且早就有这样的应用了。我不知道为什么人们会认为这是一个需求。&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;p&gt;&lt;strong&gt;优惠券/每日交易&lt;/strong&gt; - 如果你现在正有这个想法，相信我，成千上万的人都有相同想法，并且正在实现它。这个市场已经饱和了，应该用你的时间做更有意义的事。&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;p&gt;&lt;strong&gt;线上约会网站&lt;/strong&gt; - 除非你的应用基于现有大型约会网站，否则你几乎不可能进入这个市场。&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;p&gt;&lt;strong&gt;校园书籍交换&lt;/strong&gt; - 我们基于一定目的使用Craiglist（注：一个网上大型免费分类广告网站），而且它很有效。是的，我知道书很贵，人们很难把钱换回来，但这始终是一个问题。一个书籍交换网站也不能解决这个问题。并且市场已经饱和了，所以应当避免这种情况。&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;p&gt;&lt;strong&gt;生成应用的应用&lt;/strong&gt; - 这种创意大多来自技术人员，但基于一些原因我很难容忍这种类型的解决方案。是的，这种应用对于不懂技术的人很有用，但我不确定最终它究竟能创造多大价值。&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
----------------------

本文译自 &lt;a href=&quot;http://robbieabed.com/5-startup-ideas-that-im-sick-of-hearing-about/&quot;&gt;5 startup idea’s that I’m sick of hearing about&lt;/a&gt; ，Hacker News的评论在&lt;a href=&quot;https://news.ycombinator.com/item?id=3536472&quot;&gt;这里&lt;/a&gt;。译者：&lt;a href=&quot;http://www.creatist.cn/&quot;&gt;Slacken&lt;/a&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492401/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492401/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>创业</category><pubDate>Thu, 02 Feb 2012 17:14:04 +0800</pubDate><author>Slacken</author><comments>http://heikezhi.com/2012/02/02/5-startup-ideas-that-im-sick-of-hearing-about/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1943</guid><dc:creator>Slacken</dc:creator><fs:srclink>http://heikezhi.com/2012/02/02/5-startup-ideas-that-im-sick-of-hearing-about/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492401/6713895</fs:itemid></item><item><title>脏代码技巧 精准补丁(外二则)</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492402/6713895/1/item.html</link><content:encoded>&lt;h1&gt;&lt;strong&gt;精准补丁&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt;有个老笑话是这么说的：&lt;/p&gt;
&lt;p&gt;病人：“医生，我一这样就难受。”&lt;br /&gt;
医生：“那就别那样。”&lt;/p&gt;
&lt;p&gt;有趣，但把它用在自己的项目中也管用吗？这让我想起了自己从PC移植一款3D第三人称射击游戏到初代PS上时所经受的痛苦。&lt;/p&gt;
&lt;p&gt;现在，PS1不支持浮点数，所以我们要重新编译PC代码，把所有浮点数都换成顶点数。这确实效果不错，除了碰撞检测。&lt;/p&gt;
&lt;p&gt;我们的关卡的模型在PC版里确实运作的很好，但当浮点型转为定点型以后，微小的数值误差使各种拼接缝线、T型拼接处和其他问题层出不穷。这个问题的表现之一是主人公（叫做“Damp”）会轻易掉进那些微小的缝隙中，落入关卡深处。&lt;/p&gt;
&lt;p&gt;我们补上了我们发现的缝隙，调整几何模型直到Damp不再从上面掉下去。但在游戏进入测试阶段移交给发行商之后，我们收到了海量的“掉落bug”报告。每天都会有一批新的可以把Damp漏下去的地方被发现。我们修复了一批模型，第二天又会送来十几个问题模型。这持续了几天。后来出版商的测试部门专门雇了一个人每天在游戏里蹦来跳去10小时，就是为了看看还有哪儿能把人漏下去。&lt;/p&gt;
&lt;p&gt;问题是模型不好。它不是紧密无缝的集合体。它在PC上可以运行，但在PS1上不行，定点数极大地放大了这一问题。最优的方案是把几何体修补至无缝。&lt;/p&gt;
&lt;p&gt;可是，这个工作量太大了，以我们的人力不可能在时限之内找完，所以我们靠测试部门告诉我们出问题的区域。&lt;/p&gt;
&lt;p&gt;这个方案的问题是，找出来的地方无穷无尽。我们越来越痛苦。每天都有这个bug的新变体。这似乎没有尽头。&lt;/p&gt;
&lt;p&gt;最终问题被解决了。真正的问题不是几何体有缝隙，而是Damp会从那上面掉下去。这么一想，我就可以很快写一个简单的补丁修复这个问题了。修复代码类似这样：&lt;/p&gt;
&lt;pre&gt;IF ( Damp will fall through a hole() ) THEN
Don't do it&lt;/pre&gt;
&lt;p&gt;实际代码也没比这复杂到哪去（如下）.&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;damp_old = damp_loc;
move_damp();
if( NoCollision() )
{
    damp_loc = damp_old;
}&lt;/pre&gt;
&lt;p&gt;这下上千个bug得以修复。现在我们不让Damp掉到关卡下面去了，现在Damp只会在缝隙上抖一下，然后走过去。我们发现什么让我们很受伤，然后我们就不那样做了。出版商解雇了他们的“蹦跳测试员”，游戏发售。&lt;/p&gt;
&lt;p&gt;哦，他终于发售了。得益于“if A == bad THEN NOT A”的教训，我用这个方法又修复了几个bug —— 都是与碰撞相关的代码。在开发的最后阶段，bug变得越来越精确，修补的代码也就变得越来越类似“Don't do thispreciseandexacthing”（别做这件具体明确指定的事）。&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;if (damp_aliencoll != old_aliencoll
&amp;amp;&amp;amp; strcmpi(&quot;X4DOOR&quot;,damp_aliencoll-&amp;gt;enemy-&amp;gt;ename)==0
&amp;amp;&amp;amp; StartArena == 6 &amp;amp;&amp;amp; damp_loc.y&amp;lt;13370)
{
    damp_loc.y = damp_old.y; // don't let damp ever
    touch the door.. (move away in the x and y)
    damp_loc.x = damp_old.x;
    damp_aliencoll = NULL; // and say thusly!!!
}&lt;/pre&gt;
&lt;p&gt;这段代码是干什么的？嗯，首先，当Damp在某关的某处碰到某种类型的门时，会出bug。为此我们不是去追根究源找到那个bug的根本原因，而只是简单地当Damp碰到这个门的时候，就把他移开，永远不让他摸那扇门。问题解决了。&lt;/p&gt;
&lt;p&gt;回头再看这段代码让我觉得毛骨悚然。这是在补漏洞而不是修漏洞。不幸的是，真正的修复工作要重做整个游戏的模型和碰撞检测系统，而且是基于PS1的定点数限制。进度表一开始就很紧张了，我们总是身处发货前的修罗场一般，所以快速补丁总是胜过全面而耗时的修复。&lt;/p&gt;
&lt;p&gt;但是这也好不到哪去。我们需要上百个补丁，部分补丁自身就有问题，所以它们又需要新的补丁。bug没完没了，而我们就用补丁击退它们。最终我们胜利了，但代价是游戏延期了几个月发售，以及每天14小时，一连几个月的高强度工作量。&lt;/p&gt;
&lt;p&gt;这一经历让我很讨厌“补丁”。现在我总是尽量从根部修补bug，即使是一个简单无害、可用补丁掩盖的bug。我希望我的代码保持健康。如果你去见医生时告诉他“我一这样就难受，”那你应该让他告诉你为什么这样会难受，然后治好它。你的痛苦和你代码的bug可能都是某些更严重的问题的症状。教训：你希望医生怎么对待你，你就应该怎么对待你的代码。&lt;/p&gt;
&lt;p&gt;- Mick West&lt;/p&gt;
&lt;h1&gt;&lt;strong&gt;你不会喜欢生气的我的&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt;我曾在THQ工作室遗迹娱乐参与制作《The Outfit》，也许有人记得那是xbox 360早期的一款游戏。我们从一个（单线程）PC引擎开始，要在18个月之内用它完成一款多核次世代平台上的游戏。在离发售日还有3个月的时候，我们在360上还是只能跑到5帧每秒。显然这个游戏需要进行一些重大优化。&lt;/p&gt;
&lt;p&gt;在我做性能测试的时候，我发现大量代码有效率问题而且写得很“PC”，当然素材方面也有很多问题。有些模型太细致了，有些shader开销太大，有些关卡则是有太多家伙在里面跑来跑去了。&lt;/p&gt;
&lt;p&gt;这次的效率问题不是程序员简单地“fix”一下就可以解决的，我们需要的是改变一直以来的一些工作方式，但要说服一个百人团队接受这一观点，是很难的。人们需要了解，游戏的效率问题是我们每个人的问题。最终我决定用幽默一点的方式去解决这个问题。&lt;/p&gt;
&lt;p&gt;这个方案画了大概一个小时。一个程序员拿了四张我的正面照片——一张很高兴，一张普通，一张有点生气，还有一张是我在拽自己的头发。我让图片显示在屏幕的一角，然后把它和游戏帧数关联。如果游戏运行在每秒30帧以上，显示我很开心的那张照片，如果帧数低于20，就是我生气的那张。&lt;/p&gt;
&lt;p&gt;方案实施以后，帧数问题就从“嘛，程序员会搞定它的。”变成了，“呃，要是我把这个模型加进去，Nick就要发火了！看来我得先优化一下。”人们可以立刻看到他们所做的改变对帧数的影响。最终当游戏发售时，我们的游戏帧数达到了30.&lt;/p&gt;
&lt;p&gt;- Nick Waanders&lt;/p&gt;
&lt;h1&gt;&lt;strong&gt;神秘的第10关&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt;当年在[某公司]时，我记的是在[某项目]的收尾阶段，我们有一个对象需要在某一关隐藏起来。我们不想重新导出那一关，而且我们也没有用校验名。所以在引擎代码里，我们加入了类似下面的这段代码。最后游戏就带着这段代码发售了。&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;if( level == 10 &amp;amp;&amp;amp; object == 56)
{
    HideObject();
}&lt;/pre&gt;
&lt;p&gt;也许一年以后，某个用我们引擎的美术人员会一脸沮丧地跑来问我们为什么把某个对象导入到第10关以后它就不见了。到时候连我也会一头雾水吧？&lt;/p&gt;
&lt;p&gt;- 匿名&lt;/p&gt;
&lt;p&gt;--------&lt;br /&gt;
本文译自GAMASUTRA的 &lt;a href=&quot;http://www.gamasutra.com/view/feature/4111/dirty_coding_tricks.php&quot;&gt;Dirty Coding Tricks &lt;/a&gt; ，原文作者：&lt;a href=&quot;http://www.gamasutra.com/view/authors/543/Brandon_Sheffield.php&quot;&gt;Brandon Sheffield&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot;&gt;kira0001&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;将任何网页变成Katamari Damacy游戏&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F03%2F13%2Fkatamari-hack%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F12%2F02%2Fdirty-coding-tricks-2%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/03/14/3502487.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;将任何网页变成Katamari Damacy游戏&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;脏代码技巧 之 写程序的黑暗英雄&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F30%2Fdirty_coding_tricks%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F12%2F02%2Fdirty-coding-tricks-2%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;脏代码技巧 之 写程序的黑暗英雄&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;不喜欢8小时外写代码的就不是好开发？&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F06%2F23%2Fi-dont-program-in-my-spare-time-does-that-make-me-a-bad-developer%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F12%2F02%2Fdirty-coding-tricks-2%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/24/14154347.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;不喜欢8小时外写代码的就不是好开发？&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;轻松为任意程序代码添加语法高亮&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F08%2F01%2Fquick-tip-how-to-add-syntax-highlighting-to-any-project%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F12%2F02%2Fdirty-coding-tricks-2%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/08/01/20424846.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;轻松为任意程序代码添加语法高亮&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492402/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492402/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/12/02/dirty-coding-tricks-2/feed/</wfw:commentRss><slash:comments>5</slash:comments><description>&lt;h1&gt;&lt;strong&gt;精准补丁&lt;/strong&gt;&lt;/h1&gt;
有个老笑话是这么说的：

病人：“医生，我一这样就难受。”
医生：“那就别那样。”

有趣，但把它用在自己的项目中也管用吗？这让我想起了自己从PC移植一款3D第三人称射击游戏到初代PS上时所经受的痛苦。

现在，PS1不支持浮点数，所以我们要重新编译PC代码，把所有浮点数都换成顶点数。这确实效果不错，除了碰撞检测。

我们的关卡的模型在PC版里确实运作的很好，但当浮点型转为定点型以后，微小的数值误差使各种拼接缝线、T型拼接处和其他问题层出不穷。这个问题的表现之一是主人公（叫做“Damp”）会轻易掉进那些微小的缝隙中，落入关卡深处。

我们补上了我们发现的缝隙，调整几何模型直到Damp不再从上面掉下去。但在游戏进入测试阶段移交给发行商之后，我们收到了海量的“掉落bug”报告。每天都会有一批新的可以把Damp漏下去的地方被发现。我们修复了一批模型，第二天又会送来十几个问题模型。这持续了几天。后来出版商的测试部门专门雇了一个人每天在游戏里蹦来跳去10小时，就是为了看看还有哪儿能把人漏下去。

问题是模型不好。它不是紧密无缝的集合体。它在PC上可以运行，但在PS1上不行，定点数极大地放大了这一问题。最优的方案是把几何体修补至无缝。

可是，这个工作量太大了，以我们的人力不可能在时限之内找完，所以我们靠测试部门告诉我们出问题的区域。

这个方案的问题是，找出来的地方无穷无尽。我们越来越痛苦。每天都有这个bug的新变体。这似乎没有尽头。

最终问题被解决了。真正的问题不是几何体有缝隙，而是Damp会从那上面掉下去。这么一想，我就可以很快写一个简单的补丁修复这个问题了。修复代码类似这样：
&lt;pre&gt;IF ( Damp will fall through a hole() ) THEN
Don't do it&lt;/pre&gt;
实际代码也没比这复杂到哪去（如下）.
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;damp_old = damp_loc;
move_damp();
if( NoCollision() )
{
    damp_loc = damp_old;
}&lt;/pre&gt;
这下上千个bug得以修复。现在我们不让Damp掉到关卡下面去了，现在Damp只会在缝隙上抖一下，然后走过去。我们发现什么让我们很受伤，然后我们就不那样做了。出版商解雇了他们的“蹦跳测试员”，游戏发售。

哦，他终于发售了。得益于“if A == bad THEN NOT A”的教训，我用这个方法又修复了几个bug —— 都是与碰撞相关的代码。在开发的最后阶段，bug变得越来越精确，修补的代码也就变得越来越类似“Don't do thispreciseandexacthing”（别做这件具体明确指定的事）。
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;if (damp_aliencoll != old_aliencoll
&amp;#38;&amp;#38; strcmpi(&quot;X4DOOR&quot;,damp_aliencoll-&amp;#62;enemy-&amp;#62;ename)==0
&amp;#38;&amp;#38; StartArena == 6 &amp;#38;&amp;#38; damp_loc.y&amp;#60;13370)
{
    damp_loc.y = damp_old.y; // don't let damp ever
    touch the door.. (move away in the x and y)
    damp_loc.x = damp_old.x;
    damp_aliencoll = NULL; // and say thusly!!!
}&lt;/pre&gt;
这段代码是干什么的？嗯，首先，当Damp在某关的某处碰到某种类型的门时，会出bug。为此我们不是去追根究源找到那个bug的根本原因，而只是简单地当Damp碰到这个门的时候，就把他移开，永远不让他摸那扇门。问题解决了。

回头再看这段代码让我觉得毛骨悚然。这是在补漏洞而不是修漏洞。不幸的是，真正的修复工作要重做整个游戏的模型和碰撞检测系统，而且是基于PS1的定点数限制。进度表一开始就很紧张了，我们总是身处发货前的修罗场一般，所以快速补丁总是胜过全面而耗时的修复。

但是这也好不到哪去。我们需要上百个补丁，部分补丁自身就有问题，所以它们又需要新的补丁。bug没完没了，而我们就用补丁击退它们。最终我们胜利了，但代价是游戏延期了几个月发售，以及每天14小时，一连几个月的高强度工作量。

这一经历让我很讨厌“补丁”。现在我总是尽量从根部修补bug，即使是一个简单无害、可用补丁掩盖的bug。我希望我的代码保持健康。如果你去见医生时告诉他“我一这样就难受，”那你应该让他告诉你为什么这样会难受，然后治好它。你的痛苦和你代码的bug可能都是某些更严重的问题的症状。教训：你希望医生怎么对待你，你就应该怎么对待你的代码。

- Mick West
&lt;h1&gt;&lt;strong&gt;你不会喜欢生气的我的&lt;/strong&gt;&lt;/h1&gt;
我曾在THQ工作室遗迹娱乐参与制作《The Outfit》，也许有人记得那是xbox 360早期的一款游戏。我们从一个（单线程）PC引擎开始，要在18个月之内用它完成一款多核次世代平台上的游戏。在离发售日还有3个月的时候，我们在360上还是只能跑到5帧每秒。显然这个游戏需要进行一些重大优化。

在我做性能测试的时候，我发现大量代码有效率问题而且写得很“PC”，当然素材方面也有很多问题。有些模型太细致了，有些shader开销太大，有些关卡则是有太多家伙在里面跑来跑去了。

这次的效率问题不是程序员简单地“fix”一下就可以解决的，我们需要的是改变一直以来的一些工作方式，但要说服一个百人团队接受这一观点，是很难的。人们需要了解，游戏的效率问题是我们每个人的问题。最终我决定用幽默一点的方式去解决这个问题。

这个方案画了大概一个小时。一个程序员拿了四张我的正面照片——一张很高兴，一张普通，一张有点生气，还有一张是我在拽自己的头发。我让图片显示在屏幕的一角，然后把它和游戏帧数关联。如果游戏运行在每秒30帧以上，显示我很开心的那张照片，如果帧数低于20，就是我生气的那张。

方案实施以后，帧数问题就从“嘛，程序员会搞定它的。”变成了，“呃，要是我把这个模型加进去，Nick就要发火了！看来我得先优化一下。”人们可以立刻看到他们所做的改变对帧数的影响。最终当游戏发售时，我们的游戏帧数达到了30.

- Nick Waanders
&lt;h1&gt;&lt;strong&gt;神秘的第10关&lt;/strong&gt;&lt;/h1&gt;
当年在[某公司]时，我记的是在[某项目]的收尾阶段，我们有一个对象需要在某一关隐藏起来。我们不想重新导出那一关，而且我们也没有用校验名。所以在引擎代码里，我们加入了类似下面的这段代码。最后游戏就带着这段代码发售了。
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;if( level == 10 &amp;#38;&amp;#38; object == 56)
{
    HideObject();
}&lt;/pre&gt;
也许一年以后，某个用我们引擎的美术人员会一脸沮丧地跑来问我们为什么把某个对象导入到第10关以后它就不见了。到时候连我也会一头雾水吧？

- 匿名

--------
本文译自GAMASUTRA的 &lt;a href=&quot;http://www.gamasutra.com/view/feature/4111/dirty_coding_tricks.php&quot;&gt;Dirty Coding Tricks &lt;/a&gt; ，原文作者：&lt;a href=&quot;http://www.gamasutra.com/view/authors/543/Brandon_Sheffield.php&quot;&gt;Brandon Sheffield&lt;/a&gt;

本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot;&gt;kira0001&lt;/a&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492402/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492402/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><category>游戏</category><pubDate>Fri, 02 Dec 2011 16:27:30 +0800</pubDate><author>kira0001</author><comments>http://heikezhi.com/2011/12/02/dirty-coding-tricks-2/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1872</guid><dc:creator>kira0001</dc:creator><fs:srclink>http://heikezhi.com/2011/12/02/dirty-coding-tricks-2/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492402/6713895</fs:itemid></item><item><title>脏代码技巧 之 写程序的黑暗英雄</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492403/6713895/1/item.html</link><content:encoded>&lt;p&gt;[当日程表紧张而游戏即将发售时，程序员会用一些脏代码技巧来保证游戏按时完工。本文原载于今年（译注：2009年）早些时候发售的Gamasutra姊妹出版物《&lt;a href=&quot;http://www.gdmag.com/&quot;&gt;Game Developer magazine&lt;/a&gt;》，记载了9个真实的脏代码技巧的例子，本文是其中的一个。]&lt;/p&gt;
&lt;p&gt;程序员通常都是些追求条理和严谨性的家伙，他们总是尽最大努力保持代码的整洁和优雅。但当情况紧急，日程表不容变更，而游戏即将发售时，“把它完成”的优先级就会超过代码优雅。&lt;/p&gt;
&lt;p&gt;在这种情况下，一个过度加班疲惫不堪的程序员更倾向于抛弃最佳方案，而以一种难以令人满意的的hack方式来完成代码，这里我们编辑了来自现职开发者的9份证言，记录了当他们不能遵循编程规范，不得不用一些技巧来挽救项目。&lt;/p&gt;
&lt;p&gt;- Brandon Sheffield&lt;/p&gt;
&lt;p&gt;9. 写程序的黑暗英雄&lt;/p&gt;
&lt;p&gt;在即将迎来我参与的第一个专业游戏项目 —— 一个90年代后期的PC游戏 —— 的beta阶段时，我还只是个刚毕业的新手。那就像坐过山车一样令人兴奋。内容全部整合好了，而且游戏看起来很棒。只有一个问题：内存使用量超出了预计。&lt;/p&gt;
&lt;p&gt;因为大部分内存都是被模型和纹理用掉的，所以我们和美工一起删减美术资源以节省内存开销。我们缩小图片，大量删除模型，压缩纹理。有些做法美工可以接受，有些就只能推倒美工才得以实行了。&lt;/p&gt;
&lt;p&gt;我们删了1M又1M，经过几天艰苦的努力，我们抵达了某种临界 —— 再也没有什么可以删的了。除非我们砍掉游戏的一些主体内容，不然再没有任何办法可以削减内存使用量了。我们精疲力尽地统计了当前的内存用量，发现还是多出1.5M！&lt;/p&gt;
&lt;p&gt;这时，我们这里最有经验的程序员之一 —— 一个曾在“美好的久远年代”混迹开发领域数年的前辈 —— 决定接手这件事。他把我叫进他的办公室，我心想又要来一场劳心伤神的内存争夺战了吧。&lt;/p&gt;
&lt;p&gt;可是，他只是打开一个源文件然后指着其中一行：&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;static char buffer[1024*1024*2];&lt;/pre&gt;
&lt;p&gt;说，“看到了吗？”然后轻轻一按，删掉了这行代码。搞定！&lt;/p&gt;
&lt;p&gt;也许是察觉到我眼中的震撼，他向我解释说他在开发的早期阶段加进了这2M内存。经验告诉他删减内容到预计内存之内总是非常重要的，很多项目因此几近失败。所以现在，作为一种常规做法，他总是留一小块内存，到真正需要的时候再释放他们。&lt;/p&gt;
&lt;p&gt;他走出办公室，然后宣布他已经把内存使用量减至上限之内，后来他被看作是这个项目的英雄。&lt;/p&gt;
&lt;p&gt;尽管被这种野蛮的做法“震惊了”，我还是不得不承认我对他的做法很感兴趣。我还没想到在哪里可以用上这招，但我知道了在有些时候，当你面对障碍时，为了应对困境而事先藏起一些内存真的非常有意义。时间和经验带来的改变可真是有趣。&lt;/p&gt;
&lt;p&gt;- Noel Llopis&lt;/p&gt;
&lt;p&gt;--------&lt;br /&gt;
本文译自GAMASUTRA的 &lt;a href=&quot;http://www.gamasutra.com/view/feature/4111/dirty_coding_tricks.php&quot;&gt;Dirty Coding Tricks &lt;/a&gt; ，原文作者：&lt;a href=&quot;http://www.gamasutra.com/view/authors/543/Brandon_Sheffield.php&quot;&gt;Brandon Sheffield&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot;&gt;kira0001&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;轻松为任意程序代码添加语法高亮&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F08%2F01%2Fquick-tip-how-to-add-syntax-highlighting-to-any-project%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F30%2Fdirty_coding_tricks%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/08/01/20424846.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;轻松为任意程序代码添加语法高亮&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;脏代码技巧 精准补丁(外二则)&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F12%2F02%2Fdirty-coding-tricks-2%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F30%2Fdirty_coding_tricks%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;脏代码技巧 精准补丁(外二则)&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;TermKit: 下一代的Mac命令行/终端程序&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F05%2F18%2Ftermkit-next-gen-terminal-command-line-app-for-mac%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F30%2Fdirty_coding_tricks%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/05/18/8913429.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;TermKit: 下一代的Mac命令行/终端程序&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;一个训练你摄影技巧的方法&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F03%2F%25E4%25B8%2580%25E4%25B8%25AA%25E8%25AE%25AD%25E7%25BB%2583%25E4%25BD%25A0%25E6%2591%2584%25E5%25BD%25B1%25E6%258A%2580%25E5%25B7%25A7%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F30%2Fdirty_coding_tricks%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/04/04/4990269.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;一个训练你摄影技巧的方法&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492403/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492403/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/11/30/dirty_coding_tricks/feed/</wfw:commentRss><slash:comments>8</slash:comments><description>[当日程表紧张而游戏即将发售时，程序员会用一些脏代码技巧来保证游戏按时完工。本文原载于今年（译注：2009年）早些时候发售的Gamasutra姊妹出版物《&lt;a href=&quot;http://www.gdmag.com/&quot;&gt;Game Developer magazine&lt;/a&gt;》，记载了9个真实的脏代码技巧的例子，本文是其中的一个。]

程序员通常都是些追求条理和严谨性的家伙，他们总是尽最大努力保持代码的整洁和优雅。但当情况紧急，日程表不容变更，而游戏即将发售时，“把它完成”的优先级就会超过代码优雅。

在这种情况下，一个过度加班疲惫不堪的程序员更倾向于抛弃最佳方案，而以一种难以令人满意的的hack方式来完成代码，这里我们编辑了来自现职开发者的9份证言，记录了当他们不能遵循编程规范，不得不用一些技巧来挽救项目。

- Brandon Sheffield

9. 写程序的黑暗英雄

在即将迎来我参与的第一个专业游戏项目 —— 一个90年代后期的PC游戏 —— 的beta阶段时，我还只是个刚毕业的新手。那就像坐过山车一样令人兴奋。内容全部整合好了，而且游戏看起来很棒。只有一个问题：内存使用量超出了预计。

因为大部分内存都是被模型和纹理用掉的，所以我们和美工一起删减美术资源以节省内存开销。我们缩小图片，大量删除模型，压缩纹理。有些做法美工可以接受，有些就只能推倒美工才得以实行了。

我们删了1M又1M，经过几天艰苦的努力，我们抵达了某种临界 —— 再也没有什么可以删的了。除非我们砍掉游戏的一些主体内容，不然再没有任何办法可以削减内存使用量了。我们精疲力尽地统计了当前的内存用量，发现还是多出1.5M！

这时，我们这里最有经验的程序员之一 —— 一个曾在“美好的久远年代”混迹开发领域数年的前辈 —— 决定接手这件事。他把我叫进他的办公室，我心想又要来一场劳心伤神的内存争夺战了吧。

可是，他只是打开一个源文件然后指着其中一行：
&lt;pre name=&quot;code&quot; class=&quot;c&quot;&gt;static char buffer[1024*1024*2];&lt;/pre&gt;
说，“看到了吗？”然后轻轻一按，删掉了这行代码。搞定！

也许是察觉到我眼中的震撼，他向我解释说他在开发的早期阶段加进了这2M内存。经验告诉他删减内容到预计内存之内总是非常重要的，很多项目因此几近失败。所以现在，作为一种常规做法，他总是留一小块内存，到真正需要的时候再释放他们。

他走出办公室，然后宣布他已经把内存使用量减至上限之内，后来他被看作是这个项目的英雄。

尽管被这种野蛮的做法“震惊了”，我还是不得不承认我对他的做法很感兴趣。我还没想到在哪里可以用上这招，但我知道了在有些时候，当你面对障碍时，为了应对困境而事先藏起一些内存真的非常有意义。时间和经验带来的改变可真是有趣。

- Noel Llopis

--------
本文译自GAMASUTRA的 &lt;a href=&quot;http://www.gamasutra.com/view/feature/4111/dirty_coding_tricks.php&quot;&gt;Dirty Coding Tricks &lt;/a&gt; ，原文作者：&lt;a href=&quot;http://www.gamasutra.com/view/authors/543/Brandon_Sheffield.php&quot;&gt;Brandon Sheffield&lt;/a&gt;

本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot;&gt;kira0001&lt;/a&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492403/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492403/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Wed, 30 Nov 2011 18:32:51 +0800</pubDate><author>kira0001</author><comments>http://heikezhi.com/2011/11/30/dirty_coding_tricks/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1848</guid><dc:creator>kira0001</dc:creator><fs:srclink>http://heikezhi.com/2011/11/30/dirty_coding_tricks/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492403/6713895</fs:itemid></item><item><title>Valve CEO Gabe表示盗版与定价无关</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492404/6713895/1/item.html</link><content:encoded>&lt;p&gt;Valve的老板认为，对消费者和发行商来说最大的问题不是定价，是服务。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/5374048042/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://farm6.staticflickr.com/5208/5374048042_3ed58a2ba5.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;以下是Valve的联合创始人、现任CEO Gabe Newell 对游戏业盗版问题的看法。这个站在在线零售服务Steam背后的男人反对那些号称游戏降价就能摆脱盗版问题的人，也拒绝与靠牺牲玩家便利来摆脱盗版问题的公司为伍。&lt;/p&gt;
&lt;p&gt;“我们认为人们对盗版有一个根本上的误解，”Newell说，“盗版滋生几乎总是因为服务问题而不定价问题。例如，盗版可以向世界上任何地方7×24小时的提供一款游戏，用你的个人电脑就可以很方便的获得游戏，而正版发行商会说这个产品是地区限定的，等在美国发售3个月以后才会在你的国家发行，而且只会在实体店出售，这时盗版提供的服务就更有吸引力。&lt;/p&gt;
&lt;p&gt;“大部分DRM（译注：数字版权管理）方案都是在降低产品的价值，它们要么直接限制用户的使用，要么留下了不确定因素。”&lt;/p&gt;
&lt;p&gt;他补充道，“我们的目标是创造比盗版更好的服务价值，到目前为止我们在这方面都很成功，盗版对我们公司基本上不构成威胁。比如，在进入俄罗斯市场之前，我们被告知俄罗斯之行是浪费时间，因为那儿的人都玩盗版。现在，俄罗斯即将成为我们在欧洲最大的市场。&lt;/p&gt;
&lt;p&gt;“我们的成功源于我们总是确保让消费者和合作伙伴都觉得他们从我们的服务中获益。他们可以相信我们不会利用我们之间的关系来占便宜。”&lt;/p&gt;
&lt;p&gt;“我们把自己想象成客服中心而不是销售中心。我们大部分的决定都是为了尽快抓住机会来更好的服务我们的客户，而不是为了成为一个更好的游戏公司或数字分销商。后者将更多关注如何限制，而不是如何改善”&lt;/p&gt;
&lt;p&gt;----------------------&lt;/p&gt;
&lt;p&gt;本文译自IGN新闻：&lt;a href=&quot;http://games.ign.com/articles/121/1213357p1.html&quot; target=&quot;_blank&quot;&gt;Gabe Says Piracy Isn't About Price&lt;/a&gt;，作者 &lt;a href=&quot;http://twitter.com/#!/ColinCampbellx&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;Colin Campbell&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;图片来自：&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/5374048042/&quot;&gt;http://www.flickr.com/photos/trojanguy/5374048042/&lt;/a&gt;， 作者：&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/&quot;&gt;Jeff the Trojan&lt;/a&gt; ，基于&lt;a href=&quot;http://creativecommons.org/licenses/by-nc-sa/2.0/deed.zh_HK&quot; target=&quot;_blank&quot;&gt;姓名標示-非商業性-相同方式分享&lt;/a&gt;，原作者保留部分权利。&lt;/p&gt;
&lt;p&gt;本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot; target=&quot;_blank&quot;&gt;kira0001&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2 style=&quot;font-size: 1.46em;padding-top: 90px;line-height: 1.1;color: #ffffff;font-family: arial, verdana, sans-serif;text-align: center;background-color: #424242;margin: 0px&quot;&gt;&lt;span&gt;姓名標示-非商業性-相同方式分享&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
  
&lt;div class=&quot;wp_license&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-nc-sa/3.0/&quot;&gt;&lt;img src=&quot;http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png&quot; alt=&quot;Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported&quot; class=&quot;alignleft&quot; style=&quot;margin-top:4px;&quot; /&gt;
&lt;/a&gt;此作品采用 &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-nc-sa/3.0/&quot;&gt;Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;创业公司CEO每周必做的13件事&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F09%2F13-things-you-must-do-every-week-as-a-startup-ceo%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fgabe-says-piracy-isnt-about-price%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;创业公司CEO每周必做的13件事&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;HTML5可见性API以及页面预渲染&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F06%2Fhtml5-visibility-api-page-pre-rendering%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fgabe-says-piracy-isnt-about-price%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/07/07/16466946.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;HTML5可见性API以及页面预渲染&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;测测你的Github能得多少分&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F20%2Fgithub-score%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fgabe-says-piracy-isnt-about-price%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/04/21/6102220.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;测测你的Github能得多少分&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;10个编程首选字体&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F05%2F31%2Ftop-10-programming-font%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fgabe-says-piracy-isnt-about-price%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/01/10395930.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;10个编程首选字体&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492404/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492404/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/11/29/gabe-says-piracy-isnt-about-price/feed/</wfw:commentRss><slash:comments>1</slash:comments><description>&lt;a href=&quot;http://heikezhi.com/2011/11/29/gabe-says-piracy-isnt-about-price/&quot;&gt;&lt;img align=&quot;left&quot; hspace=&quot;5&quot; width=&quot;150&quot; src=&quot;http://farm6.staticflickr.com/5208/5374048042_3ed58a2ba5.jpg&quot; class=&quot;alignleft wp-post-image tfe&quot; alt=&quot;&quot; title=&quot;&quot; /&gt;&lt;/a&gt;Valve的老板认为，对消费者和发行商来说最大的问题不是定价，是服务。

&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/5374048042/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://farm6.staticflickr.com/5208/5374048042_3ed58a2ba5.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;

以下是Valve的联合创始人、现任CEO Gabe Newell 对游戏业盗版问题的看法。这个站在在线零售服务Steam背后的男人反对那些号称游戏降价就能摆脱盗版问题的人，也拒绝与靠牺牲玩家便利来摆脱盗版问题的公司为伍。

“我们认为人们对盗版有一个根本上的误解，”Newell说，“盗版滋生几乎总是因为服务问题而不定价问题。例如，盗版可以向世界上任何地方7×24小时的提供一款游戏，用你的个人电脑就可以很方便的获得游戏，而正版发行商会说这个产品是地区限定的，等在美国发售3个月以后才会在你的国家发行，而且只会在实体店出售，这时盗版提供的服务就更有吸引力。

“大部分DRM（译注：数字版权管理）方案都是在降低产品的价值，它们要么直接限制用户的使用，要么留下了不确定因素。”

他补充道，“我们的目标是创造比盗版更好的服务价值，到目前为止我们在这方面都很成功，盗版对我们公司基本上不构成威胁。比如，在进入俄罗斯市场之前，我们被告知俄罗斯之行是浪费时间，因为那儿的人都玩盗版。现在，俄罗斯即将成为我们在欧洲最大的市场。

“我们的成功源于我们总是确保让消费者和合作伙伴都觉得他们从我们的服务中获益。他们可以相信我们不会利用我们之间的关系来占便宜。”

“我们把自己想象成客服中心而不是销售中心。我们大部分的决定都是为了尽快抓住机会来更好的服务我们的客户，而不是为了成为一个更好的游戏公司或数字分销商。后者将更多关注如何限制，而不是如何改善”

----------------------

本文译自IGN新闻：&lt;a href=&quot;http://games.ign.com/articles/121/1213357p1.html&quot; target=&quot;_blank&quot;&gt;Gabe Says Piracy Isn't About Price&lt;/a&gt;，作者 &lt;a href=&quot;http://twitter.com/#!/ColinCampbellx&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;Colin Campbell&lt;/a&gt;

图片来自：&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/5374048042/&quot;&gt;http://www.flickr.com/photos/trojanguy/5374048042/&lt;/a&gt;， 作者：&lt;a href=&quot;http://www.flickr.com/photos/trojanguy/&quot;&gt;Jeff the Trojan&lt;/a&gt; ，基于&lt;a href=&quot;http://creativecommons.org/licenses/by-nc-sa/2.0/deed.zh_HK&quot; target=&quot;_blank&quot;&gt;姓名標示-非商業性-相同方式分享&lt;/a&gt;，原作者保留部分权利。

本文译者：&lt;a href=&quot;http://hi.baidu.com/kira0001&quot; target=&quot;_blank&quot;&gt;kira0001&lt;/a&gt;

&amp;#160;

&amp;#160;

&amp;#160;
&lt;h2 style=&quot;font-size: 1.46em;padding-top: 90px;line-height: 1.1;color: #ffffff;font-family: arial, verdana, sans-serif;text-align: center;background-color: #424242;margin: 0px&quot;&gt;&lt;span&gt;姓名標示-非商業性-相同方式分享&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492404/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492404/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Wed, 30 Nov 2011 04:31:47 +0800</pubDate><author>kira0001</author><comments>http://heikezhi.com/2011/11/29/gabe-says-piracy-isnt-about-price/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1814</guid><dc:creator>kira0001</dc:creator><fs:srclink>http://heikezhi.com/2011/11/29/gabe-says-piracy-isnt-about-price/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492404/6713895</fs:itemid></item><item><title>技术宅的圣诞礼物</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492405/6713895/1/item.html</link><content:encoded>&lt;p&gt;如果你是个技术宅，正在发愁圣诞送什么礼物给女友，那你不妨学学&lt;a href=&quot;https://github.com/spmacdonald&quot;&gt;Scott MacDonald&lt;/a&gt;，&lt;a href=&quot;http://www.elusivesnark.com/2008/11/carolines-dice-portrait.html&quot;&gt;用骰子为她制作一副肖像画&lt;/a&gt;，下面就让我们看看Scott是如何完成这幅重达100磅（约45公斤）的骰子肖像画的吧。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/1.png&quot; alt=&quot;&quot; title=&quot;1&quot; width=&quot;660&quot; height=&quot;352&quot; class=&quot;alignnone size-full wp-image-1833&quot; /&gt;&lt;/p&gt;
&lt;p&gt;首先第一步就是图像处理，我们需要将全彩图像转换为骰子灰度，首先将图像转换为6阶灰度图，然后将这6个灰度对应到骰子的6个点，1代表黑色，6代表白色，帖子结尾附有&lt;a href=&quot;http://processing.org&quot;&gt;Processing&lt;/a&gt;转换程序（如果你是PS宅，这里是&lt;a href=&quot;http://www.attackofdesign.com/how-to-build-a-portrait-with-dice-using-photoshop/&quot;&gt;一篇PS转换教程&lt;/a&gt;）。&lt;/p&gt;
&lt;p&gt;接下来就是材料准备了，这是Scott购买的3000颗骰子，他计划制作一幅64 x 102.4厘米的画作，如果以骰子为单位，那就是40 x 64平方骰子，总共需要2560颗骰子，这个尺寸的高宽比为1.6，接近黄金比例。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/2.jpg&quot; alt=&quot;&quot; title=&quot;2&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1834&quot; /&gt;&lt;/p&gt;
&lt;p&gt;spmacdonald的工作台，他花了4个小时完成组装：&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/3.jpg&quot; alt=&quot;&quot; title=&quot;3&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1835&quot; /&gt;&lt;/p&gt;
&lt;p&gt;下面是最后的成品：&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/4.jpg&quot; alt=&quot;&quot; title=&quot;4&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1836&quot; /&gt;&lt;/p&gt;
&lt;p&gt;大图：&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/5.jpg&quot; alt=&quot;&quot; title=&quot;5&quot; width=&quot;660&quot; height=&quot;880&quot; class=&quot;alignnone size-full wp-image-1837&quot; /&gt;&lt;/p&gt;
&lt;p&gt;转换程序：&lt;/p&gt;
&lt;pre&gt;
PImage img;
PImage cropped_img;
PImage patch;

int _width = 640;
int _height = 1024;
int patch_w = 16;
int patch_h = 16;
int pip_size = 4;

void setup() {
    size(_width, _height);
    img = loadImage(&quot;Caroline.jpg&quot;);
    img.resize(1536, 1024);
    cropped_img = img.get(250, 0, _width, _height);
}

// Draw quantized image
void draw() {

    // Array to hold the gray values of a patch
    int[] x = new int[patch_w * patch_h];

    // Quantize the image
    for (int i=0; i &lt; (_width/patch_w); ++i) {
        for (int j=0; j &lt; (_height/patch_h); ++j) {
            patch = cropped_img.get(i*patch_w,
                                    j*patch_h,
                                    patch_w,
                                    patch_h);
            patch.loadPixels();
            for (int k=0; k &lt; patch.pixels.length; ++k) {
                x[k] = rgb2gray(patch.pixels[k]);
            }

            int dice_num = six_step_gray(mean(x));
            if (dice_num == 1) draw_one(i, j);
            if (dice_num == 2) draw_two(i, j);
            if (dice_num == 3) draw_three(i, j);
            if (dice_num == 4) draw_four(i, j);
            if (dice_num == 5) draw_five(i, j);
            if (dice_num == 6) draw_six(i, j);
        }
    }
}

void draw_one(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
}

void draw_two(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

void draw_three(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

void draw_four(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

void draw_five(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
}

void draw_six(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

// Impose 6 step gray palette
int six_step_gray(int x) {
    if (0 &lt;= x &amp;#038;&amp; x &lt;= 41)
        return 1;
    if (41 &lt; x &amp;#038;&amp; x &lt;= 83)
        return 2;
    if (83 &lt; x &amp;#038;&amp; x &lt;= 124)
        return 3;
    if (124 &lt; x &amp;#038;&amp; x &lt;= 165)
        return 4;
    if (165 &lt; x &amp;#038;&amp; x &lt;= 206)
        return 5;
    if (x &lt; 206 &amp;#038;&amp; x &lt;= 247)
        return 6;
    else
        return 6;
}

// Blend rgb channels
int rgb2gray(int argb) {
    int _alpha = (argb &gt;&gt; 24) &amp;#038; 0xFF;
    int _red = (argb &gt;&gt; 16) &amp;#038; 0xFF;
    int _green = (argb &gt;&gt; 8 ) &amp;#038; 0xFF;
    int _blue = (argb) &amp;#038; 0xFF;

    return int(0.3*_red + 0.59*_green + 0.11*_blue);
}

// Calculates the average of an integer array
int mean(int[] x) {
    float m = 0;
    for (int i=0; i &lt; x.length; ++i) {
        m += x[i];
    }
    m = m/x.length;
    return int(m);
}
&lt;/pre&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;帮助Geek找到技术合作伙伴，点燃心中曾经的梦想！&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F06%2F%25E5%25B8%25AE%25E5%258A%25A9geek%25E6%2589%25BE%25E5%2588%25B0%25E6%258A%2580%25E6%259C%25AF%25E5%2590%2588%25E4%25BD%259C%25E4%25BC%2599%25E4%25BC%25B4%25EF%25BC%258C%25E7%2582%25B9%25E7%2587%2583%25E5%25BF%2583%25E4%25B8%25AD%25E6%259B%25BE%25E7%25BB%258F%25E7%259A%2584%25E6%25A2%25A6%25E6%2583%25B3%25EF%25BC%2581%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fdice-portrait%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;帮助Geek找到技术合作伙伴，点燃心中曾经的梦想！&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;如何评估非技术的创业伙伴&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F03%2F29%2Fhow-to-evaluate-a-non-technical-co-founder%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fdice-portrait%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;如何评估非技术的创业伙伴&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;一个训练你摄影技巧的方法&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F03%2F%25E4%25B8%2580%25E4%25B8%25AA%25E8%25AE%25AD%25E7%25BB%2583%25E4%25BD%25A0%25E6%2591%2584%25E5%25BD%25B1%25E6%258A%2580%25E5%25B7%25A7%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fdice-portrait%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/04/04/4990269.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;一个训练你摄影技巧的方法&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;测测你的Github能得多少分&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F20%2Fgithub-score%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F29%2Fdice-portrait%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/04/21/6102220.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;测测你的Github能得多少分&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492405/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492405/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/11/29/dice-portrait/feed/</wfw:commentRss><slash:comments>6</slash:comments><description>&lt;a href=&quot;http://heikezhi.com/2011/11/29/dice-portrait/&quot;&gt;&lt;img align=&quot;left&quot; hspace=&quot;5&quot; width=&quot;150&quot; height=&quot;150&quot; src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/1-150x150.png&quot; class=&quot;alignleft wp-post-image tfe&quot; alt=&quot;&quot; title=&quot;1&quot; /&gt;&lt;/a&gt;如果你是个技术宅，正在发愁圣诞送什么礼物给女友，那你不妨学学&lt;a href=&quot;https://github.com/spmacdonald&quot;&gt;Scott MacDonald&lt;/a&gt;，&lt;a href=&quot;http://www.elusivesnark.com/2008/11/carolines-dice-portrait.html&quot;&gt;用骰子为她制作一副肖像画&lt;/a&gt;，下面就让我们看看Scott是如何完成这幅重达100磅（约45公斤）的骰子肖像画的吧。

&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/1.png&quot; alt=&quot;&quot; title=&quot;1&quot; width=&quot;660&quot; height=&quot;352&quot; class=&quot;alignnone size-full wp-image-1833&quot; /&gt;

首先第一步就是图像处理，我们需要将全彩图像转换为骰子灰度，首先将图像转换为6阶灰度图，然后将这6个灰度对应到骰子的6个点，1代表黑色，6代表白色，帖子结尾附有&lt;a href=&quot;http://processing.org&quot;&gt;Processing&lt;/a&gt;转换程序（如果你是PS宅，这里是&lt;a href=&quot;http://www.attackofdesign.com/how-to-build-a-portrait-with-dice-using-photoshop/&quot;&gt;一篇PS转换教程&lt;/a&gt;）。

接下来就是材料准备了，这是Scott购买的3000颗骰子，他计划制作一幅64 x 102.4厘米的画作，如果以骰子为单位，那就是40 x 64平方骰子，总共需要2560颗骰子，这个尺寸的高宽比为1.6，接近黄金比例。

&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/2.jpg&quot; alt=&quot;&quot; title=&quot;2&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1834&quot; /&gt;

spmacdonald的工作台，他花了4个小时完成组装：

&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/3.jpg&quot; alt=&quot;&quot; title=&quot;3&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1835&quot; /&gt;

下面是最后的成品：

&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/4.jpg&quot; alt=&quot;&quot; title=&quot;4&quot; width=&quot;660&quot; height=&quot;495&quot; class=&quot;alignnone size-full wp-image-1836&quot; /&gt;

大图：

&lt;img src=&quot;http://heikezhi.com/wp-content/uploads/2011/11/5.jpg&quot; alt=&quot;&quot; title=&quot;5&quot; width=&quot;660&quot; height=&quot;880&quot; class=&quot;alignnone size-full wp-image-1837&quot; /&gt;

转换程序：

&lt;pre&gt;
PImage img;
PImage cropped_img;
PImage patch;

int _width = 640;
int _height = 1024;
int patch_w = 16;
int patch_h = 16;
int pip_size = 4;

void setup() {
    size(_width, _height);
    img = loadImage(&quot;Caroline.jpg&quot;);
    img.resize(1536, 1024);
    cropped_img = img.get(250, 0, _width, _height);
}

// Draw quantized image
void draw() {

    // Array to hold the gray values of a patch
    int[] x = new int[patch_w * patch_h];

    // Quantize the image
    for (int i=0; i &lt; (_width/patch_w); ++i) {
        for (int j=0; j &lt; (_height/patch_h); ++j) {
            patch = cropped_img.get(i*patch_w, 
                                    j*patch_h, 
                                    patch_w, 
                                    patch_h);
            patch.loadPixels();
            for (int k=0; k &lt; patch.pixels.length; ++k) {
                x[k] = rgb2gray(patch.pixels[k]);
            }

            int dice_num = six_step_gray(mean(x));
            if (dice_num == 1) draw_one(i, j);
            if (dice_num == 2) draw_two(i, j);
            if (dice_num == 3) draw_three(i, j);
            if (dice_num == 4) draw_four(i, j);
            if (dice_num == 5) draw_five(i, j);
            if (dice_num == 6) draw_six(i, j);      
        }
    }  
}

void draw_one(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
}

void draw_two(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

void draw_three(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

void draw_four(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);  
}

void draw_five(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+8, j*patch_h+8, pip_size, pip_size);
}

void draw_six(int i, int j) {
    fill(0);
    rect(i*patch_w, j*patch_h, 16, 16);
    fill(255);
    ellipse(i*patch_w+3, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+3, j*patch_h+13, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+3, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+8, pip_size, pip_size);
    ellipse(i*patch_w+13, j*patch_h+13, pip_size, pip_size);
}

// Impose 6 step gray palette
int six_step_gray(int x) {
    if (0 &lt;= x &amp;#038;&amp; x &lt;= 41)
        return 1;
    if (41 &lt; x &amp;#038;&amp; x &lt;= 83)
        return 2;
    if (83 &lt; x &amp;#038;&amp; x &lt;= 124)
        return 3;
    if (124 &lt; x &amp;#038;&amp; x &lt;= 165)
        return 4;
    if (165 &lt; x &amp;#038;&amp; x &lt;= 206)
        return 5;
    if (x &lt; 206 &amp;#038;&amp; x &lt;= 247)
        return 6;
    else
        return 6;
}

// Blend rgb channels
int rgb2gray(int argb) { 
    int _alpha = (argb &gt;&gt; 24) &amp;#038; 0xFF;
    int _red = (argb &gt;&gt; 16) &amp;#038; 0xFF;
    int _green = (argb &gt;&gt; 8 ) &amp;#038; 0xFF;
    int _blue = (argb) &amp;#038; 0xFF;

    return int(0.3*_red + 0.59*_green + 0.11*_blue);
}

// Calculates the average of an integer array
int mean(int[] x) {
    float m = 0;
    for (int i=0; i &lt; x.length; ++i) {
        m += x[i];
    }
    m = m/x.length;  
    return int(m);
}
&lt;/pre&gt;&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492405/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492405/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Wed, 30 Nov 2011 02:12:02 +0800</pubDate><author>yuanyi</author><comments>http://heikezhi.com/2011/11/29/dice-portrait/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1832</guid><dc:creator>yuanyi</dc:creator><fs:srclink>http://heikezhi.com/2011/11/29/dice-portrait/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492405/6713895</fs:itemid></item><item><title>那些你希望在N年前就掌握的命令</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492406/6713895/1/item.html</link><content:encoded>&lt;p&gt;有人在Reddit上发帖询问：&lt;a href=&quot;http://www.reddit.com/r/linux/comments/mi80x/give_me_that_one_command_you_wish_you_knew_years/&quot;&gt;有没有哪条命令是你希望自己在几年前就掌握的&lt;/a&gt;，下面的回复中提到的一些命令，看看你知道几个，当然，也欢迎补充你的。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;units&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;单位转换程序：&lt;/p&gt;
&lt;pre&gt;
You have: cm^3
You want: gallons
      * 0.00026417205
      / 3785.4118

You have: 1|2 inch
You want: cm
      * 1.27
      / 0.78740157
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;后台运行命令&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;如果你希望让某条命令在退出SSH后依然保持运行状态，ZSH用户可以在命令后加上&amp;#038;|或是&amp;#038;!，也可以设置Shell的nohup属性，这样所有后台任务都将忽略hangup信号。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;取得运行中进程的输出&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;
~$ touch log
~$ gdb -p 22499
(gdb) p close(1) # This closes the stdout of the running process
(gdb) p open(&quot;/home/.../log&quot;, 1) # This will open the log-file with O_WRITE (gdb) c
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;fc&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;fc命令会根据$EDITOR变量打开一个编辑器，让你编辑上一条命令，你还可以使用Ctrl-x,Ctrl-e来编辑当前行的命令。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;bindkey&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;绑定键盘快捷键，执行下面这条命令后，你就可以使用Ctrl-j回到上一条命令：&lt;/p&gt;
&lt;pre&gt;
bindkey &quot;^j&quot; history-search-backward
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;lsof&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;关于lsof，可以查看我们之前的一篇介绍文章&quot;&lt;a href=&quot;http://heikezhi.com/2011/06/19/swiss-army-knife-of-unix-debugging-lsof/&quot;&gt;Unix调试的瑞士军刀：lsof&lt;/a&gt;&quot;。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;man ascii&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;以8进制，10进制以及16进制显示ASCII码表&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;^find^replace&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;
$ /etc/init.d/foo stop
$ ^stop^start
&lt;/pre&gt;
&lt;p&gt;下面是一条等价命令：&lt;/p&gt;
&lt;pre&gt;
!:s/foo/bar  # 替换第一个
!:gs/foo/bar # 替换全部
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;cd -&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;看个例子：&lt;/p&gt;
&lt;pre&gt;
cd /some/complicated/directory
cd ~/foo cp some_file `cd -`
&lt;/pre&gt;
&lt;p&gt;更简单的：&lt;/p&gt;
&lt;pre&gt;
cp some_file ~-
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;:w ! sudo tee %&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;当你在vi中修改了半天配置文件，然后发现没有写权限，没有比这更令人感到挫败了，此时你需要这条命令。&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;TermKit: 下一代的Mac命令行/终端程序&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F05%2F18%2Ftermkit-next-gen-terminal-command-line-app-for-mac%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F28%2Fone-command-you-wish-you-knew-years%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/05/18/8913429.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;TermKit: 下一代的Mac命令行/终端程序&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;使用命令行界面vmc部署程序到VMware Cloud Foundry&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F06%2F11%2Fdeploying-applications-with-the-vmware-cloud-foundry-cli%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F28%2Fone-command-you-wish-you-knew-years%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/06/11/11802220.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;使用命令行界面vmc部署程序到VMware Cloud Foundry&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;想找好工作？那就别再投简历了&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F11%2Fwhat-i-learned-today-never-apply-for-a-job%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F28%2Fone-command-you-wish-you-knew-years%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/07/12/17104842.jpg&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;想找好工作？那就别再投简历了&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;世界上最有趣的开发者&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F05%2F03%2Fthe-most-interesting-developer-in-the-world%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F28%2Fone-command-you-wish-you-knew-years%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/05/04/7537330.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;世界上最有趣的开发者&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492406/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492406/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/11/28/one-command-you-wish-you-knew-years/feed/</wfw:commentRss><slash:comments>8</slash:comments><description>有人在Reddit上发帖询问：&lt;a href=&quot;http://www.reddit.com/r/linux/comments/mi80x/give_me_that_one_command_you_wish_you_knew_years/&quot;&gt;有没有哪条命令是你希望自己在几年前就掌握的&lt;/a&gt;，下面的回复中提到的一些命令，看看你知道几个，当然，也欢迎补充你的。

&lt;strong&gt;units&lt;/strong&gt;

单位转换程序：

&lt;pre&gt;
You have: cm^3
You want: gallons
      * 0.00026417205
      / 3785.4118

You have: 1&amp;#124;2 inch
You want: cm
      * 1.27
      / 0.78740157
&lt;/pre&gt;

&lt;strong&gt;后台运行命令&lt;/strong&gt;

如果你希望让某条命令在退出SSH后依然保持运行状态，ZSH用户可以在命令后加上&amp;#038;&amp;#124;或是&amp;#038;!，也可以设置Shell的nohup属性，这样所有后台任务都将忽略hangup信号。

&lt;strong&gt;取得运行中进程的输出&lt;/strong&gt;

&lt;pre&gt;
~$ touch log
~$ gdb -p 22499
(gdb) p close(1) # This closes the stdout of the running process
(gdb) p open(&quot;/home/.../log&quot;, 1) # This will open the log-file with O_WRITE (gdb) c
&lt;/pre&gt;

&lt;strong&gt;fc&lt;/strong&gt;

fc命令会根据$EDITOR变量打开一个编辑器，让你编辑上一条命令，你还可以使用Ctrl-x,Ctrl-e来编辑当前行的命令。

&lt;strong&gt;bindkey&lt;/strong&gt;

绑定键盘快捷键，执行下面这条命令后，你就可以使用Ctrl-j回到上一条命令：

&lt;pre&gt;
bindkey &quot;^j&quot; history-search-backward
&lt;/pre&gt;

&lt;strong&gt;lsof&lt;/strong&gt;

关于lsof，可以查看我们之前的一篇介绍文章&quot;&lt;a href=&quot;http://heikezhi.com/2011/06/19/swiss-army-knife-of-unix-debugging-lsof/&quot;&gt;Unix调试的瑞士军刀：lsof&lt;/a&gt;&quot;。

&lt;strong&gt;man ascii&lt;/strong&gt;

以8进制，10进制以及16进制显示ASCII码表

&lt;strong&gt;^find^replace&lt;/strong&gt;

&lt;pre&gt;
$ /etc/init.d/foo stop
$ ^stop^start
&lt;/pre&gt;

下面是一条等价命令：

&lt;pre&gt;
!:s/foo/bar  # 替换第一个
!:gs/foo/bar # 替换全部
&lt;/pre&gt;

&lt;strong&gt;cd -&lt;/strong&gt;

看个例子：

&lt;pre&gt;
cd /some/complicated/directory
cd ~/foo cp some_file `cd -`
&lt;/pre&gt;

更简单的：

&lt;pre&gt;
cp some_file ~-
&lt;/pre&gt;

&lt;strong&gt;:w ! sudo tee %&lt;/strong&gt;

当你在vi中修改了半天配置文件，然后发现没有写权限，没有比这更令人感到挫败了，此时你需要这条命令。&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492406/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492406/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>分类？没有</category><pubDate>Mon, 28 Nov 2011 17:32:56 +0800</pubDate><author>yuanyi</author><comments>http://heikezhi.com/2011/11/28/one-command-you-wish-you-knew-years/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1810</guid><dc:creator>yuanyi</dc:creator><fs:srclink>http://heikezhi.com/2011/11/28/one-command-you-wish-you-knew-years/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492406/6713895</fs:itemid></item><item><title>创建你的第一个Gem</title><link>http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492407/6713895/1/item.html</link><content:encoded>&lt;p&gt;原文作者：John McAliley，&lt;a href=&quot;http://rubysource.com/creating-your-first-gem/&quot;&gt;原文地址&lt;/a&gt;，翻译：Pilipala&lt;/p&gt;
&lt;p&gt;你在Ruby世界看到到处都是Gem。他们几乎是所有的Ruby应用程序的核心。我承认当我试着建立第一个Gem的时候，我有点战战兢兢。但我很快就发现了，这玩意简单得要死。在这个博客系列中，我将涵盖从头开始创建一个Gem的基础，然后转移到更高级的主题，包括Gem生成工具和Rails引擎。首先，对于你们这些Ruby有新手，第一个问题是：什么是Gem？简而言之，它是打包的Ruby代码。在最低限度，Gem包括一个Ruby文件和一个gemspec。gemspec（Gem规范）描述Gem信息，RubyGems包管理器需要这些信息安装Gem。&lt;/p&gt;
&lt;p&gt;RubyGems包管理器可以下载，并安装Gem到你的系统，并允许你在其他Ruby程序中使用这些Gem。Ruby 1.9默认安装RubyGems。如果你使用的是Ruby 1.9之前的版本，你可以在&lt;a href=&quot;http://rubygems.org/pages/download&quot;&gt;这里&lt;/a&gt;下载RubyGems。在Ruby 1.9之前版本的应用程序中使用RubyGems，你需要在你的应用程序，加入这一行 ：&lt;/p&gt;
&lt;pre&gt;require 'rubygems'&lt;/pre&gt;
&lt;p&gt;Ruby 1.9中不需要这么做，因为RubyGems已经被包含在Ruby 1.9中。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Gem规范(Gem Specification)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;正如我在前面提到，Gem的规范描述了Gem。让我们看看一个基本的gemspec文件：&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
Gem::Specification.new do |s|
  s.name = %q{my_gem}
  s.version = &quot;0.0.1&quot;
  s.date = %q{2011-09-29}
  s.summary = %q{my_gem is an awesome gem}
  s.files = [
    &quot;Gemfile&quot;,
    &quot;Rakefile&quot;,
    &quot;VERSION&quot;,
    &quot;lib/my_gem.rb&quot;
  ]
  s.require_paths = [&quot;lib&quot;]
end&lt;/pre&gt;
&lt;p&gt;gemspec是一个相当简单的文件，描述你的Gem的各个方面。在上面的例子gemspec中的文件中，我只列出必需的属性。&lt;br /&gt;
前4个属性是不言自明。“文件”属性中列出包括在Gem中的所有文件。&lt;br /&gt;
“require_paths”属性指定的目录，其中包含Ruby文件应该被这个Gem所加载。gemspec所用到的完整属性列表，请参考&lt;a href=&quot;http://docs.rubygems.org/read/chapter/20&quot;&gt;这里&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;这是一些简单的基础知识，现在让我们切入正题，寻找更有趣的东西。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;从头开始创建一个Gem&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1、建立Gem的基本文件结构：&lt;/p&gt;
&lt;p&gt;输入shell指令,并创建Gem需要的目录：&lt;/p&gt;
&lt;pre&gt;
$ mkdir awesome_gem
$ cd awesome_gem
$ mkdir lib
&lt;/pre&gt;
&lt;p&gt;就这样！你需要为你的Gem和一个lib目录来存放你的Ruby文件的根目录。&lt;/p&gt;
&lt;p&gt;2、创建的gemspec&lt;/p&gt;
&lt;p&gt;我们将使用上一节gemspec文件作为模板。创建一个名为“awesome_gem.gemspec”在你的Gem的根目录中。然后添加一些代码，以成为一个有效的gemspec：&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
Gem::Specification.new do |s|
  s.name = %q{awesome_gem}
  s.version = &quot;0.0.0&quot;
  s.date = %q{2011-09-29}
  s.summary = %q{awesome_gem is the best}
  s.files = [
    &quot;lib/awesome_gem.rb&quot;
  ]
  s.require_paths = [&quot;lib&quot;]
end&lt;/pre&gt;
&lt;p&gt;这个文件包含了一个gemspec标准所需的属性，并且显示我们有一个“lib”目录。在lib目录中的文件“awesome_gem.rb”将被用来保存这个Gem的Ruby代码。&lt;/p&gt;
&lt;p&gt;3、添加一些代码&lt;/p&gt;
&lt;p&gt;为了简单起见，我们将只用一个Ruby文件在这个Gem里：/lib/awesome_gem.rb，你会看到这种结构类型在大多数你遇到的Gem中。 “lib”内的根文件通常会与Gem的名称相匹配。本例中，“awesome_gem”和“/lib/awesome_gem.rb” 。&lt;/p&gt;
&lt;p&gt;继续创建这个文件，添加下面的代码：&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
module AwesomeGem
  class WhoIs
    def self.awesome?
      puts &quot;YOU ARE AWESOME!!&quot;
    end
  end
end&lt;/pre&gt;
&lt;p&gt;这虽然不是什么改变世界的代码，至少， awesome? 方法让你感觉不错。这个Gem将允许你在其他Ruby程序里面使用 WhoIs 的类方法awesome?。&lt;/p&gt;
&lt;p&gt;正如我在第一部分中提到，RubyGems的将安装Gem在你的应用程序中，并使用Gem中的类。&lt;/p&gt;
&lt;p&gt;4、生成的Gem文件&lt;/p&gt;
&lt;p&gt;现在，你有一些很棒的代码，你将要创建一个Gem，所以你可以在另一个Ruby程序用这些代码。RubyGems提供命令，让你创建一个Gem。输入下面命令在Gem的根目录：&lt;/p&gt;
&lt;pre&gt;
$ gem build awesome_gem.gemspec
&lt;/pre&gt;
&lt;p&gt;此命令将建立Gem和输出Gem文件，将包括版本号在文件名中。由于gemspec中版本属性的值是“0.0.0”，Gem的文件将被命名为awesome_gem-0.0.0。&lt;br /&gt;
你应该看到下面的输出和对一些缺少的属性警告：&lt;/p&gt;
&lt;pre&gt;
Successfully built RubyGem
Name: awesome_gem
Version: 0.0.0
File: awesome_gem-0.0.0.gem
&lt;/pre&gt;
&lt;p&gt;你可以忽略这些警告，继续在系统上安装这个Gem。请注意，Gem文件被创建在当前目录中。&lt;/p&gt;
&lt;p&gt;5、安装Gem&lt;/p&gt;
&lt;p&gt;现在，你有一个Gem文件，你可以使用RubyGems安装这个Gem到你的计算机上。通常情况下，你安装的Gem来源于外部，但不限于此。如果你有机会得到Gem文件，你可以通过指定Gem文件的位置将其安装在本地。下面的命令在本地安装awesome_gem.gem：&lt;/p&gt;
&lt;pre&gt;gem install awesome_gem.gemspec&lt;/pre&gt;
&lt;p&gt;你应该得到以下输出：&lt;/p&gt;
&lt;pre&gt;
Successfully installed awesome_gem-0.0.0
1 gem installed
Installing ri documentation for awesome_gem-0.0.0...
Installing RDoc documentation for awesome_gem-0.0.0...&lt;/pre&gt;
&lt;p&gt;耶！你刚创建了Gem！这个Gem现在已经安装在你的系统，并准备在另一个Ruby程序中使用。&lt;/p&gt;
&lt;p&gt;6、Gem的另一个Ruby程序&lt;/p&gt;
&lt;p&gt;创建一个新的Ruby文件将用来测试我们的Gem。让我们叫它“be_awesome.rb”。你可以在你的系统中的任何位置创建此文件，然后添加下面的代码，所以我们可以使用Gem中的“awesom?”类方法。用 require “awesome_gem”，RubyGems将能够找到Gem，把这个类提供给你的程序。然后你只需要调用它。以下是代码：&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
require 'awesome_gem'
AwesomeGem::WhoIs.awesome?&lt;/pre&gt;
&lt;p&gt;现在你可以运行Ruby程序和测试你新创建的Gem，看看你是如何awesome的。通过命令行输入：&lt;/p&gt;
&lt;pre&gt;ruby be_awesome.rb&lt;/pre&gt;
&lt;p&gt;你应该看到在你的shell下面的输出：&lt;/p&gt;
&lt;pre&gt;YOUR ARE AWESOME!&lt;/pre&gt;
&lt;p&gt;恭喜你，你只要在程序中使用你的新的Gem！虽然它还不值得放在GitHub上，跟朋友吹嘘，但是， 你还是学会了如何从头开始创建一个Gem，并在另一个程序中使用它。现在，你可以继续前进，追求更大的进步。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;结论&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;虽然本教程是相当简单，只涉及创建一个基本的Gem，我认为它对新的Gem开发者仍然很重要。&lt;/p&gt;
&lt;p&gt;基础知识给你一个进入高级的主题良好基础。平时，我用Jeweler去创造Gem，这的确是一个功能强大的工具， 但我觉得手工从头创建一个Gem之前就用这样的生成工具，可能是有害的。&lt;/p&gt;
&lt;p&gt;你需要了解如何构建一个Gem的最简单的形式，才可以理解像Jeweler这样的生成工具的背后是什么。虽然我建议在你第一次学习Gem开发时，手工从头创建一个Gem。但是，当你理解了基础知识，就没什么理由拒绝使用生成器了。&lt;/p&gt;
&lt;p&gt;生成器可以节省很多时间，因为他们给你一个很好的起始架构。本系列的下一个博客后，将有关Gem的开发，以及更高级的主题，诸如：如何使用生成工具来开始你的Gem开发。以后的文章将解释如何开发Ruby on Rails的Gem。&lt;/p&gt;
&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;
  
&lt;div class=&quot;wp_license&quot;&gt;
&lt;p&gt;&lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;&lt;img src=&quot;http://i.creativecommons.org/l/by/3.0//88x31.png&quot; alt=&quot;Creative Commons Attribution 3.0 Unported&quot; class=&quot;alignleft&quot; style=&quot;margin-top:4px;&quot; /&gt;
&lt;/a&gt;此作品采用 &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by/3.0/&quot;&gt;Creative Commons Attribution 3.0 Unported&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;table class=&quot;wumii-related-items&quot; cellspacing=&quot;0&quot; cellpadding=&quot;3&quot; border=&quot;0&quot;  style=&quot;clear: both;&quot;&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot;&gt;&lt;b&gt;&lt;font size=&quot;-1&quot;  style=&quot;display: block !important; padding: 20px 0 5px !important;&quot;&gt;无觅猜您也喜欢：&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
    
        &lt;tr&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;Github第一年教给我的10堂课&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F04%2F03%2Ften-lessons-from-githubs-first-year%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F15%2F%25E5%2588%259B%25E5%25BB%25BA%25E4%25BD%25A0%25E7%259A%2584%25E7%25AC%25AC%25E4%25B8%2580%25E4%25B8%25AAgem%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;Github第一年教给我的10堂课&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;10个你不曾知道Steve Jobs的故事（第一部分）&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F03%2F22%2F10%25E4%25B8%25AA%25E4%25BD%25A0%25E4%25B8%258D%25E6%259B%25BE%25E7%259F%25A5%25E9%2581%2593steve-jobs%25E7%259A%2584%25E6%2595%2585%25E4%25BA%258B%25EF%25BC%2588%25E7%25AC%25AC%25E4%25B8%2580%25E9%2583%25A8%25E5%2588%2586%25EF%25BC%2589%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F15%2F%25E5%2588%259B%25E5%25BB%25BA%25E4%25BD%25A0%25E7%259A%2584%25E7%25AC%25AC%25E4%25B8%2580%25E4%25B8%25AAgem%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/images/blogWidget/wordpress_default.gif&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;10个你不曾知道Steve Jobs的故事（第一部分）&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;84个纯CSS GUI图标&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F07%2F12%2Fpure-css-gui-icons%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F15%2F%25E5%2588%259B%25E5%25BB%25BA%25E4%25BD%25A0%25E7%259A%2584%25E7%25AC%25AC%25E4%25B8%2580%25E4%25B8%25AAgem%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/07/21/18260031.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;84个纯CSS GUI图标&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
                &lt;td width=&quot;102&quot; valign=&quot;top&quot; style=&quot;padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;&quot;&gt;
                    &lt;a target=&quot;_blank&quot; title=&quot;Taazr: 监控并优化你的Javascript&quot; style=&quot;text-decoration: none !important; cursor: pointer !important;&quot; href=&quot;http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fheikezhi.com%2F2011%2F08%2F07%2Ftaazr-optimize-and-monitor-your-javascript%2F&amp;from=http%3A%2F%2Fheikezhi.com%2F2011%2F11%2F15%2F%25E5%2588%259B%25E5%25BB%25BA%25E4%25BD%25A0%25E7%259A%2584%25E7%25AC%25AC%25E4%25B8%2580%25E4%25B8%25AAgem%2F&quot;&gt;
                        &lt;img style=&quot;margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;&quot; src=&quot;http://static.wumii.com/site_images/2011/08/07/21533855.png&quot; width=&quot;96px&quot; height=&quot;96px&quot; /&gt;&lt;br /&gt;
                        &lt;font size=&quot;-1&quot; color=&quot;#333333&quot; style=&quot;display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;&quot;&gt;Taazr: 监控并优化你的Javascript&lt;/font&gt;
                    &lt;/a&gt;
                &lt;/td&gt;
        &lt;/tr&gt;
    
    &lt;tr&gt;
        &lt;td colspan=&quot;4&quot; align=&quot;right&quot;&gt;
            &lt;a style=&quot;text-decoration: none !important;&quot; href=&quot;http://www.wumii.com/widget/relatedItems&quot; target=&quot;_blank&quot; title=&quot;无觅相关文章插件&quot;&gt;
                &lt;font size=&quot;-1&quot; color=&quot;#bbbbbb&quot; style=&quot;display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;&quot;&gt;无觅&lt;/font&gt;
            &lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492407/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492407/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</content:encoded><wfw:commentRss>http://heikezhi.com/2011/11/15/%e5%88%9b%e5%bb%ba%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aagem/feed/</wfw:commentRss><slash:comments>6</slash:comments><description>原文作者：John McAliley，&lt;a href=&quot;http://rubysource.com/creating-your-first-gem/&quot;&gt;原文地址&lt;/a&gt;，翻译：Pilipala

你在Ruby世界看到到处都是Gem。他们几乎是所有的Ruby应用程序的核心。我承认当我试着建立第一个Gem的时候，我有点战战兢兢。但我很快就发现了，这玩意简单得要死。在这个博客系列中，我将涵盖从头开始创建一个Gem的基础，然后转移到更高级的主题，包括Gem生成工具和Rails引擎。首先，对于你们这些Ruby有新手，第一个问题是：什么是Gem？简而言之，它是打包的Ruby代码。在最低限度，Gem包括一个Ruby文件和一个gemspec。gemspec（Gem规范）描述Gem信息，RubyGems包管理器需要这些信息安装Gem。

RubyGems包管理器可以下载，并安装Gem到你的系统，并允许你在其他Ruby程序中使用这些Gem。Ruby 1.9默认安装RubyGems。如果你使用的是Ruby 1.9之前的版本，你可以在&lt;a href=&quot;http://rubygems.org/pages/download&quot;&gt;这里&lt;/a&gt;下载RubyGems。在Ruby 1.9之前版本的应用程序中使用RubyGems，你需要在你的应用程序，加入这一行 ：

&lt;pre&gt;require 'rubygems'&lt;/pre&gt;

Ruby 1.9中不需要这么做，因为RubyGems已经被包含在Ruby 1.9中。

&lt;strong&gt;Gem规范(Gem Specification)&lt;/strong&gt;

正如我在前面提到，Gem的规范描述了Gem。让我们看看一个基本的gemspec文件：

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
Gem::Specification.new do &amp;#124;s&amp;#124;
  s.name = %q{my_gem}
  s.version = &quot;0.0.1&quot;
  s.date = %q{2011-09-29}
  s.summary = %q{my_gem is an awesome gem}
  s.files = [
    &quot;Gemfile&quot;,
    &quot;Rakefile&quot;,
    &quot;VERSION&quot;,
    &quot;lib/my_gem.rb&quot;
  ]
  s.require_paths = [&quot;lib&quot;]
end&lt;/pre&gt;



gemspec是一个相当简单的文件，描述你的Gem的各个方面。在上面的例子gemspec中的文件中，我只列出必需的属性。
前4个属性是不言自明。“文件”属性中列出包括在Gem中的所有文件。
“require_paths”属性指定的目录，其中包含Ruby文件应该被这个Gem所加载。gemspec所用到的完整属性列表，请参考&lt;a href=&quot;http://docs.rubygems.org/read/chapter/20&quot;&gt;这里&lt;/a&gt;。

这是一些简单的基础知识，现在让我们切入正题，寻找更有趣的东西。

&lt;strong&gt;从头开始创建一个Gem&lt;/strong&gt;

1、建立Gem的基本文件结构：

输入shell指令,并创建Gem需要的目录：

&lt;pre&gt;
$ mkdir awesome_gem
$ cd awesome_gem
$ mkdir lib
&lt;/pre&gt;

就这样！你需要为你的Gem和一个lib目录来存放你的Ruby文件的根目录。

2、创建的gemspec

我们将使用上一节gemspec文件作为模板。创建一个名为“awesome_gem.gemspec”在你的Gem的根目录中。然后添加一些代码，以成为一个有效的gemspec：

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
Gem::Specification.new do &amp;#124;s&amp;#124;
  s.name = %q{awesome_gem}
  s.version = &quot;0.0.0&quot;
  s.date = %q{2011-09-29}
  s.summary = %q{awesome_gem is the best}
  s.files = [
    &quot;lib/awesome_gem.rb&quot;
  ]
  s.require_paths = [&quot;lib&quot;]
end&lt;/pre&gt;

这个文件包含了一个gemspec标准所需的属性，并且显示我们有一个“lib”目录。在lib目录中的文件“awesome_gem.rb”将被用来保存这个Gem的Ruby代码。

3、添加一些代码

为了简单起见，我们将只用一个Ruby文件在这个Gem里：/lib/awesome_gem.rb，你会看到这种结构类型在大多数你遇到的Gem中。 “lib”内的根文件通常会与Gem的名称相匹配。本例中，“awesome_gem”和“/lib/awesome_gem.rb” 。

继续创建这个文件，添加下面的代码：

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
module AwesomeGem
  class WhoIs
    def self.awesome?
      puts &quot;YOU ARE AWESOME!!&quot;
    end
  end
end&lt;/pre&gt;

这虽然不是什么改变世界的代码，至少， awesome? 方法让你感觉不错。这个Gem将允许你在其他Ruby程序里面使用 WhoIs 的类方法awesome?。

正如我在第一部分中提到，RubyGems的将安装Gem在你的应用程序中，并使用Gem中的类。

4、生成的Gem文件

现在，你有一些很棒的代码，你将要创建一个Gem，所以你可以在另一个Ruby程序用这些代码。RubyGems提供命令，让你创建一个Gem。输入下面命令在Gem的根目录：

&lt;pre&gt;
$ gem build awesome_gem.gemspec
&lt;/pre&gt;

此命令将建立Gem和输出Gem文件，将包括版本号在文件名中。由于gemspec中版本属性的值是“0.0.0”，Gem的文件将被命名为awesome_gem-0.0.0。
你应该看到下面的输出和对一些缺少的属性警告：

&lt;pre&gt;
Successfully built RubyGem
Name: awesome_gem
Version: 0.0.0
File: awesome_gem-0.0.0.gem
&lt;/pre&gt;

你可以忽略这些警告，继续在系统上安装这个Gem。请注意，Gem文件被创建在当前目录中。

5、安装Gem

现在，你有一个Gem文件，你可以使用RubyGems安装这个Gem到你的计算机上。通常情况下，你安装的Gem来源于外部，但不限于此。如果你有机会得到Gem文件，你可以通过指定Gem文件的位置将其安装在本地。下面的命令在本地安装awesome_gem.gem：

&lt;pre&gt;gem install awesome_gem.gemspec&lt;/pre&gt;

你应该得到以下输出：

&lt;pre&gt;
Successfully installed awesome_gem-0.0.0
1 gem installed
Installing ri documentation for awesome_gem-0.0.0...
Installing RDoc documentation for awesome_gem-0.0.0...&lt;/pre&gt;

耶！你刚创建了Gem！这个Gem现在已经安装在你的系统，并准备在另一个Ruby程序中使用。

6、Gem的另一个Ruby程序

创建一个新的Ruby文件将用来测试我们的Gem。让我们叫它“be_awesome.rb”。你可以在你的系统中的任何位置创建此文件，然后添加下面的代码，所以我们可以使用Gem中的“awesom?”类方法。用 require “awesome_gem”，RubyGems将能够找到Gem，把这个类提供给你的程序。然后你只需要调用它。以下是代码：

&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
require 'awesome_gem'
AwesomeGem::WhoIs.awesome?&lt;/pre&gt;

现在你可以运行Ruby程序和测试你新创建的Gem，看看你是如何awesome的。通过命令行输入：

&lt;pre&gt;ruby be_awesome.rb&lt;/pre&gt;

你应该看到在你的shell下面的输出：

&lt;pre&gt;YOUR ARE AWESOME!&lt;/pre&gt;

恭喜你，你只要在程序中使用你的新的Gem！虽然它还不值得放在GitHub上，跟朋友吹嘘，但是， 你还是学会了如何从头开始创建一个Gem，并在另一个程序中使用它。现在，你可以继续前进，追求更大的进步。

&lt;strong&gt;结论&lt;/strong&gt;

虽然本教程是相当简单，只涉及创建一个基本的Gem，我认为它对新的Gem开发者仍然很重要。

基础知识给你一个进入高级的主题良好基础。平时，我用Jeweler去创造Gem，这的确是一个功能强大的工具， 但我觉得手工从头创建一个Gem之前就用这样的生成工具，可能是有害的。

你需要了解如何构建一个Gem的最简单的形式，才可以理解像Jeweler这样的生成工具的背后是什么。虽然我建议在你第一次学习Gem开发时，手工从头创建一个Gem。但是，当你理解了基础知识，就没什么理由拒绝使用生成器了。

生成器可以节省很多时间，因为他们给你一个很好的起始架构。本系列的下一个博客后，将有关Gem的开发，以及更高级的主题，诸如：如何使用生成工具来开始你的Gem开发。以后的文章将解释如何开发Ruby on Rails的Gem。&lt;p&gt;想和我们一道传播黑客精神？&lt;a href=&quot;http://heikezhi.com/join&quot;&gt;快来加入吧！&lt;/a&gt;&lt;/p&gt;&lt;img src=&quot;http://www1.feedsky.com/t1/633492407/heikezhi/feedsky/s.gif?r=http://item.feedsky.com/~feedsky/heikezhi/~8608072/633492407/6713895/1/item.html&quot; border=&quot;0&quot; height=&quot;0&quot; width=&quot;0&quot; style=&quot;position:absolute&quot; /&gt;</description><category>编程</category><pubDate>Wed, 16 Nov 2011 14:37:21 +0800</pubDate><author>pilipala</author><comments>http://heikezhi.com/2011/11/15/%e5%88%9b%e5%bb%ba%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aagem/#comments</comments><guid isPermaLink="false">http://heikezhi.com/?p=1707</guid><dc:creator>pilipala</dc:creator><fs:srclink>http://heikezhi.com/2011/11/15/%e5%88%9b%e5%bb%ba%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aagem/</fs:srclink><fs:srcfeed>http://heikezhi.com/feed/</fs:srcfeed><fs:itemid>feedsky/heikezhi/~8608072/633492407/6713895</fs:itemid></item></channel></rss>
