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

<channel>
	<title>流氓花园</title>
	<atom:link href="http://huangdonghai.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://huangdonghai.com</link>
	<description>Huang Donghai and his friends</description>
	<lastBuildDate>Mon, 10 Oct 2011 05:44:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>呓语</title>
		<link>http://huangdonghai.com/yiyu/</link>
		<comments>http://huangdonghai.com/yiyu/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 05:44:39 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[五味杂陈]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=309</guid>
		<description><![CDATA[我们升斗小民，微不足道，如路边的蚂蚁，粪缸里的蛆虫，不过是苟且图存，既无行善的能力，也无作恶的力量，说话不过像是疯子的呓语，是无人肯听的，传播几米就会消散在风中，所谓群众的呼声，不过是被呼声而已。生存着不过是被人践踏，被人口红利，吸着本已不多的血，无声无息并不会有老爷大人注目; 死也如风吹残叶，旋几下落在地上，不几天就化为了尘土，悲伤的不过是几个亲友，生命就弥散在了无边无际无来无去的宇宙中。]]></description>
			<content:encoded><![CDATA[<p>我们升斗小民，微不足道，如路边的蚂蚁，粪缸里的蛆虫，不过是苟且图存，既无行善的能力，也无作恶的力量，说话不过像是疯子的呓语，是无人肯听的，传播几米就会消散在风中，所谓群众的呼声，不过是被呼声而已。生存着不过是被人践踏，被人口红利，吸着本已不多的血，无声无息并不会有老爷大人注目; 死也如风吹残叶，旋几下落在地上，不几天就化为了尘土，悲伤的不过是几个亲友，生命就弥散在了无边无际无来无去的宇宙中。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/yiyu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>王度庐《宝剑金钗》序</title>
		<link>http://huangdonghai.com/baojianjincai-xu/</link>
		<comments>http://huangdonghai.com/baojianjincai-xu/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 20:58:42 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[五味杂陈]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/%e5%ae%9e%e6%97%b6%e5%85%a8%e5%b1%80%e5%85%89%e7%85%a7%e7%a0%94%e7%a9%b6/</guid>
		<description><![CDATA[昔人不愿得千金，惟愿得季布一诺，侠者感人之力可谓大矣。春秋战国秦汉之际，一时豪俊，如重交之管鲍，仗义之杵臼程婴，好客之四公子，纾人急难之郭解朱家，莫不烈烈有侠士风范，为世人之所倾慕。迨于后世，古道渐衰，人情险诈，奸猾并起，才智之士又争赴仕途，遂使一脉侠风荡然寡存，惟于江湖闾里之间，有时尚可求到，然亦微矣！余谓任侠为中国旧有之精神，正如日本之武士道，欧洲中世纪之骑士。倘能拾摭旧闻，不涉神怪，不诲盗淫，著成一书，虽未必便挽颓风，然寒窗苦寂，持卷快谈，亦足以浮一大白也。频年饥驱远游，秦楚燕赵之间，跋涉殆遍，屡经坎坷，备尝世味，益感人间侠士之不可无。兼以情场爱迹，所见亦多，大 都财色相欺，优柔自误。因是，又拟以任侠与爱情相并言之，庶使英雄肝胆亦有旖旎之思，儿女痴情不尽娇柔之态，此《宝剑金钗》之所由作也。]]></description>
			<content:encoded><![CDATA[<p>昔人不愿得千金，惟愿得季布一诺，侠者感人之力可谓大矣。春秋战国秦汉之际，一时豪俊，如重交之管鲍，仗义之杵臼程婴，好客之四公子，纾人急难之郭解朱家，莫不烈烈有侠士风范，为世人之所倾慕。迨于后世，古道渐衰，人情险诈，奸猾并起，才智之士又争赴仕途，遂使一脉侠风荡然寡存，惟于江湖闾里之间，有时尚可求到，然亦微矣！余谓任侠为中国旧有之精神，正如日本之武士道，欧洲中世纪之骑士。倘能拾摭旧闻，不涉神怪，不诲盗淫，著成一书，虽未必便挽颓风，然寒窗苦寂，持卷快谈，亦足以浮一大白也。频年饥驱远游，秦楚燕赵之间，跋涉殆遍，屡经坎坷，备尝世味，益感人间侠士之不可无。兼以情场爱迹，所见亦多，大 都财色相欺，优柔自误。因是，又拟以任侠与爱情相并言之，庶使英雄肝胆亦有旖旎之思，儿女痴情不尽娇柔之态，此《宝剑金钗》之所由作也。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/baojianjincai-xu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macbook Air外接显示器开启ClearType</title>
		<link>http://huangdonghai.com/macbook-air-cleartype/</link>
		<comments>http://huangdonghai.com/macbook-air-cleartype/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 08:12:38 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[cleartype]]></category>
		<category><![CDATA[macbook]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/macbook-air-cleartype/</guid>
		<description><![CDATA[发现Macbook Air外接显示器的时候，默认是没有开启ClearType的，字体发虚的很厉害。 解决方法是在终端底下输入： defaults -currentHost write -globalDomain AppleFontSmoothing -int 2 就是强行把抗锯齿打开。]]></description>
			<content:encoded><![CDATA[<p>发现Macbook Air外接显示器的时候，默认是没有开启ClearType的，字体发虚的很厉害。</p>
<p>解决方法是在终端底下输入：</p>
<pre>defaults -currentHost write -globalDomain AppleFontSmoothing -int 2</pre>
<p>就是强行把抗锯齿打开。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/macbook-air-cleartype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone/iPod有时不能显示歌词的解决方法</title>
		<link>http://huangdonghai.com/iphone-cant-show-lyrics/</link>
		<comments>http://huangdonghai.com/iphone-cant-show-lyrics/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 20:10:27 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[歌词]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/iphone-cant-show-lyrics/</guid>
		<description><![CDATA[有时候明明mp3里嵌入了歌词的tag，但是iPhone/iPod里还是不能显示。经试验，发现是V2.4的ID3 Tag偶尔会有这种Bug。在iTunes里，选择相应的mp3文件，右键点击，选择Convert ID3 Tags，转成V2.3版的ID3 Tag，问题解决。]]></description>
			<content:encoded><![CDATA[<p>有时候明明mp3里嵌入了歌词的tag，但是iPhone/iPod里还是不能显示。经试验，发现是V2.4的ID3 Tag偶尔会有这种Bug。在iTunes里，选择相应的mp3文件，右键点击，选择Convert ID3 Tags，转成V2.3版的ID3 Tag，问题解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/iphone-cant-show-lyrics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>其兴也勃焉，其亡也忽焉</title>
		<link>http://huangdonghai.com/xing-wang/</link>
		<comments>http://huangdonghai.com/xing-wang/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 20:01:17 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[五味杂陈]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/xing-wang/</guid>
		<description><![CDATA[1945年，黄炎培以国民政府参政员的身份到访延安，在延安，他见到了共产党的领袖毛泽东。 毛泽东问：“任之先生，这几天通过你的所见所闻，感觉如何？” 黄炎培直言相答：“我生六十余年，耳闻的不说，所亲眼见到的，真所谓其兴也勃焉，其亡也忽焉，一人，一家，一团体，一地方，乃至一国，不少单位都没有能跳出这周期率的支配力。大凡初时聚精会神，没有一事不用心，没有一人不卖力，也许那时艰难困苦，只有从万死中觅取一生。既而环境渐渐好转了，精神也就渐渐放下了……总之没有能跳出这周期率。” 毛泽东答：“我们已经找到新路，我们能跳出这周期率。这条新路，就是民主。只有让人民来监督政府，政府才不敢松懈。只有人人起来负责，才不会人亡政息。” &#8212;&#8212;&#8212;&#8212; 挖65年的老坟，拭目以待。]]></description>
			<content:encoded><![CDATA[<p>1945年，黄炎培以国民政府参政员的身份到访延安，在延安，他见到了共产党的领袖毛泽东。</p>
<p>毛泽东问：“任之先生，这几天通过你的所见所闻，感觉如何？”</p>
<p>黄炎培直言相答：“我生六十余年，耳闻的不说，所亲眼见到的，真所谓其兴也勃焉，其亡也忽焉，一人，一家，一团体，一地方，乃至一国，不少单位都没有能跳出这周期率的支配力。大凡初时聚精会神，没有一事不用心，没有一人不卖力，也许那时艰难困苦，只有从万死中觅取一生。既而环境渐渐好转了，精神也就渐渐放下了……总之没有能跳出这周期率。”</p>
<p>毛泽东答：“我们已经找到新路，我们能跳出这周期率。这条新路，就是民主。只有让人民来监督政府，政府才不敢松懈。只有人人起来负责，才不会人亡政息。”</p>
<p>&#8212;&#8212;&#8212;&#8212;   <br />挖65年的老坟，拭目以待。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/xing-wang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HLSL to GLSL</title>
		<link>http://huangdonghai.com/hlsl-to-glsl/</link>
		<comments>http://huangdonghai.com/hlsl-to-glsl/#comments</comments>
		<pubDate>Sat, 22 May 2010 09:53:08 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[引擎开发]]></category>
		<category><![CDATA[GLSL]]></category>
		<category><![CDATA[HLSL]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/hlsl-to-glsl/</guid>
		<description><![CDATA[当年 OpenGL Shader 语言选择投票 Cg 没有通过，而让 3D labs 主导的 GLSL 成为了标准，真是一件大不幸的事件。要同时支持 D3D 和 OpenGL 的渲染引擎就很麻烦，往往得写 HLSL 和 GLSL 两套代码。我们知道，PC D3D、XBOX 360 和 PlayStation 3 都是用 HLSL(Cg)，当要移植到 OpenGL 时，就需要同样的代码 GLSL 也要写一套。 我们可以在 OpenGL 上用 nVidia 的 Cg Runtime 来解决这个问题。他可以用 HLSL 的语法来写 OpenGL 的 Shader。但是 Cg Runtime 也有他的缺点：1. 它很庞大，2. 他在 ATi 的显卡上性能不行，3. 他不支持 OpenGL ES 等等。FarCry 1，Axon [...]]]></description>
			<content:encoded><![CDATA[<p>当年 OpenGL Shader 语言选择投票 Cg 没有通过，而让 3D labs 主导的 GLSL 成为了标准，真是一件大不幸的事件。要同时支持 D3D 和 OpenGL 的渲染引擎就很麻烦，往往得写 HLSL 和 GLSL 两套代码。我们知道，PC D3D、XBOX 360 和 PlayStation 3 都是用 HLSL(Cg)，当要移植到 OpenGL 时，就需要同样的代码 GLSL 也要写一套。</p>
<p>我们可以在 OpenGL 上用 nVidia 的 Cg Runtime 来解决这个问题。他可以用 HLSL 的语法来写 OpenGL 的 Shader。但是 Cg Runtime 也有他的缺点：1. 它很庞大，2. 他在 ATi 的显卡上性能不行，3. 他不支持 OpenGL ES 等等。FarCry 1，<a href="http://code.google.com/p/axonengine/">Axon Engine</a>，id 的新游戏 Rage 采用这个方案。</p>
<p>所以有时候我们需要一个直接把 HLSL 翻译成 GLSL 的解决方案。</p>
<ol>
<li>ATi 有一个 <a href="http://sourceforge.net/projects/hlsl2glsl/">HLSL2GLSL</a> 的开源项目，支持直接从 HLSL 翻译成 GLSL，最高支持到 SM3。 </li>
<li>Lost in Triangles fork 了这个项目，<a href="http://code.google.com/p/hlsl2glslfork/">hlsl2glslfork</a>，目前不见有啥新功能 </li>
<li><a href="http://icculus.org/mojoshader/">MojoShader</a> 支持把 D3D 的汇编 shader 和编译后的字节码翻译成 GLSL，<a href="http://www.unrealtournament3.com/">Unreal Tournament 3</a> 用的这个，好像也只支持到 Shader Model 3。 </li>
</ol>
<p>另外，Cg Runtime 在 Shader Model 4 和 Shader Model 5 在 OpenGL 上的支持好像也不太好。自从 Cg 的核心开发人员投奔微软后，Cg 框架的发展就明显停了下来。</p>
<p>这种人为造成的屏障，不知道是开发人员的不幸，还是产业的不行。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/hlsl-to-glsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3G 宽带上网体验</title>
		<link>http://huangdonghai.com/3g-wide-band-experiance/</link>
		<comments>http://huangdonghai.com/3g-wide-band-experiance/#comments</comments>
		<pubDate>Thu, 13 May 2010 14:46:32 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[数字化生存]]></category>
		<category><![CDATA[3G]]></category>
		<category><![CDATA[宽带上网]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/3g-wide-band-experiance/</guid>
		<description><![CDATA[为了应付即将到来的长途旅行，搞了套 3G 上网设备。采用 Lenovo Ideapad U150 超轻便小本（11.6 吋显示屏，SU2200 双核，1G 内存， 250G 硬盘，蓝牙、Wifi、以太网卡都有，自己加了 1G 内存）。这个本子有个缺点，键盘很松的样子，响声很大，等发现已经晚了，已经买回家了。其他方面都还可以。 我对 3G 手机毫无兴趣，只是想 3G 上网，出外的时候可以看看网页，打打字而已。伟大的祖国可能是世界上唯一有 3 种制式 3G 并存的国家，中国移动的 TD-SCDMA，中国联通的 WCDMA，中国电信的 CDMA 2000。联通用的 WCDMA 是国际上最通用的 3G 制式吧。本来想用联通的服务，可是联通的 3G 上网，是只能在 3G 区域用，不能切换到 2G 用，纯 3G 网络覆盖面积还是很小的。中国移动的 3G 好像更不行。最后选了中国电信的天翼 3G，3G、2G、Wifi 随时切换。试了下速度，尚可，在家里好的时候有 200Kbytes 峰值，看看网页是够了。 本子不带 3G 模块，所以搞了个华为的 EC122 上网卡。这个卡还是显得庞大了点，相比于 U 盘。 如果是玩 3G 手机，还是用联通吧。纯 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://huangdonghai.com/wp-content/uploads/2010/05/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://huangdonghai.com/wp-content/uploads/2010/05/image_thumb3.png" width="240" height="160" /></a> 为了应付即将到来的长途旅行，搞了套 3G 上网设备。采用 Lenovo Ideapad U150 超轻便小本（11.6 吋显示屏，SU2200 双核，1G 内存， 250G 硬盘，蓝牙、Wifi、以太网卡都有，自己加了 1G 内存）。这个本子有个缺点，键盘很松的样子，响声很大，等发现已经晚了，已经买回家了。其他方面都还可以。</p>
<p>我对 3G 手机毫无兴趣，只是想 3G 上网，出外的时候可以看看网页，打打字而已。伟大的祖国可能是世界上唯一有 3 种制式 3G 并存的国家，中国移动的 TD-SCDMA，中国联通的 WCDMA，中国电信的 CDMA 2000。联通用的 WCDMA 是国际上最通用的 3G 制式吧。本来想用联通的服务，可是联通的 3G 上网，是只能在 3G 区域用，不能切换到 2G 用，纯 3G 网络覆盖面积还是很小的。中国移动的 3G 好像更不行。最后选了中国电信的天翼 3G，3G、2G、Wifi 随时切换。试了下速度，尚可，在家里好的时候有 200Kbytes 峰值，看看网页是够了。</p>
<p>本子不带 3G 模块，所以搞了个华为的 EC122 上网卡。这个卡还是显得庞大了点，相比于 U 盘。</p>
<p>如果是玩 3G 手机，还是用联通吧。纯 3G 上网，电信不错。逛某论坛发现，基本没人用电信的 3G 电话，全是上网的。而联通的 3G 用户，就是用 3G 电话的多，上网的反而极少。这是我们国家的怪现象。</p>
<p>最后给关心的人报个我买的价格：U150 (3699元)，1G DDR3(175元)，华为 EC122(280元），电信 3G(我的e家套餐内含 20 小时每月，无月租，超出 0.1 元每分钟)。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/3g-wide-band-experiance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>轮子为什么省力？</title>
		<link>http://huangdonghai.com/why-wheel-labour-saving/</link>
		<comments>http://huangdonghai.com/why-wheel-labour-saving/#comments</comments>
		<pubDate>Tue, 11 May 2010 13:21:13 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[思考者]]></category>
		<category><![CDATA[wheel]]></category>
		<category><![CDATA[轮子]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/why-wheel-labour-saving/</guid>
		<description><![CDATA[我们程序界经常有句话，不要重新去发明轮子。轮子的发明确实很伟大，到底是谁发明的也不可考。我估计，这个发明是古代人在劳动生产中自然发现（或者叫发明）的。 想象下古人推或者拉一块沉重的方石头，这个时候要克服的是滑动摩擦力，它跟材料的光滑度、物体的重量和接触面的大小有关。这个力很大，古人一定很费劲。然后他发现，滚起来更省力（哪怕他不是圆形的），这个时候，如右图，是 Fp * Dp 这个力矩对抗 Fa * Da 这个力矩。如果这块石头是八角形的，那么 Da 就会更短，抵抗的力矩就会更小，随着形状越接近圆形，那么力矩就越小。可以想象，如果是个纯粹的完美的圆形的，那么抵抗的力矩会最小，这个时候就算是一个“小古人”，也可以推得动一块很重的大石头，这个其实就是滚动摩擦。并且圆形的特点，是滚动的时候不会颠簸，因为到圆心的距离一样。轮子就这样被发明了。 我们认真研究下轮子的滚动摩擦。如右图所示，无论是轮子，还是托起轮子的地面，都不可能是完全刚性的，总会有点变形，就是这点变形，造成了滚动摩擦的起因。其实滚动摩擦并不是一种摩擦，而是一种力矩，完全的滚动摩擦，并没有在接触点产生滑动，也就不会做功。当轮子和地面越硬，变形就越小，相当于产生的滑动摩擦就越小。这就是为什么火车用钢轨和钢轮子；也是为什么自行车和汽车，气不足的时候会更吃力或者更消耗汽油。 但是汽车为什么不用钢轮子呢？这个道理是很简单的，不像铁轨，他不需要转向，他的转向，是靠扳道实现的。而汽车要主动转向（这个需要滑动摩擦力），钢轮子太滑，不能方便转向。何况，如果轮子是钢的，地面岂不是很容易划烂。如果整个地面用钢板，那成本也太高了。有轨电车，其实是可以用钢轮子的，而且，很多有轨电车，确实用的是钢轮子。 轮子里面的学问，暂时就讲这些。]]></description>
			<content:encoded><![CDATA[<p>我们程序界经常有句话，不要重新去发明轮子。轮子的发明确实很伟大，到底是谁发明的也不可考。我估计，这个发明是古代人在劳动生产中自然发现（或者叫发明）的。</p>
<p><a href="http://huangdonghai.com/wp-content/uploads/2010/05/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="right" src="http://huangdonghai.com/wp-content/uploads/2010/05/image_thumb1.png" width="208" height="194" /></a> 想象下古人推或者拉一块沉重的方石头，这个时候要克服的是<strong>滑动摩擦</strong>力，它跟材料的光滑度、物体的重量和接触面的大小有关。这个力很大，古人一定很费劲。然后他发现，滚起来更省力（哪怕他不是圆形的），这个时候，如右图，是 Fp * Dp 这个力矩对抗 Fa * Da 这个力矩。如果这块石头是八角形的，那么 Da 就会更短，抵抗的力矩就会更小，随着形状越接近圆形，那么力矩就越小。可以想象，如果是个纯粹的完美的圆形的，那么抵抗的力矩会最小，这个时候就算是一个“小古人”，也可以推得动一块很重的大石头，这个其实就是<strong>滚动摩擦</strong>。并且圆形的特点，是滚动的时候不会颠簸，因为到圆心的距离一样。轮子就这样被发明了。</p>
<p><a href="http://huangdonghai.com/wp-content/uploads/2010/05/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://huangdonghai.com/wp-content/uploads/2010/05/image_thumb2.png" width="220" height="294" /></a>我们认真研究下轮子的滚动摩擦。如右图所示，无论是轮子，还是托起轮子的地面，都不可能是完全刚性的，总会有点变形，就是这点变形，造成了滚动摩擦的起因。其实滚动摩擦并不是一种摩擦，而是一种力矩，完全的滚动摩擦，并没有在接触点产生滑动，也就不会做功。当轮子和地面越硬，变形就越小，相当于产生的滑动摩擦就越小。这就是为什么火车用钢轨和钢轮子；也是为什么自行车和汽车，气不足的时候会更吃力或者更消耗汽油。</p>
<p>但是汽车为什么不用钢轮子呢？这个道理是很简单的，不像铁轨，他不需要转向，他的转向，是靠扳道实现的。而汽车要主动转向（这个需要滑动摩擦力），钢轮子太滑，不能方便转向。何况，如果轮子是钢的，地面岂不是很容易划烂。如果整个地面用钢板，那成本也太高了。有轨电车，其实是可以用钢轮子的，而且，很多有轨电车，确实用的是钢轮子。</p>
<p>轮子里面的学问，暂时就讲这些。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/why-wheel-labour-saving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何利用大于4G内存？</title>
		<link>http://huangdonghai.com/about-4g-memory/</link>
		<comments>http://huangdonghai.com/about-4g-memory/#comments</comments>
		<pubDate>Sun, 02 May 2010 08:08:06 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[x64]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/about-4g-memory/</guid>
		<description><![CDATA[现在有大于 4G 内存相当常见，内存这么便宜。这样操作系统的选择就是件麻烦事情。Windows XP、Windows Vista 和 Windows 7 x86 版本都只能用到 3.0~3.2G 左右，跟主板有关。很多人就被逼安装 x64 版本的操作系统。 其实N年前就有PAE1这个CPU支持的特性。现在市面上的 CPU，估计没有不支持的吧。现在的 Linux 发行版，2.6 之后的内核大都编译进去了 PAE 的支持，所以，就算你是大于4G内存，装Linux 32bits，也可以完全利用全部内存。Windows Server 2003 和 Windows Server 2008 的 32 位版，也用PAE支持到 64G 的内存。 看这个表： Windows 版本 (和最大支持内存(GB)) 32-bit 版本 64-bit版本 Windows 2000 Professional, Server 4 N/A Windows 2000 Advanced Server 8 N/A Windows 2000 Datacenter [...]]]></description>
			<content:encoded><![CDATA[<p>现在有大于 4G 内存相当常见，内存这么便宜。这样操作系统的选择就是件麻烦事情。Windows XP、Windows Vista 和 Windows 7 x86 版本都只能用到 3.0~3.2G 左右，跟主板有关。很多人就被逼安装 x64 版本的操作系统。</p>
<p>其实N年前就有PAE<sup><a href="http://huangdonghai.com/about-4g-memory/#footnote_0_242" id="identifier_0_242" class="footnote-link footnote-identifier-link" title="参考：Physical_Address_Extension">1</a></sup>这个CPU支持的特性。现在市面上的 CPU，估计没有不支持的吧。现在的 Linux 发行版，2.6 之后的内核大都编译进去了 PAE 的支持，所以，就算你是大于4G内存，装Linux 32bits，也可以完全利用全部内存。Windows Server 2003 和 Windows Server 2008 的 32 位版，也用PAE支持到 64G 的内存。</p>
<p>看这个表：</p>
<table class="wikitable sortable" width="644">
<tbody>
<tr>
<th width="401">Windows 版本 (和最大支持内存(GB))</th>
<th width="112" align="center">32-bit 版本</th>
<th width="128" align="center">64-bit版本</th>
</tr>
<tr>
<td width="401">Windows 2000 Professional, Server</td>
<td width="112" align="center">4</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows 2000 Advanced Server</td>
<td width="112" align="center">8</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows 2000 Datacenter</td>
<td width="112" align="center">32</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows XP Starter</td>
<td width="112" align="center">0.5</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows XP Home &amp; Media Center</td>
<td width="112" align="center">4</td>
<td width="128">&#160;</td>
</tr>
<tr>
<td width="401">Windows XP Professional</td>
<td width="112" align="center">4</td>
<td width="128" align="center">32</td>
</tr>
<tr>
<td width="401">Windows Server 2003 Web</td>
<td width="112" align="center">2</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows Server 2003 Small Business, Home, Storage</td>
<td width="112" align="center">4</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows Server 2003 Enterprise Storage</td>
<td width="112" align="center">8</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows Server 2003 Standard (SP1/SP2/R2)</td>
<td width="112" align="center">4</td>
<td width="128" align="center">32</td>
</tr>
<tr>
<td width="401"><strong>Windows Server 2003 Enterprise (SP2)</strong></td>
<td width="112" align="center"><strong>64</strong></td>
<td width="128" align="center"><strong>2048</strong></td>
</tr>
<tr>
<td width="401"><strong>Windows Server 2003 Datacenter (SP2)</strong></td>
<td width="112" align="center"><strong>128</strong></td>
<td width="128" align="center"><strong>2048</strong></td>
</tr>
<tr>
<td width="401">Windows Vista Starter</td>
<td width="112" align="center">1</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows Vista Home Basic</td>
<td width="112" align="center">4</td>
<td width="128" align="center">8</td>
</tr>
<tr>
<td width="401">Windows Vista Home Premium</td>
<td width="112" align="center">4</td>
<td width="128" align="center">16</td>
</tr>
<tr>
<td width="401">Windows Vista Business, Enterprise, Ultimate</td>
<td width="112" align="center">4</td>
<td width="128" align="center">128</td>
</tr>
<tr>
<td width="401">Windows Server 2008 Standard, Web</td>
<td width="112" align="center">4</td>
<td width="128" align="center">32</td>
</tr>
<tr>
<td width="401"><strong>Windows Server 2008 Enterprise, Datacenter</strong></td>
<td width="112" align="center"><strong>64</strong></td>
<td width="128" align="center"><strong>2048</strong></td>
</tr>
<tr>
<td width="401">Windows 7 Starter</td>
<td width="112" align="center">2</td>
<td width="128" align="center">N/A</td>
</tr>
<tr>
<td width="401">Windows 7 Home Basic</td>
<td width="112" align="center">4</td>
<td width="128" align="center">8</td>
</tr>
<tr>
<td width="401">Windows 7 Home Premium</td>
<td width="112" align="center">4</td>
<td width="128" align="center">16</td>
</tr>
<tr>
<td width="401">Windows 7 Professional, Enterprise, Ultimate</td>
<td width="112" align="center">4</td>
<td width="128" align="center">192</td>
</tr>
</tbody>
</table>
<p>Windows 32 位版本内存的限制，完全只是商业考量，并非技术原因。所以，如果你要支持大内存，而又不想用x64版本的操作系统，XP 内核的可以选用 Windows Server 2003 Enterprise 或者 DataCenter 版本，Vista 和 Win7 内核的，可选用 Windows Server 2008&#160; Enterprise。</p>
<p>当然 32 位的操作系统利用 PAE 可以支持到 64G 内存，但是单个应用程序，还是只能最多利用 4G 内存空间，我觉得这是我们唯一要用 64bits 操作系统的原因。</p>
<ol class="footnotes">
<li id="footnote_0_242" class="footnote">参考：<a href="http://en.wikipedia.org/wiki/Physical_Address_Extension">Physical_Address_Extension</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/about-4g-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从零到点 &#8211; Chapter 0</title>
		<link>http://huangdonghai.com/from-zero-to-dot-0/</link>
		<comments>http://huangdonghai.com/from-zero-to-dot-0/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 14:32:00 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[基础理论]]></category>
		<category><![CDATA[叉积]]></category>
		<category><![CDATA[点积]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/from-zero-to-dot-0/</guid>
		<description><![CDATA[有“高手”说，考试新人，考矩阵求逆就够了。这么“高深”的东西，我怎么能懂呢。我是只知道点积和叉积的。这个话恐怕也说满了，点积和叉积，我也不能说我就知道了。我只知道了一点点。 关于矩阵求逆，我们知道求逆的定义，就是求 M-1= I / M。对于的矩阵，不过是 16 个线性联立方程，有16个未知数，这个只是体力活，就算你未尝先把公式背下来，硬算也是初中生可解的问题，并且这个只是代数问题，跟几何没有关系。而点积和叉积则不同，点积和叉积是 3D 解析几何，3D 图形学的数学基础，如何让扁平的代数立体起来，靠的就是这个。大多数引擎程序员会自认为自己很了解点积和叉积。但是实际上据我观察，却不是这样。99%的人没搞懂这个。 我们的教科书，倾向于直接把结果含糊不清的告诉学生，而没有把其中的过程，思辨教给学生，而这个反而是精华。我说他们含糊不清，已经是个很轻的说法。实际上，我发现我们的教科书，采用循环定义，想当然的推理的地方很多。我尝试用一种不同的途径来讲述这个。你看了之后，可能会更明白了，哦，原来是这样。但是很有可能 (或者说是更有可能) 是更迷糊了。很多你认为理所当然的东西一下子朦胧了起来。 自然数 Natural number 我们从最简单的开始。老王是卖白菜的，他问，一斤白菜 2 块钱，请问 3 斤白菜多少钱？虽然你家里不是卖白菜的，我想你也能得出答案，6 块钱。我如果问为什么呢？因为 2*3 = 6。如果我问为什么 2*3 = 6 呢？这个就有点难度了。九九乘法表里就是这样的，我们从小就背下来了。其实很简单，乘法是加法的简化写法，2*3 等于 3 个 2 相加，所以 2*3 = 2+2+2=6。那为什么 2+2+2=6 呢？这就很难答上来了。如果你孩子问你，你会跟他搬指头。搬指头是没错的，但是如果是 20，200，2000， 你恐怕就没这么多指头可以搬(蜈蚣除外)。 要解答这个问题，其实是没有可能的。我们要搬出公理，公理，就是公认的道理，不证自明的道理，其实就是没有办法证明的道理。我们前面说的，其实是自然数，或者说，我们叫它自然数，因为它很“自然而然”。关于自然数，我们有皮亚诺公理来描述这个问题。 皮亚诺的这五条公理用非形式化的方法叙述如下： 1 是自然数； 每一个确定的自然数a，都有一个确定的后继数 a&#8217; ，a&#8217;&#160; 也是自然数（一个数的后继数就是紧接在这个数后面的数，例如，1的后继数是2，2的后继数是3，等等）； 如果自然数 b、c 的后继数都是自然数 a，那么 b [...]]]></description>
			<content:encoded><![CDATA[<p>有“高手”说，考试新人，<a href="http://bbs.gameres.com/showthread.asp?threadid=145079">考矩阵求逆就够了</a>。这么“高深”的东西，我怎么能懂呢。我是只知道点积和叉积的。这个话恐怕也说满了，<strong>点</strong>积和<strong>叉</strong>积，我也不能说我就知道了。我只知道了一点点。</p>
<p>关于矩阵求逆，我们知道求逆的定义，就是求 M<sup>-1</sup>= I / M。对于<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_bb28c3e7c23e3d09a381e745a54511a4.png" title="4\times 4" style="vertical-align: middle;" class="tex" alt="4\times 4" />的矩阵，不过是 16 个线性联立方程，有16个未知数，这个只是体力活，就算你未尝先把公式背下来，硬算也是初中生可解的问题，并且这个只是代数问题，跟几何没有关系。而点积和叉积则不同，点积和叉积是 3D 解析几何，3D 图形学的数学基础，如何让扁平的代数立体起来，靠的就是这个。大多数引擎程序员会自认为自己很了解点积和叉积。但是实际上据我观察，却不是这样。99%的人没搞懂这个。</p>
<p>我们的教科书，倾向于直接把结果含糊不清的告诉学生，而没有把其中的过程，思辨教给学生，而这个反而是精华。我说他们含糊不清，已经是个很轻的说法。实际上，我发现我们的教科书，采用循环定义，想当然的推理的地方很多。我尝试用一种不同的途径来讲述这个。你看了之后，可能会更明白了，哦，原来是这样。但是很有可能 (或者说是更有可能) 是更迷糊了。很多你认为理所当然的东西一下子朦胧了起来。</p>
<span id="Natural_number"><h4>自然数 Natural number</h4></span>
<p><a href="http://huangdonghai.com/wp-content/uploads/2010/05/image.png"><img title="皮亚诺像" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 10px; border-right-width: 0px" height="244" alt="皮亚诺像" src="http://huangdonghai.com/wp-content/uploads/2010/05/image_thumb.png" width="206" align="right" border="0" /></a>我们从最简单的开始。老王是卖白菜的，他问，一斤白菜 2 块钱，请问 3 斤白菜多少钱？虽然你家里不是卖白菜的，我想你也能得出答案，6 块钱。我如果问为什么呢？因为 2*3 = 6。如果我问为什么 2*3 = 6 呢？这个就有点难度了。九九乘法表里就是这样的，我们从小就背下来了。其实很简单，乘法是加法的简化写法，2*3 等于 3 个 2 相加，所以 2*3 = 2+2+2=6。那为什么 2+2+2=6 呢？这就很难答上来了。如果你孩子问你，你会跟他搬指头。搬指头是没错的，但是如果是 20，200，2000， 你恐怕就没这么多指头可以搬(蜈蚣除外)。</p>
<p>要解答这个问题，其实是没有可能的。我们要搬出公理，公理，就是公认的道理，不证自明的道理，其实就是没有办法证明的道理。我们前面说的，其实是自然数，或者说，我们叫它自然数，因为它很“自然而然”。关于自然数，我们有皮亚诺公理来描述这个问题。</p>
<p>皮亚诺的这五条公理用非形式化的方法叙述如下：</p>
<ol>
<li>1 是自然数； </li>
<li>每一个确定的自然数<i>a</i>，都有一个确定的后继数 <i>a&#8217;</i> ，<i>a&#8217;</i>&#160; 也是自然数（一个数的后继数就是紧接在这个数后面的数，例如，1的后继数是2，2的后继数是3，等等）； </li>
<li>如果自然数 <i>b</i>、<i>c </i>的后继数都是自然数 <i>a</i>，那么 <i>b = c</i>； </li>
<li>1 不是任何自然数的后继数； </li>
<li>任意关于自然数的命题，如果证明了它对自然数1是对的，又假定它对自然数 <i>n </i>为真时，可以证明它对 <i>n&#8217;</i>&#160; 也真，那么，命题对所有自然数都真。(这条公理保证了数学归纳法的正确性) </li>
</ol>
<p>皮亚诺公理里的第 2 项所谓的后继，其实定义了加法，后继，就是搬一个指头，就是 +1 的得到的数。后继的后继，就是 + 1 + 1。我们知道 1 的后继那个数，我们写作 2，意思就是 1 + 1 = 2。所以<strong>加法就是多次搬指头的简写</strong>。 </p>
<p>a+b 定义为 a 后面第 b 个后继，也就是 a 之后再搬 b 次指头。</p>
<p>我们先证明证明加法结合律：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_8630c3b0e025f08652b385b7690ae657.png" title="(a+b)+c=a+(b+c)" style="vertical-align: middle;" class="tex" alt="(a+b)+c=a+(b+c)" /></p>
<p>首先证明 c=1 时上式成立， (a+b)+1 是 (a+b) 的后继，而 a+b 是 a 后的第 b 个后继，那么 a+(b+1) 也就是 (a+b) 的后继。所以</p>
<p align="center">公式1： <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_d30bbcb817ab388c4dd2ba0a07ad9f57.png" title="(a+b)+1 = a+(b+1)" style="vertical-align: middle;" class="tex" alt="(a+b)+1 = a+(b+1)" /></p>
<p align="left">成立。</p>
<p>假设 c=m 时成立，我们证明 c=m+1 时也成立。</p>
<p>如果</p>
<p align="center">公式2：<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_ec1b5261a8cc9bd38288468bf71314b5.png" title="(a+b)+m=a+(b+m)" style="vertical-align: middle;" class="tex" alt="(a+b)+m=a+(b+m)" /></p>
<p>成立，</p>
<p>那么 根据公式1有</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_77ac7198b6928bdfedc82a6906bf9e73.png" title="(a+b)+(m+1) = (a+b+m) + 1" style="vertical-align: middle;" class="tex" alt="(a+b)+(m+1) = (a+b+m) + 1" /></p>
<p>根据公式2有</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_705d16b2a7b4340c1340efe5c4daaebb.png" title="(a+b+m) + 1 = ( a+(b+m))+1" style="vertical-align: middle;" class="tex" alt="(a+b+m) + 1 = ( a+(b+m))+1" /></p>
<p>再根据公式1(用了两次公式1)</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_722f20e6c87feffb2bd5adf65780ce6c.png" title="( a+(b+m))+1 = a+( (b+m)+1) = a+(b+(m+1))" style="vertical-align: middle;" class="tex" alt="( a+(b+m))+1 = a+( (b+m)+1) = a+(b+(m+1))" /></p>
<p>证毕。</p>
<p>加法交换律也可以用归纳法类似的证明。</p>
<p>那么 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_52a61d5e6a330f55be7226adaa70beab.png" title="2+2" style="vertical-align: middle;" class="tex" alt="2+2" /> 等于多少呢？<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_651ecb153591120a569aaedbbd67fba8.png" title="2+2 = (1+1) + (1+1) = (1+1+1) + 1 = 3+1 = 4" style="vertical-align: middle;" class="tex" alt="2+2 = (1+1) + (1+1) = (1+1+1) + 1 = 3+1 = 4" />。</p>
<p><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_b6d9db7483408502a2c68ed48491ec46.png" title="2+2+2" style="vertical-align: middle;" class="tex" alt="2+2+2" /> 等于多少呢？按上面的方法，不难证明 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_e5d82381ac2e20b3ad3176d17fd5568a.png" title="2+2+2=6" style="vertical-align: middle;" class="tex" alt="2+2+2=6" />。</p>
<p>但是<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_b6d9db7483408502a2c68ed48491ec46.png" title="2+2+2" style="vertical-align: middle;" class="tex" alt="2+2+2" />写起来太难看了，如果你买100斤白菜，那岂不是要写老长？我们定义一个新的简写方法，a多次累加b次，我们写成<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_09cfccbe0cca8554492be1e4ae8e5677.png" title="a\times b" style="vertical-align: middle;" class="tex" alt="a\times b" />。<strong>乘法就是多次加法的简写</strong>。就得到 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_027a0a3eb1a23a3d7d0fa705918cda4e.png" title="2\times 3=6" style="vertical-align: middle;" class="tex" alt="2\times 3=6" />。</p>
<p>乘法也可以证明符合结合律和交换律。证明就不写了。自己可以去试试。</p>
<p>另外，对于一个自然数，乘以1等于多少呢？这个很容易理解，还是等于自身。一斤白菜2块钱，你买一斤，当然还是2块钱。所以我们有：</p>
<p align="center">公式3: <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_2b2e58985e7c5006d2d47e6b5c153ad0.png" title="1 \times n = n" style="vertical-align: middle;" class="tex" alt="1 \times n = n" /></p>
<span id="Integer"><h4>整数 Integer</h4></span>
<p>卖白菜是件很高深的工作，跟掏粪不相上下，也需要大学生才能搞定。老王大学毕业后，卖白菜卖的很有心得。有个问题，今天进了100斤白菜的货，卖出了85斤，问，还剩多少斤呢？</p>
<p>所以我们要定义一个搬指头的逆运算，反向扳指头，先拿出100根指头，然后拿掉85个指头，这个运算我们叫<strong>减法，减法是加法的逆运算</strong>。</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_45c992c09f9c2429190384a72be761e2.png" title="100-85=15" style="vertical-align: middle;" class="tex" alt="100-85=15" /></p>
<p>如果卖了100斤呢？你发现啥都没剩下。这时候我们定义一个新的数 <strong>0</strong>，表示没有，空。0算不算自然数，有的领域倾向于算是，比如集合论和计算机科学里。有的领域一般不算，比如数论。数论里面算0，很多东西就不好搞了。比如0算不算偶数？算不算质数？不好搞。我们不讨论这个。卖白菜虽然高深，但是也没到要去证明哥德巴赫猜想的地步。</p>
<p>所以，卖完100斤后，老王今天收入了200块钱。老王的白菜生意做得很好，又很有信誉，所以，白菜供应商可以让老王先拿货，后付款。第二天老王又拿了100斤白菜，但是挂了帐，拿货价是1元每斤（白菜的利润没这么高，否则就不是叫白菜，但是我们还没学过实数，所以暂时这么定）。结果这天生意不好，大家都喜欢吃点好的(豆腐就不错)，只卖掉了30斤，老王今天收入多少钱呢？</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_1a0889b4c3e8f03fe27537ee94345a48.png" title="30\times2=60" style="vertical-align: middle;" class="tex" alt="30\times2=60" /></p>
<p>要还供应商100块，这个帐一算，老王亏了40块。如何计帐这个亏了的40块钱(统计局不叫这个叫亏损，叫赤字，老王收入下降也不是下降，叫负增长)，我们扩展自然数支持这个记法，叫负数。-1就是0前继，-40就是0往前数40。</p>
<p>我们不难得到，0-40 = -40，0-n=-n;</p>
<p>负整数乘以正整数是正整数还是负整数呢。当然是负整数。我欠你10块钱，是-10。如果是欠10倍的10块钱，当然是 –100。如果是正数就麻烦了，你要倒找我钱。即, 假设a, b是正整数：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_ff6e30339bbe066283dfb5f8aa7f93d4.png" title="(-a)\times b=-(a\times b)" style="vertical-align: middle;" class="tex" alt="(-a)\times b=-(a\times b)" /></p>
<p>负整数乘以负整数是负整数还是正整数呢？</p>
<p>假设a, b是正整数，那么</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_ab8c3b16f9f92ca2bdc5cb5a93eb8dda.png" title="\begin{array}{rl} (-a)\times(-b) &#038; =-1\times a\times(-b)\\ &#038; =-(a\times(-b))\\ &#038; =0-(a\times(-b))\\ &#038; =0-(-(a\times b))\\ &#038; =a\times b\end{array}" style="vertical-align: middle;" class="tex" alt="\begin{array}{rl} (-a)\times(-b) &#038; =-1\times a\times(-b)\\ &#038; =-(a\times(-b))\\ &#038; =0-(a\times(-b))\\ &#038; =0-(-(a\times b))\\ &#038; =a\times b\end{array}" /></p>
<p>显然结果为正整数。</p>
</p>
<span id=""><h1></h1></span>
<span id="_1"><h4>小结</h4></span>
<p>我们初步从一无所有开始，得到了整数的概念和一些基本的运算。后面我们要进入实数和几何，然后接近点积和叉积。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/from-zero-to-dot-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu 9.10下Firefox字体发虚的问题</title>
		<link>http://huangdonghai.com/ubuntu-9-10-firefox-font-smooth/</link>
		<comments>http://huangdonghai.com/ubuntu-9-10-firefox-font-smooth/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 09:24:34 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[字体]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/2010/04/27/194/</guid>
		<description><![CDATA[Ubuntu 9.10 下如果你出现了 Firefox 字体始终发虚(启动了ClearType)，并且在“外观”里修改而 Firefox 始终发虚(其他程序正常)，如这个案例： &#160;&#160;&#160; Ubuntu中文论坛 • 查看主题 &#8211; ubuntu 9.10下firefox 3.5 的字体平滑方式如何解决？ 那么你可以这样做： sudo rm /etc/fonts/conf.d/10* sudo dpkg-reconfigure fontconfig 重启 Firefox 就好了。]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 9.10 下如果你出现了 Firefox 字体始终发虚(启动了ClearType)，并且在“外观”里修改而 Firefox 始终发虚(其他程序正常)，如这个案例：</p>
<p>&#160;&#160;&#160; <a href="http://forum.ubuntu.org.cn/viewtopic.php?f=8&amp;t=254565">Ubuntu中文论坛 • 查看主题 &#8211; ubuntu 9.10下firefox 3.5 的字体平滑方式如何解决？</a></p>
<p>那么你可以这样做：</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">10</span><span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dpkg-reconfigure fontconfig</pre></div></div>

<p>重启 Firefox 就好了。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/ubuntu-9-10-firefox-font-smooth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZT：建立只能使用ssh&#8220;转发&#8221;功能的系统账户</title>
		<link>http://huangdonghai.com/ssh-forward-only-account/</link>
		<comments>http://huangdonghai.com/ssh-forward-only-account/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 19:28:52 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/2010/04/24/176/</guid>
		<description><![CDATA[为了满足“翻Wall”的需要，在国外的 Linux主机上或 VPS 上建个可 ssh登录的用户，使用 ssh 的 Tunnel 来作代理是十分常见的方法。 但是主人往往又想最小化用户权限，以避免对系统造成影响。最简单的办法就是，禁止用户登录。 其实 ssh 可以连接到 sshd 但是不执行远程命令（默认是启动用户设定的 shell ），使用 -N 参数即可。 在服务器上建一个 username ： $ useradd -s /bin/false username 将用户的 shell 设置成 /bin/false。这样用户就无法与系统进行交互。设置密码： $ passwd username 补充一下：对已有帐号禁止其shell交互使用： $ usermod -s /bin/false username 小技巧： 也可以使用 /usr/bin/passwd 作为用户的 shell ，这样用户就可以通过登录而来自主修改密码。需要注意的是，需要将 /usr/bin/passwd 这一行写进 /etc/shells 文件。 sshd 认证通后之后，会检查设定的 shell 是否登记在 /etc/shells [...]]]></description>
			<content:encoded><![CDATA[<p>为了满足“翻Wall”的需要，在国外的 Linux主机上或 VPS 上建个可 ssh登录的用户，使用 ssh 的 Tunnel 来作代理是十分常见的方法。</p>
<p>但是主人往往又想最小化用户权限，以避免对系统造成影响。最简单的办法就是，禁止用户登录。</p>
<p>其实 ssh 可以连接到 sshd 但是不执行远程命令（默认是启动用户设定的 shell ），使用 -N 参数即可。</p>
<p>在服务器上建一个 username ：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ useradd <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> username</pre></div></div>

<p>将用户的 shell 设置成 <code>/bin/false</code>。这样用户就无法与系统进行交互。设置密码：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">passwd</span> username</pre></div></div>

<p>补充一下：对已有帐号禁止其shell交互使用：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ usermod <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> username</pre></div></div>

<p>小技巧：</p>
<p>也可以使用 <code>/usr/bin/passwd</code> 作为用户的 shell ，这样用户就可以通过登录而来自主修改密码。需要注意的是，需要将 <code>/usr/bin/passwd</code> 这一行写进 <code>/etc/shells </code>文件。</p>
<p>sshd 认证通后之后，会检查设定的 shell 是否登记在 <code>/etc/shells</code> 文件中，若已经登记，则 fork自己，然后 fork 出来的子进程再 exec 设定的 shell 。而 ssh 的 -N 参数，则是告诉 sshd 不需要执行 shell。</p>
<p>建立Tunnel：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-D</span> <span style="color: #000000;">1080</span> <span style="color: #660033;">-qfnN</span> username<span style="color: #000000; font-weight: bold;">@</span><span style="color: #c20cb9; font-weight: bold;">hostname</span></pre></div></div>

<p>输入密码即可使用（也可以用key认证）。</p>
<p>Windows的话，可以使用 <a href="http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html">plink.exe</a> 或者 <a href="http://nemesis2.qx.net/pages/MyEnTunnel">MyEnTunnel</a>（MyEnTunnel 本质上也是使用 plink.exe 来建立Tunnel）。</p>
<p>此时账号 username 可以通过 sshd 的认证使用 TcpForwarding ，但是不能运行 shell，不能与系统交互。刚好可以用来为朋友提供国外的代理翻Wall。</p>
<pre>参数详解：
-D 1080 建立动态Tunnel，监听在本地1080端口。
-q 安静模式。
-f ssh在后台运行，即认证之后，ssh退居后台。
-n 将 stdio 重定向到 /dev/null，与-f配合使用。
-N 不运行远程程序。即通知 sshd 不运行设定的 shell。</pre>
<p>source: <a title="http://www.bsdmap.com/2010/02/22/create-tunnel-user/" href="http://www.bsdmap.com/2010/02/22/create-tunnel-user/">http://www.bsdmap.com/2010/02/22/create-tunnel-user/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/ssh-forward-only-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 fail2ban 来保护 VPS</title>
		<link>http://huangdonghai.com/fail2ban-protected-vps/</link>
		<comments>http://huangdonghai.com/fail2ban-protected-vps/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 13:10:47 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[时区]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/index.php/2010/04/23/%e7%94%a8fail2ban%e6%9d%a5%e4%bf%9d%e6%8a%a4vps/</guid>
		<description><![CDATA[总是有无聊的人来扫描 ssh 的密码，看看 /var/log/auth.log 就可以看到。为了安全, 可以用 fail2ban 来保护, 这个软件会自动屏蔽一段时间错误尝试的 ip。直接从源里安装： $ apt-get install fail2ban 就行了。 我用的时候碰到了奇怪的问题，发现这个软件不能发挥功用，经过检查，原来是我因为我设定了新的服务器时区。设定服务器时区，在 Ubuntu上 可以用命令： $ dpkg-reconfigure tzdata 但是系统没有重启，所以 log 系统还是用老时区时间，但是 fail2ban 用的是新时区的时间，而 fail2ban 是靠查 /var/log/auth.log 来判断是否侵入的，所以就无法正常工作。 重新启动之后问题消失。]]></description>
			<content:encoded><![CDATA[<p>总是有无聊的人来扫描 ssh 的密码，看看 <code>/var/log/auth.log</code> 就可以看到。为了安全, 可以用 fail2ban 来保护, 这个软件会自动屏蔽一段时间错误尝试的 ip。直接从源里安装：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> fail2ban</pre></div></div>

<p>就行了。</p>
<p>我用的时候碰到了奇怪的问题，发现这个软件不能发挥功用，经过检查，原来是我因为我设定了新的服务器时区。设定服务器时区，在 Ubuntu上 可以用命令：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ dpkg-reconfigure tzdata</pre></div></div>

<p>但是系统没有重启，所以 log 系统还是用老时区时间，但是 fail2ban 用的是新时区的时间，而 fail2ban 是靠查 <code>/var/log/auth.log</code> 来判断是否侵入的，所以就无法正常工作。</p>
<p>重新启动之后问题消失。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/fail2ban-protected-vps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>由 Z buffer 得到 View Space Z</title>
		<link>http://huangdonghai.com/from-zbuffer-recover-viewspace-z/</link>
		<comments>http://huangdonghai.com/from-zbuffer-recover-viewspace-z/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 16:36:42 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[引擎开发]]></category>
		<category><![CDATA[DEPTH]]></category>
		<category><![CDATA[DF16]]></category>
		<category><![CDATA[DF24]]></category>
		<category><![CDATA[INTZ]]></category>
		<category><![CDATA[RAWZ]]></category>
		<category><![CDATA[VIEWSPACE]]></category>
		<category><![CDATA[ZBUFFER]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/index.php/2010/04/23/%e6%af%8f%e6%97%a5%e4%b8%80trick-%e7%94%b1zbuffer%e5%be%97%e5%88%b0viewspace-z/</guid>
		<description><![CDATA[现在几乎没有不用某种程度的延迟模式渲染，我们经常需要在 GBuffer 里保存 Z 信息，然后可以反算出视点坐标系或者世界坐标系的坐标。如果你直接保存 ViewSpace 的 Z，那没有这篇所说的问题。但是保存 ViewSpace Z，需要 DepthBuffer 之外的地方来保存。有的引擎直接用 Hardware ZBuffer，OpenGL 上这个并不难实现，D3D 上需要些 Tricks，要用 vendor 提供的特殊的 FOURCC 格式，比如 nVidia 的 RAWZ、INTZ，ATi 的 DF16、DF24，好像最新的 ATi 显卡也支持 INTZ 了。 由 ZBuffer Z 得到 ViewSpace Z 是件很简单的事情，我们先看 Direct3D 和 OpenGL 上的变换矩阵： OpenGL: D3D: OpenGL 的投影变换矩阵变换后，z 的值在 [-1, 1] 范围，而 D3D 的值在 [0, 1] 范围。新手混淆不清的是，OpenGL 的 [...]]]></description>
			<content:encoded><![CDATA[<p>现在几乎没有不用某种程度的延迟模式渲染，我们经常需要在 GBuffer 里保存 Z 信息，然后可以反算出视点坐标系或者世界坐标系的坐标。如果你直接保存 ViewSpace 的 Z，那没有这篇所说的问题。但是保存 ViewSpace Z，需要 DepthBuffer 之外的地方来保存。有的引擎直接用 Hardware ZBuffer，OpenGL 上这个并不难实现，D3D 上需要些 Tricks，要用 vendor 提供的特殊的 FOURCC 格式，比如 nVidia 的 RAWZ、INTZ，ATi 的 DF16、DF24，好像最新的 ATi 显卡也支持 INTZ 了。</p>
<p>由 ZBuffer Z 得到 ViewSpace Z 是件很简单的事情，我们先看 Direct3D 和 OpenGL 上的变换矩阵：</p>
<p>OpenGL:</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_516b8a4dc2f3f283ae27bb63395a680a.png" title="\mathrm{P}_{OpenGL}=\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle -\frac{f+n}{f-n}} &#038; {\displaystyle -\frac{2fn}{f-n}}\\ 0 &#038; 0 &#038; -1 &#038; 0\end{array}\right)" style="vertical-align: middle;" class="tex" alt="\mathrm{P}_{OpenGL}=\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle -\frac{f+n}{f-n}} &#038; {\displaystyle -\frac{2fn}{f-n}}\\ 0 &#038; 0 &#038; -1 &#038; 0\end{array}\right)" /></p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_a65e97b33487067cb6338eca5b7778ed.png" title="z\in\left[-1,1\right]" style="vertical-align: middle;" class="tex" alt="z\in\left[-1,1\right]" /></p>
<p align="left">D3D:</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_f772b9e58ca433e04207d8710623db20.png" title="\mathrm{P}_{D3D}=\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle \frac{f}{f-n}} &#038; {\displaystyle -\frac{fn}{f-n}}\\ 0 &#038; 0 &#038; 1 &#038; 0\end{array}\right)" style="vertical-align: middle;" class="tex" alt="\mathrm{P}_{D3D}=\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle \frac{f}{f-n}} &#038; {\displaystyle -\frac{fn}{f-n}}\\ 0 &#038; 0 &#038; 1 &#038; 0\end{array}\right)" /></p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_d600f0364bc212828933b4f2f5516638.png" title="z\in\left[0,1\right]" style="vertical-align: middle;" class="tex" alt="z\in\left[0,1\right]" /></p>
<p>OpenGL 的投影变换矩阵变换后，z 的值在 [-1, 1] 范围，而 D3D 的值在 [0, 1] 范围。新手混淆不清的是，OpenGL 的 z 实际上是在 [1, -1]，因为他的右手坐标系，z 是指向你的眼睛的，所以，远的地方 z 值反而较小，以至于为负。</p>
<p>但是当你写到硬件 ZBuffer 以后，读出来的时候，无论是 OpenGL 还是 D3D，无论是那个格式(RAWZ, INTZ, DF16, DF24, GL_DEPTH_COMPONENTxx)，都是 [0, 1] 范围，0 是最近点，既是 near plane 的 z，1 是最远点，far plane 的 z。这也是经常让人混淆的东西。因为这个原因，我们可以值用 D3D 的公式来算。</p>
<p>有了这些信息，我们不难推导出求 ViewSpace Z 的公式。</p>
<p>因为：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_a2ec652db954a4bd066fbf9e68fb29bf.png" title="\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle \frac{f}{f-n}} &#038; {\displaystyle -\frac{fn}{f-n}}\\ 0 &#038; 0 &#038; 1 &#038; 0\end{array}\right)\left(\begin{array}{c} x_{v}\\ y_{v}\\ z_{v}\\ w_{v}\end{array}\right)=\left(\begin{array}{c} x_{c}\\ y_{c}\\ z_{c}\\ w_{c}\end{array}\right)" style="vertical-align: middle;" class="tex" alt="\left(\begin{array}{cccc} {\displaystyle \frac{2n}{r-l}} &#038; 0 &#038; {\displaystyle \frac{r+l}{r-l}} &#038; 0\\ 0 &#038; {\displaystyle \frac{2n}{t-b}} &#038; {\displaystyle \frac{t+b}{t-b}} &#038; 0\\ 0 &#038; 0 &#038; {\displaystyle \frac{f}{f-n}} &#038; {\displaystyle -\frac{fn}{f-n}}\\ 0 &#038; 0 &#038; 1 &#038; 0\end{array}\right)\left(\begin{array}{c} x_{v}\\ y_{v}\\ z_{v}\\ w_{v}\end{array}\right)=\left(\begin{array}{c} x_{c}\\ y_{c}\\ z_{c}\\ w_{c}\end{array}\right)" /></p>
<p align="left">我们只关心 Z 的值：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_4d368a930fca87c020e1480ddc53d9c4.png" title="\begin{cases} \begin{array}{l} {\displaystyle \frac{f}{f-n}}z_{v}-{\displaystyle \frac{fn}{f-n}=z_{c}}\\ \\w_{c}=z_{v}\end{array}\end{cases}" style="vertical-align: middle;" class="tex" alt="\begin{cases} \begin{array}{l} {\displaystyle \frac{f}{f-n}}z_{v}-{\displaystyle \frac{fn}{f-n}=z_{c}}\\ \\w_{c}=z_{v}\end{array}\end{cases}" /></p>
<p>根据上两式我们得到：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_1d412848cd24019333c9c375a714276f.png" title="\begin{array}{rcl} z_{buf} &#038; = &#038; {\displaystyle \frac{z_{c}}{z_{v}}}\\ &#038; = &#038; \frac{{\displaystyle \frac{f}{f-n}}z_{v}-{\displaystyle \frac{fn}{f-n}}}{{\displaystyle z_{v}}}\\ &#038; = &#038; {\displaystyle \frac{f}{f-n}}-{\displaystyle \frac{fn}{z_{v}\left(f-n\right)}}\end{array}" style="vertical-align: middle;" class="tex" alt="\begin{array}{rcl} z_{buf} &#038; = &#038; {\displaystyle \frac{z_{c}}{z_{v}}}\\ &#038; = &#038; \frac{{\displaystyle \frac{f}{f-n}}z_{v}-{\displaystyle \frac{fn}{f-n}}}{{\displaystyle z_{v}}}\\ &#038; = &#038; {\displaystyle \frac{f}{f-n}}-{\displaystyle \frac{fn}{z_{v}\left(f-n\right)}}\end{array}" /></p>
<p>移动一下位置：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_6820e8feff900e7f8cbb2d24d4c09ca8.png" title="{\displaystyle \frac{fn}{z_{v}\left(f-n\right)}}={\displaystyle \frac{f}{f-n}}-z_{buf}" style="vertical-align: middle;" class="tex" alt="{\displaystyle \frac{fn}{z_{v}\left(f-n\right)}}={\displaystyle \frac{f}{f-n}}-z_{buf}" /></p>
<p align="left">两边乘以<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_77a843719841a926b6778c61d7415490.png" title="\left(f-n\right)" style="vertical-align: middle;" class="tex" alt="\left(f-n\right)" /></p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_ab544b2238a1d219fac55e4d0abe7fe5.png" title="{\displaystyle \frac{fn}{z_{v}}}=f-z_{buf}\left(f-n\right)" style="vertical-align: middle;" class="tex" alt="{\displaystyle \frac{fn}{z_{v}}}=f-z_{buf}\left(f-n\right)" /></p>
<p>最终得到：</p>
<p align="center"><img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_5a7cb3abe2fab80621e2d89cdc56fb68.png" title="\mathrm{z}_{view}=\frac{fn}{f-\mathrm{z}_{buf}(f-n)}" style="vertical-align: middle;" class="tex" alt="\mathrm{z}_{view}=\frac{fn}{f-\mathrm{z}_{buf}(f-n)}" /></p>
<p>神奇的是，这个公式反而不分 OpenGL 和 D3D 了。这是因为，虽然 OpenGL 和 D3D 的透视变换矩阵虽然不同，定义的 clip space 的 z 也不同，但是，实际上写入物理 zbuf 的值，却是完全一样的，所以一个公式可以搞定。</p>
<p>具体实现上，可以传入 f*n, f, f-n 三个值，以减少 shader 的计算，如果这样的话，HLSL 代码大概是这样的：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp"><span style="color: #666666;">// zparam, for recover view space z, Zview = 2*f*n/((f+n)-Zbuf(f-n)), where Zbuf is [-1,1]</span>
<span style="color: #666666;">// if Zbuf is [0,1], acultly we use, the equation should be</span>
<span style="color: #666666;">//</span>
<span style="color: #666666;">//              f * n</span>
<span style="color: #666666;">// Zview = -------------------</span>
<span style="color: #666666;">//           f - Zbuf(f-n)</span>
<span style="color: #666666;">// faster than use matrix multiply, but only for perspective projection</span>
&nbsp;
<span style="color: #0000ff;">struct</span> ZrecoverParam <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">float</span> near, far, farXnear, farSUBnear<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">const</span> ZrecoverParam g_zrecoverParam<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// return n~f</span>
<span style="color: #0000ff;">float</span> ZR_getViewSpace<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> zbuf<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">return</span> g_zrecoverParam.<span style="color: #007788;">farXnear</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>g_zrecoverParam.<span style="color: #007788;">far</span> <span style="color: #000040;">-</span> zbuf <span style="color: #000040;">*</span> g_zrecoverParam.<span style="color: #007788;">farXnear</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #666666;">// return 0~1 view space</span>
<span style="color: #0000ff;">float</span> ZR_getViewSpaceNormalized<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> zbuf<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">return</span> <span style="color:#800080;">1.0</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>zbuf <span style="color: #000040;">*</span> g_zrecoverParam.<span style="color: #007788;">far</span> <span style="color: #000040;">+</span> g_zrecoverParam.<span style="color: #007788;">farXnear</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/from-zbuffer-recover-viewspace-z/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nullptr</title>
		<link>http://huangdonghai.com/nullptr/</link>
		<comments>http://huangdonghai.com/nullptr/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 17:23:21 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[nullptr]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/index.php/2010/04/22/%e6%af%8f%e6%97%a5%e4%b8%80trick-nullptr/</guid>
		<description><![CDATA[nullptr 将会是 C++1X 标准支持的功能之一(VC2008 有实现这个)。目前 C++ 里 NULL 直接宏定义为 0，这个很不对，首先 0 是个整数字面量，没有指针的含义，另外用宏也对命名空间造成污染，并且会让人造成误解，以为跟 C 语言一样，NULL 是个指针，结果传入模板时推导就会错误，所以有的开发人员和小组直接用 0(比如 Qt)，而不用 NULL。 nullptr 可以解决这个问题，可惜的是 C++1X 遥遥无期。幸运的是，我们可以在 C++98 上近乎完美的模拟出这个功能： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 const class nullptr_t // const 对象... &#123; public: template&#60;class T&#62; operator T*&#40;&#41; const // 转换成任何非成员指针... &#123; return [...]]]></description>
			<content:encoded><![CDATA[<p>nullptr 将会是 C++1X 标准支持的功能之一(VC2008 有实现这个)。目前 C++ 里 NULL 直接宏定义为 0，这个很不对，首先 0 是个整数字面量，没有指针的含义，另外用宏也对命名空间造成污染，并且会让人造成误解，以为跟 C 语言一样，NULL 是个指针，结果传入模板时推导就会错误，所以有的开发人员和小组直接用 0(比如 Qt)，而不用 NULL。</p>
<p>nullptr 可以解决这个问题，可惜的是 C++1X 遥遥无期。幸运的是，我们可以在 C++98 上近乎完美的模拟出这个功能：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="cpp"><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">class</span> nullptr_t  <span style="color: #666666;">// const 对象...</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span>
	operator T<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #666666;">// 转换成任何非成员指针...</span>
	<span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> C, <span style="color: #0000ff;">class</span> T<span style="color: #000080;">&gt;</span>
	operator T C<span style="color: #008080;">::</span><span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>   <span style="color: #666666;">// 或者任何成员指针...</span>
	<span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">void</span> operator<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>  <span style="color: #666666;">// 禁止拿地址</span>
<span style="color: #008000;">&#125;</span> nullptr <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/nullptr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用模板得到 C++ 数组大小</title>
		<link>http://huangdonghai.com/use-template-get-cpp-array-size/</link>
		<comments>http://huangdonghai.com/use-template-get-cpp-array-size/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 16:31:07 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[数组]]></category>
		<category><![CDATA[模板]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=112</guid>
		<description><![CDATA[用宏很容易实现这样的需求 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0]) 但是宏总是会污染名字空间，不建议用，可以用模板很容易实现这个功能 template&#60;typename T, size_t size&#62; size_t ArraySize&#40;T &#40;&#38;&#41;&#91;size&#93;&#41; &#123; return size; &#125;]]></description>
			<content:encoded><![CDATA[<p>用宏很容易实现这样的需求</p>

<div class="wp_syntax"><div class="code"><pre class="cpp"><span style="color: #339900;">#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])</span></pre></div></div>

<p>但是宏总是会污染名字空间，不建议用，可以用模板很容易实现这个功能</p>

<div class="wp_syntax"><div class="code"><pre class="cpp"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T, <span style="color: #0000ff;">size_t</span> size<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">size_t</span> ArraySize<span style="color: #008000;">&#40;</span>T <span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span>size<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">return</span> size<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/use-template-get-cpp-array-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>试证明为无理数</title>
		<link>http://huangdonghai.com/sqrt-2-is-irrational-number/</link>
		<comments>http://huangdonghai.com/sqrt-2-is-irrational-number/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 14:59:23 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[无理数]]></category>
		<category><![CDATA[根号2]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=63</guid>
		<description><![CDATA[假设 是有理数，即有整数a、b， 将 写成最简分数 ，即a和b互质，且 所以 ， 因为 必为偶数，故 亦是偶数 故a为偶数（奇数的平方不会是偶数） 所以必有一整数k，使得a = 2k 将（3）的式子代入（6）： 化简得 因为 是偶数，所以 是偶数，b亦是偶数 所以a和b都是偶数，跟是最简分数的假设矛盾 因为我们发现矛盾，所以（1）的假设错误，不是有理数，即是无理数]]></description>
			<content:encoded><![CDATA[<ol>
<li>假设 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_534fbdc723ee212933aa1af534d2dc69.png" title="\sqrt{2}" style="vertical-align: middle;" class="tex" alt="\sqrt{2}" /> 是有理数，即有整数<i>a</i>、<i>b</i>，<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_c0b761d3b1e82ab378badb1fa7814fa9.png" title="\frac{a}{b}=\sqrt{2}" style="vertical-align: middle;" class="tex" alt="\frac{a}{b}=\sqrt{2}" /> </li>
<li>将 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_534fbdc723ee212933aa1af534d2dc69.png" title="\sqrt{2}" style="vertical-align: middle;" class="tex" alt="\sqrt{2}" /> 写成最简分数 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_0cff26c0fa4cebb9ebc0906490e580df.png" title="\frac{a}{b}" style="vertical-align: middle;" class="tex" alt="\frac{a}{b}" />，即<i>a</i>和<i>b</i>互质，且 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_d5fc0d47b280b9eca2dbd0ca3490b167.png" title="\left(\frac{a}{b}\right)^2=2" style="vertical-align: middle;" class="tex" alt="\left(\frac{a}{b}\right)^2=2" /> </li>
<li>所以 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_1dd996abeca1a7875d258536cc21db0f.png" title="\frac{a^2}{b^2} =2" style="vertical-align: middle;" class="tex" alt="\frac{a^2}{b^2} =2" />，<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_8223d44bed7c633155faf1c00ade195b.png" title="a^2=2b^2" style="vertical-align: middle;" class="tex" alt="a^2=2b^2" /> </li>
<li>因为 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_d005a0bab84f494eb41100e04481ac34.png" title="2b^2" style="vertical-align: middle;" class="tex" alt="2b^2" /> 必为偶数，故 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_732a3df051015e5f1348425a685b080d.png" title="a^2" style="vertical-align: middle;" class="tex" alt="a^2" /> 亦是偶数 </li>
<li>故<i>a</i>为偶数（奇数的平方不会是偶数） </li>
<li>所以必有一整数<i>k</i>，使得<i>a</i> = 2<i>k</i> </li>
<li>将（3）的式子代入（6）：<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_09ea1318f244951325ea64a56496df7d.png" title="2b^2=\left(2k\right)^2" style="vertical-align: middle;" class="tex" alt="2b^2=\left(2k\right)^2" /> </li>
<li>化简得 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_0c089e3682a071b72f320f5e9c1083ae.png" title="b^2=2k^2" style="vertical-align: middle;" class="tex" alt="b^2=2k^2" /> </li>
<li>因为 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_abbc03c6860779f512f727117c4561ec.png" title="2k^2" style="vertical-align: middle;" class="tex" alt="2k^2" /> 是偶数，所以 <img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_e2cf2dc43591fde2819586f879620f64.png" title="b^2" style="vertical-align: middle;" class="tex" alt="b^2" /> 是偶数，<i>b</i>亦是偶数 </li>
<li>所以<i>a</i>和<i>b</i>都是偶数，跟<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_0cff26c0fa4cebb9ebc0906490e580df.png" title="\frac{a}{b}" style="vertical-align: middle;" class="tex" alt="\frac{a}{b}" />是最简分数的假设矛盾 </li>
<li>因为我们发现矛盾，所以（1）的假设错误，<img src="http://huangdonghai.com/wp-content/plugins/easy-latex/cache/tex_534fbdc723ee212933aa1af534d2dc69.png" title="\sqrt{2}" style="vertical-align: middle;" class="tex" alt="\sqrt{2}" />不是有理数，即是无理数 </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/sqrt-2-is-irrational-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C/C++/C like 语言 for 语句内变量作用域的问题</title>
		<link>http://huangdonghai.com/cpp-for-scope/</link>
		<comments>http://huangdonghai.com/cpp-for-scope/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 08:14:45 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[for语句]]></category>
		<category><![CDATA[变量作用域]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=55</guid>
		<description><![CDATA[按照 ANSI C, C++ 标准，for 语句里定义的变量的作用域应该只在这个 for 语句内：比如： for &#40;int i=0; i&#60;100; i++&#41; &#123;... &#125; 但是有些编译器不符合这个标准，比如 VC 6，D3D HLSL，如果你要在几个不同的编译器下编译，就有毛病。 对于不符合标准的编译器，其实你可以这么做 #define for if (0) else for 搞定。]]></description>
			<content:encoded><![CDATA[<p>按照 ANSI C, C++ 标准，for 语句里定义的变量的作用域应该只在这个 for 语句内：比如：</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">100</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>... <span style="color: #009900;">&#125;</span></pre></div></div>

<p>但是有些编译器不符合这个标准，比如 VC 6，D3D HLSL，如果你要在几个不同的编译器下编译，就有毛病。</p>
<p>对于不符合标准的编译器，其实你可以这么做</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#define for if (0) else for</span></pre></div></div>

<p>搞定。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/cpp-for-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips and Tricks: 新分类</title>
		<link>http://huangdonghai.com/new-tips-tricks-category/</link>
		<comments>http://huangdonghai.com/new-tips-tricks-category/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 08:12:15 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[火腿]]></category>
		<category><![CDATA[花生]]></category>
		<category><![CDATA[豆干]]></category>
		<category><![CDATA[金圣叹]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=53</guid>
		<description><![CDATA[每天一个小技巧。 第一个：金圣叹说，花生米与豆干同嚼，大有火腿之滋味。]]></description>
			<content:encoded><![CDATA[<p>每天一个小技巧。</p>
<p>第一个：金圣叹说，花生米与豆干同嚼，大有火腿之滋味。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/new-tips-tricks-category/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于 PPTP over PPPoE 准确的 MTU 值</title>
		<link>http://huangdonghai.com/pptp-over-pppoe-mtu/</link>
		<comments>http://huangdonghai.com/pptp-over-pppoe-mtu/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 23:39:31 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>
		<category><![CDATA[MTU]]></category>
		<category><![CDATA[PPPoE]]></category>
		<category><![CDATA[PPTP]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=46</guid>
		<description><![CDATA[先看下表： Ethernet MinSize = 512bit = 64 Byte Ethernet MaxSize = 1518 Byte so Ethernet IP MTU = 1518 - 18 ( 6 SRCMAC+ 6 DSTMAC+ 2 TYPE+ 4 CRC) = 1500 B so Ethernet IP TCP MSS = 1500 - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1460 B so Ethernet IP UDP [...]]]></description>
			<content:encoded><![CDATA[<p>先看下表：</p>

<div class="wp_syntax"><div class="code"><pre class="text">Ethernet MinSize = 512bit = 64 Byte
Ethernet MaxSize = 1518 Byte
so Ethernet IP MTU = 1518 - 18 ( 6 SRCMAC+ 6 DSTMAC+ 2 TYPE+ 4 CRC) = 1500 B
so Ethernet IP TCP MSS = 1500 - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1460 B
so Ethernet IP UDP MTU/MRU = 1500 - 28 ( 20 IP_HEADER + 8 UDP_HEADER ) = 1472 B
so PPPoE MTU/MRU = 1500 - 8 ( 6 PPPoE_SESSION + 2 PPP_HEADER ) = 1492 B
so TCP over PPPoE MSS = 1492 ( PPPoE MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1452
so PPTP MTU/MRU = 1500 - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1444 B
so TCP over PPTP MSS = 1444 ( PPTP MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1404
so L2TP MTU/MRU = 1500 - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1460 B
so TCP over L2TP MSS = 1460 ( L2TP MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1420 B
so PPTP over PPPoE MTU/MRU = 1492 ( PPPoE MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1436 B
so PPTP over PPTP MTU/MRU = 1444 ( PPTP MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1388 B
so PPTP over L2TP MTU/MRU = 1460 ( L2TP MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1404 B
so L2TP over PPPoE MTU/MRU = 1492 ( PPPoE MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1452 B
so L2TP over PPTP MTU/MRU = 1444 ( PPTP MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1404 B
so L2TP over L2TP MTU/MRU = 1460 ( L2TP MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1420 B</pre></div></div>

<p>故而，准确的值是 1436，前篇的 1400 偏保守了点。</p>
<p>如果你用 ADSL 上网，然后用 PPTP 来翻Wall，那么，你实际上是&#160; PPP 协议跑在 TCP 协议上再跑在 IP 协议上再跑在 PPP 协议上再跑在 IP 协议上再跑在以太网协议上。1518 字节的最大以太网 frame，扣来扣去，就剩下 1436。如果你 pptp 连公司的 vpn，公司又 pppoe(adsl拨号)，然后你再 pptp 来翻功夫网，那么，你的 MTU 只能设为 1518-18-8-56-56=1380 字节。</p>
<p>就是这么回事。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/pptp-over-pppoe-mtu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linode VPS Ubuntu 9.10 PPTPD, LEMP(LNMP) 安装流程</title>
		<link>http://huangdonghai.com/linode-vps-ubuntu-setup/</link>
		<comments>http://huangdonghai.com/linode-vps-ubuntu-setup/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 18:43:37 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>
		<category><![CDATA[LEMP]]></category>
		<category><![CDATA[Linode]]></category>
		<category><![CDATA[LNMP]]></category>
		<category><![CDATA[MTU]]></category>
		<category><![CDATA[NGINX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PPTPD]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=34</guid>
		<description><![CDATA[VPS 很流行，嗯嗯。不是要翻那个啥么，所以从虚拟主机换成了 VPS。我选用操作系统是 Ubuntu 9.10，其他操作系统也差不多。 现在把安装流程记录下来，防止自己忘记，别人也会有参考价值。为了省事，尽量选择源里已经有的软件，Ubuntu 9.10 源里的软件相对来说还是比较新的。 0. 准备工作 首先修改源设置， $ vim /etc/apt/sources.list 把里面的注释掉的源取消注释，否则 nginx 这个包找不到，内容大概是： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ## main &#38; restricted repositories deb http://us.archive.ubuntu.com/ubuntu/ karmic main restricted deb-src http://us.archive.ubuntu.com/ubuntu/ karmic main restricted &#160; deb http://security.ubuntu.com/ubuntu karmic-security main restricted deb-src http://security.ubuntu.com/ubuntu [...]]]></description>
			<content:encoded><![CDATA[<p>VPS 很流行，嗯嗯。不是要翻那个啥么，所以从虚拟主机换成了 VPS。我选用操作系统是 Ubuntu 9.10，其他操作系统也差不多。</p>
<p><a href="http://huangdonghai.com/wp-content/uploads/2010/04/image3.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin-left: 0px; margin-right: 0px; border-right-width: 0px" height="439" alt="image" src="http://huangdonghai.com/wp-content/uploads/2010/04/image_thumb3.png" width="646" border="0" /></a></p>
<p>  <div class='toc wptoc'>
<h2>Contents</h2>
<ul class='toc-odd level-1'>
	<li>
		<a href="#0._"><strong>0. 准备工作</strong></a>
	</li>
	<li>
		<a href="#pptpd"><strong>1. 安装 pptpd</strong></a>
	</li>
	<li>
		<a href="#nginx_php_mysql"><strong>2. 安装 nginx, php, mysql</strong></a>
	</li>
</div>

<p>现在把安装流程记录下来，防止自己忘记，别人也会有参考价值。为了省事，尽量选择源里已经有的软件，Ubuntu 9.10 源里的软件相对来说还是比较新的。</p>
<span id="0._"><h4><strong>0. 准备工作</strong></h4></span>
<p>首先修改源设置，</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></div></div>

<p>把里面的注释掉的源取消注释，否则 nginx 这个包找不到，内容大概是：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">## main &amp; restricted repositories</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic main restricted
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic main restricted
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu karmic-security main restricted
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu karmic-security main restricted
&nbsp;
<span style="color: #666666; font-style: italic;">## universe repositories</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic universe
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic universe
deb http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic-updates universe
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>us.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> karmic-updates universe
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu karmic-security universe
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu karmic-security universe</pre></td></tr></table></div>

<p>然后更新一下 apt 库的 cache</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> upgrade</pre></div></div>

<p>然后</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">apt-cache</span> search <span style="color: #660033;">-n</span> nginx</pre></div></div>

<p>就会发现找得到 nginx。</p>
</p>
<p><span id="more-34"></span></p>
<span id="pptpd"><h4><strong>1. 安装 pptpd</strong></h4></span>
<p>从源里安装：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> pptpd</pre></div></div>

<p>修改 /etc/pptpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>pptpd.conf</pre></div></div>

<p>在文件尾部添加，ip 不要和你以用的 ip 段和你的 ISP 给你的 ip 段冲突就可以</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash">localip 10.0.0.1 
remoteip 10.0.0.20-<span style="color: #000000;">220</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ppp<span style="color: #000000; font-weight: bold;">/</span>pptpd-options</pre></div></div>

<p>修改 dns 设置</p>

<div class="wp_syntax"><div class="code"><pre class="bash">ms-dns 8.8.8.8 
ms-dns 8.8.4.4</pre></div></div>

<p>增加用户</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ppp<span style="color: #000000; font-weight: bold;">/</span>chap-secrets</pre></div></div>

<p>按照格式添加用户，比如</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># Secrets for authentication using CHAP</span>
<span style="color: #666666; font-style: italic;"># client        server  secret                  IP addresses</span>
fuckgfw pptpd fuckgfw <span style="color: #000000; font-weight: bold;">*</span></pre></td></tr></table></div>

<p>这个时候已经可以连上了，但是不能访问外网，因为没开转发和NAT。</p>
<p>配置 forward 和 NAT</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> sysctl.conf</pre></div></div>

<p>取消下面那行的注释</p>

<div class="wp_syntax"><div class="code"><pre class="bash">net.ipv4.ip_forward=<span style="color: #000000;">1</span></pre></div></div>

<p>开启 NAT 增加一个路由表文件</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>iptables</pre></div></div>

<p>内容如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="bash"><span style="color: #666666; font-style: italic;"># Generated by iptables-save v1.4.4 on Fri Apr  9 17:15:56 2010</span>
<span style="color: #000000; font-weight: bold;">*</span>nat
:PREROUTING ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span>:<span style="color: #000000;">272</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
:POSTROUTING ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>:<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
:OUTPUT ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span>:<span style="color: #000000;">124</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> eth0 <span style="color: #660033;">-j</span> MASQUERADE
COMMIT
<span style="color: #666666; font-style: italic;"># Completed on Fri Apr  9 17:15:56 2010</span>
<span style="color: #666666; font-style: italic;"># Generated by iptables-save v1.4.4 on Fri Apr  9 17:15:56 2010</span>
<span style="color: #000000; font-weight: bold;">*</span>filter
:INPUT ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">5909</span>:<span style="color: #000000;">607601</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
:FORWARD ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>:<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
:OUTPUT ACCEPT <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">5324</span>:<span style="color: #000000;">2972751</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
COMMIT
<span style="color: #666666; font-style: italic;"># Completed on Fri Apr  9 17:15:56 2010</span></pre></td></tr></table></div>

<p>让配置表启动时自动生效</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>interfaces</pre></div></div>

<p>增加下面一行</p>

<div class="wp_syntax"><div class="code"><pre class="bash">pre-up iptables-restore <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>iptables</pre></div></div>

<p>这个时候重启一下让配置生效</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ shutdown <span style="color: #660033;">-r</span> now</pre></div></div>

<p>开始愉快的翻那个啥了。<strong>一般网上的其他教程到这就结束了。但是实际上你发现有些网站打不开，有些邮件读不了，特别是通过 adsl 拨号上网的。这是因为 ppp 的 MTU 要调小点才比较好</strong>：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ppp<span style="color: #000000; font-weight: bold;">/</span>ip-up</pre></div></div>

<p>添加一行，把 MTU 设置为 1400，(<a href="http://huangdonghai.com/2010/04/17/46/">修正</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> $<span style="color: #000000;">1</span> mtu <span style="color: #000000;">1400</span></pre></div></div>

<p>大功告成。</p>
<span id="nginx_php_mysql"><h4><strong>2. 安装 nginx, php, mysql</strong></h4></span>
<p>依然从源里安装：</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server nginx php-cgi php-gd php-mysql</pre></div></div>

<p>创建个 factcgi 的 init 脚本</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php-fastcgi</pre></div></div>

<p>内容:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">BIND_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>php-fastcgi
<span style="color: #007800;">BIND</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BIND_DIR</span>/php.sock&quot;</span>
<span style="color: #007800;">USER</span>=www-data
<span style="color: #007800;">PHP_FCGI_CHILDREN</span>=<span style="color: #000000;">12</span>
<span style="color: #007800;">PHP_FCGI_MAX_REQUESTS</span>=<span style="color: #000000;">1000</span>
&nbsp;
<span style="color: #007800;">PHP_CGI</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php-cgi
<span style="color: #007800;">PHP_CGI_NAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$PHP_CGI</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">PHP_CGI_ARGS</span>=<span style="color: #ff0000;">&quot;- USER=<span style="color: #007800;">$USER</span> PATH=/usr/bin PHP_FCGI_CHILDREN=<span style="color: #007800;">$PHP_FCGI_CHILDREN</span> PHP_FCGI_MAX_REQUESTS=<span style="color: #007800;">$PHP_FCGI_MAX_REQUESTS</span> <span style="color: #007800;">$PHP_CGI</span> -b <span style="color: #007800;">$BIND</span>&quot;</span>
<span style="color: #007800;">RETVAL</span>=<span style="color: #000000;">0</span>
&nbsp;
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting PHP FastCGI: &quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$BIND_DIR</span>
    <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$USER</span> <span style="color: #007800;">$BIND_DIR</span>
    start-stop-daemon <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--start</span> <span style="color: #660033;">--background</span> <span style="color: #660033;">--chuid</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$USER</span>&quot;</span> <span style="color: #660033;">--exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$PHP_CGI_ARGS</span>
    <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PHP_CGI_NAME</span>.&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping PHP FastCGI: &quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-w</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span> <span style="color: #007800;">$PHP_CGI</span>
    <span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$BIND_DIR</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PHP_CGI_NAME</span>.&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
    start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        start
  <span style="color: #000000; font-weight: bold;">;;</span>
    stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        stop
  <span style="color: #000000; font-weight: bold;">;;</span>
    restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        stop
        start
  <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: php-fastcgi {start|stop|restart}&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$RETVAL</span></pre></td></tr></table></div>

<p>然后启动 fastcgi 服务</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php-fastcgi start</pre></div></div>

<p>搞定。配置 nginx 的时候，每个 virtual host 要加上 php cgi 的转发。举个例子：</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>default</pre></div></div>

<p>内容：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="bash">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        listen   <span style="color: #000000;">80</span>;
        server_name  huangdonghai.com www.huangdonghai.com <span style="color: #000000; font-weight: bold;">*</span>.huangdonghai.com;
&nbsp;
        access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>localhost.access.log;
&nbsp;
        location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                root   <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>huangdonghai.com;
                index  index.html index.htm index.php;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        location ~ \.php$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            fastcgi_pass   unix:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>php-fastcgi<span style="color: #000000; font-weight: bold;">/</span>php.sock;
&nbsp;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>huangdonghai.com<span style="color: #007800;">$fastcgi_script_name</span>;
            include         fastcgi_params;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># deny access to .htaccess files, if Apache's document root</span>
        <span style="color: #666666; font-style: italic;"># concurs with nginx's one</span>
        <span style="color: #666666; font-style: italic;">#</span>
        <span style="color: #666666; font-style: italic;">#location ~ /\.ht {</span>
                <span style="color: #666666; font-style: italic;">#deny  all;</span>
        <span style="color: #666666; font-style: italic;">#}</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>然后</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx restart</pre></div></div>

<p>就大功告成。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/linode-vps-ubuntu-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VIM快捷键图</title>
		<link>http://huangdonghai.com/vim-graphical-cheat-sheet/</link>
		<comments>http://huangdonghai.com/vim-graphical-cheat-sheet/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:41:40 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[五味杂陈]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=9</guid>
		<description><![CDATA[2010.4.27补充：中文版的]]></description>
			<content:encoded><![CDATA[<p><a href="http://huangdonghai.com/?attachment_id=14" rel="attachment wp-att-14"><img class="alignnone size-medium wp-image-14" title="vim" height="452" alt="VIM快捷键图" src="/wp-content/uploads/2010/04/vim-640x452.gif" width="640" /></a></p>
<p>2010.4.27补充：中文版的</p>
<p><a href="http://huangdonghai.com/wp-content/uploads/2010/04/4054593399_34e0d24433_o1.gif"><img title="4054593399_34e0d24433_o" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="452" alt="4054593399_34e0d24433_o" src="http://huangdonghai.com/wp-content/uploads/2010/04/4054593399_34e0d24433_o_thumb1.gif" width="640" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/vim-graphical-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ipv6 over 广州电信 ADSL</title>
		<link>http://huangdonghai.com/ipv6-over-guangzhou-adsl/</link>
		<comments>http://huangdonghai.com/ipv6-over-guangzhou-adsl/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 09:40:36 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[系统网络]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=7</guid>
		<description><![CDATA[偶然发现广州电信的 ADSL 支持 ipv6 协议了。xp 在控制台用 ipv6 install 就可以安装ipv6 协议栈。然后打开 ipv6.google.com，看看能不能打开页面，ipv6 版本的 google 图标是动画的。 trace 一个纯 ipv6 网站： D:\showip&#62;tracert video6.sjtu.edu.cn Tracing route to video6.sjtu.edu.cn [2001:da8:a4:ff::84] over a maximum of 30 hops: 1 64 ms 64 ms 67 ms 2001:da8:8000:d010:0:5efe:202.120.58.150 2 66 ms 67 ms 64 ms 2001:da8:8000:6022::1 3 65 ms 64 ms 65 ms 2001:da8:8000:80d::1 [...]]]></description>
			<content:encoded><![CDATA[<p>偶然发现广州电信的 ADSL 支持 ipv6 协议了。xp 在控制台用 ipv6 install 就可以安装ipv6 协议栈。然后打开 ipv6.google.com，看看能不能打开页面，ipv6 版本的 google 图标是动画的。</p>
<p>trace 一个纯 ipv6 网站：</p>
<pre>D:\showip&gt;tracert video6.sjtu.edu.cn

Tracing route to video6.sjtu.edu.cn [2001:da8:a4:ff::84]
over a maximum of 30 hops:

  1    64 ms    64 ms    67 ms  2001:da8:8000:d010:0:5efe:202.120.58.150
  2    66 ms    67 ms    64 ms  2001:da8:8000:6022::1
  3    65 ms    64 ms    65 ms  2001:da8:8000:80d::1
  4    66 ms    66 ms    68 ms  2001:da8:8000:101::54
  5    65 ms    67 ms    64 ms  2001:da8:8000:104::77
  6    65 ms    64 ms    63 ms  2001:da8:8000:105::46
  7    66 ms    67 ms    66 ms  2001:da8:8000:102::205
  8    65 ms    66 ms    65 ms  cernet2.net [2001:da8:a4:2::1]
  9    64 ms    64 ms    65 ms  cernet2.net [2001:da8:a4:ff::84]

Trace complete.</pre>
<p>打开 <a href="http://www.ipv6.org">www.ipv6.org</a>，应该可以看到自己的 ipv6 地址。</p>
<p>soso</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/ipv6-over-guangzhou-adsl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hello world！</title>
		<link>http://huangdonghai.com/hello-world/</link>
		<comments>http://huangdonghai.com/hello-world/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 16:38:32 +0000</pubDate>
		<dc:creator>Huang Donghai</dc:creator>
				<category><![CDATA[五味杂陈]]></category>

		<guid isPermaLink="false">http://huangdonghai.com/?p=1</guid>
		<description><![CDATA[欢迎来到我的博客。这并不是系统自动生成的演示文章。]]></description>
			<content:encoded><![CDATA[<p>欢迎来到我的博客。这并不是系统自动生成的演示文章。</p>
]]></content:encoded>
			<wfw:commentRss>http://huangdonghai.com/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

