<?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://bluehua.org/feed" rel="self" type="application/rss+xml" />
	<link>http://bluehua.org</link>
	<description>分享所学,backup一切~</description>
	<lastBuildDate>Fri, 13 Apr 2012 14:08:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>2B长城宽带正在做网站内容挟持，私自投放广告的勾当～</title>
		<link>http://bluehua.org/2012/04/13/1867.html</link>
		<comments>http://bluehua.org/2012/04/13/1867.html#comments</comments>
		<pubDate>Fri, 13 Apr 2012 14:06:25 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1867</guid>
		<description><![CDATA[访问招行的网站，一片空白，先跳出一个广告，感觉不对劲，立刻查看dom，发现已经被iframe加了壳。此2b宽带运营商之前就干过dns挟持到自己的官网的事。。不曝光不足以平息自己的愤怒～～]]></description>
			<content:encoded><![CDATA[<p>访问招行的网站，一片空白，先跳出一个广告，感觉不对劲，立刻查看dom，发现已经被iframe加了壳。此2b宽带运营商之前就干过dns挟持到自己的官网的事。。不曝光不足以平息自己的愤怒～～</p>
<p><a href="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午9.44.54.png"><img src="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午9.44.54-300x174.png" alt="" title="屏幕快照 2012-04-13 下午9.44.54" width="300" height="174" class="alignnone size-medium wp-image-1869" /></a></p>
<p><a href="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午9.50.26.png"><img src="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午9.50.26-300x176.png" alt="" title="屏幕快照 2012-04-13 下午9.50.26" width="300" height="176" class="alignnone size-medium wp-image-1870" /></a></p>
<p><a href="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午10.02.42.png"><img src="http://bluehua.org/wp-content/uploads/2012/04/屏幕快照-2012-04-13-下午10.02.42.png" alt="" title="屏幕快照 2012-04-13 下午10.02.42" width="408" height="111" class="alignnone size-full wp-image-1872" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/04/13/1867.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>NPAPI插件开发备忘</title>
		<link>http://bluehua.org/2012/04/03/1839.html</link>
		<comments>http://bluehua.org/2012/04/03/1839.html#comments</comments>
		<pubDate>Tue, 03 Apr 2012 12:50:57 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[soft]]></category>
		<category><![CDATA[NPAPI]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1839</guid>
		<description><![CDATA[1 . 如何在NPClass中存储自己的自定义数据? 只要实现NPClass的allocate和deallocate两个方法，并定义自己的扩展NPClass结构便可 static struct NPClass nativeScriptablePluginClass = &#123; NP_CLASS_STRUCT_VERSION, JSCLASS_alloc, JSCLASS_free, NULL, JSCLASS_hasMethod, JSCLASS_invoke, NULL, JSCLASS_hasProperty, JSCLASS_getProperty, NULL, NULL, &#125;; &#160; //定义自己的扩展结构体 typedef struct MyScriptPluginClass MyScriptPluginClass; struct MyScriptPluginClass &#123; NPClass nativeClass; NPUTF8 *someStringData; //这是我们的自定义数据 &#125;; &#160; //在自定义的alloc方法中返回为自定义NPClass申请的内存 NPObject* JSCLASS_alloc&#40;NPP inst, NPClass *aClass&#41; &#123; return &#40;NPObject *&#41;malloc&#40;sizeof&#40;struct MyScriptPluginClass&#41;&#41;; &#125; &#160; //相应的释放 void JSCLASS_free&#40;NPObject *nobj&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>1 . 如何在NPClass中存储自己的自定义数据?</p>
<p>只要实现NPClass的allocate和deallocate两个方法，并定义自己的扩展NPClass结构便可</p>

<div class="wp_syntax"><div class="code overflow"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> NPClass nativeScriptablePluginClass <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    NP_CLASS_STRUCT_VERSION<span style="color: #339933;">,</span>
    JSCLASS_alloc<span style="color: #339933;">,</span>
    JSCLASS_free<span style="color: #339933;">,</span>
    NULL<span style="color: #339933;">,</span>
    JSCLASS_hasMethod<span style="color: #339933;">,</span>
    JSCLASS_invoke<span style="color: #339933;">,</span>
    NULL<span style="color: #339933;">,</span>
    JSCLASS_hasProperty<span style="color: #339933;">,</span>
    JSCLASS_getProperty<span style="color: #339933;">,</span>
    NULL<span style="color: #339933;">,</span>
    NULL<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//定义自己的扩展结构体</span>
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> MyScriptPluginClass MyScriptPluginClass<span style="color: #339933;">;</span>
<span style="color: #993333;">struct</span> MyScriptPluginClass <span style="color: #009900;">&#123;</span>
    NPClass nativeClass<span style="color: #339933;">;</span>
    NPUTF8 <span style="color: #339933;">*</span>someStringData<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//这是我们的自定义数据</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//在自定义的alloc方法中返回为自定义NPClass申请的内存</span>
NPObject<span style="color: #339933;">*</span> JSCLASS_alloc<span style="color: #009900;">&#40;</span>NPP inst<span style="color: #339933;">,</span> NPClass <span style="color: #339933;">*</span>aClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>NPObject <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> MyScriptPluginClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//相应的释放</span>
<span style="color: #993333;">void</span> JSCLASS_free<span style="color: #009900;">&#40;</span>NPObject <span style="color: #339933;">*</span>nobj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//之后都可以通过种类型强转得到我们自定义的结构体</span>
    MyScriptPluginClass <span style="color: #339933;">*</span>obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MyScriptPluginClass <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>nobj<span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span>obj<span style="color: #339933;">-&gt;</span>someStringData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    free<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>2 . 如何在插件中调用页面中的js方法?</p>

<div class="wp_syntax"><div class="code overflow"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//这里我们将实现一个可以调用window.eval的方法</span>
<span style="color: #993333;">void</span> JSAPI_methodImpl_getLocation<span style="color: #009900;">&#40;</span>NPObject <span style="color: #339933;">*</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    NPString rt<span style="color: #339933;">;</span>
    MyScriptPluginClass <span style="color: #339933;">*</span>obj <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MyScriptPluginClass <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>o<span style="color: #339933;">;</span>
    NPP _npp <span style="color: #339933;">=</span> obj<span style="color: #339933;">-&gt;</span>instance<span style="color: #339933;">;</span>
    NPObject <span style="color: #339933;">*</span>window <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//static NPNetscapeFuncs* browser;</span>
    <span style="color: #666666; font-style: italic;">//获取window对象</span>
    browser<span style="color: #339933;">-&gt;</span>getvalue<span style="color: #009900;">&#40;</span>_npp<span style="color: #339933;">,</span> NPNVWindowNPObject<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    NPIdentifier eval <span style="color: #339933;">=</span> browser<span style="color: #339933;">-&gt;</span>getstringidentifier<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;eval&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    NPVariant evalResponse<span style="color: #339933;">;</span>
    NPVariant evalCode<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//初始化我们需要eval的代码</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>c_javascriptCode <span style="color: #339933;">=</span> calloc<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2048</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sprintf<span style="color: #009900;">&#40;</span>c_javascriptCode<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;(function(){&quot;</span>
            <span style="color: #ff0000;">&quot;return window.location.href;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            <span style="color: #ff0000;">&quot;})();&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    STRINGZ_TO_NPVARIANT<span style="color: #009900;">&#40;</span>c_javascriptCode<span style="color: #339933;">,</span> evalCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    NPVariant args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>evalCode<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//window.eval(mycode);</span>
    browser<span style="color: #339933;">-&gt;</span>invoke<span style="color: #009900;">&#40;</span>_npp<span style="color: #339933;">,</span> window<span style="color: #339933;">,</span> eval<span style="color: #339933;">,</span> args<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>evalResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    free<span style="color: #009900;">&#40;</span>c_javascriptCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//判断一下js的返回值是否为我们期望的字符串类型</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>NPVARIANT_IS_STRING<span style="color: #009900;">&#40;</span>evalResponse<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//得到我们想要的返回值</span>
        rt <span style="color: #339933;">=</span> NPVARIANT_TO_STRING<span style="color: #009900;">&#40;</span>evalResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        fprintf<span style="color: #009900;">&#40;</span>stdout<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;window.location = %.*s&quot;</span><span style="color: #339933;">,</span> rt.<span style="color: #202020;">UTF8Length</span><span style="color: #339933;">,</span> rt.<span style="color: #202020;">UTF8Characters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    browser<span style="color: #339933;">-&gt;</span>releaseobject<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    browser<span style="color: #339933;">-&gt;</span>releasevariantvalue<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>evalResponse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>3 . 如何管理内存<br />
<a href="http://colonelpanic.net/2009/12/memory-management-in-npapi/">http://colonelpanic.net/2009/12/memory-management-in-npapi/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/04/03/1839.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>让PHP”WYSIWYG”起来～～</title>
		<link>http://bluehua.org/2012/04/03/1850.html</link>
		<comments>http://bluehua.org/2012/04/03/1850.html#comments</comments>
		<pubDate>Tue, 03 Apr 2012 12:49:19 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[WYSIWYG]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1850</guid>
		<description><![CDATA[最近因为配置问题搞的我有点烦了。。，开发时我本地搭一个开发环境，测试时qa自己会搭一个测试环境，部署之前pe也会自己搭一个测试环境。因为环境之间的差异，多次造成程序不能按照预期运行。所以也学习开源软件，在所有项目的loader里做一下环境判断。我觉得真的有必要学习下css搞个reset.php啥的(TODO)。。。 最多的问题出在PHP不能“所见即所得”，传參被“智能”的过滤或覆盖 //默认应该是没有配置filter，但是哪位大神配置了特殊字符过滤，导致json串被转义 if &#40;ini_get&#40;'filter.default'&#41; !== 'unsafe_raw'&#41; die&#40;'please disable filter.default in php.ini!'&#41;; //不解释，这个选项无论如何都应该干掉 if &#40;get_magic_quotes_gpc&#40;&#41;&#41; die&#40;'please disable magic_quotes_gpc in php.ini!'&#41;; &#160; //php 5.3开始默认配置REQUEST里不再包含 COOKIE,但是测试环境配了个php 5.2 //导致POST参数被COOKIE同名参数覆盖。。。 &#160; if &#40;ini_get&#40;'request_order'&#41; !== 'GP'&#41; &#123; foreach&#40;$_COOKIE as $k=&#62;$v&#41; &#123; if &#40;isset&#40;$_GET&#91;$k&#93;&#41;&#41; &#123; $_REQUEST&#91;$k&#93; = $_GET&#91;$k&#93;; &#125; &#160; if &#40;isset&#40;$_POST&#91;$k&#93;&#41;&#41; &#123; $_REQUEST&#91;$k&#93; = $_POST&#91;$k&#93;; &#125; &#160; if &#40;!isset&#40;$_POST&#91;$k&#93;&#41; &#38;&#38; [...]]]></description>
			<content:encoded><![CDATA[<p>最近因为配置问题搞的我有点烦了。。，开发时我本地搭一个开发环境，测试时qa自己会搭一个测试环境，部署之前pe也会自己搭一个测试环境。因为环境之间的差异，多次造成程序不能按照预期运行。所以也学习开源软件，在所有项目的loader里做一下环境判断。我觉得真的有必要学习下css搞个reset.php啥的(TODO)。。。</p>
<p>最多的问题出在PHP不能“所见即所得”，传參被“智能”的过滤或覆盖</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//默认应该是没有配置filter，但是哪位大神配置了特殊字符过滤，导致json串被转义</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'filter.default'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'unsafe_raw'</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'please disable filter.default in php.ini!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//不解释，这个选项无论如何都应该干掉</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'please disable magic_quotes_gpc in php.ini!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//php 5.3开始默认配置REQUEST里不再包含 COOKIE,但是测试环境配了个php 5.2</span>
<span style="color: #666666; font-style: italic;">//导致POST参数被COOKIE同名参数覆盖。。。</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'request_order'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">'GP'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/04/03/1850.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>补了几篇文章竟然超了。。</title>
		<link>http://bluehua.org/2012/03/21/1832.html</link>
		<comments>http://bluehua.org/2012/03/21/1832.html#comments</comments>
		<pubDate>Wed, 21 Mar 2012 14:42:29 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1832</guid>
		<description><![CDATA[这tm才应该是第201啊。。。现在只能含恨202]]></description>
			<content:encoded><![CDATA[<p>这tm才应该是第201啊。。。现在只能含恨202</p>
<p><a href="http://bluehua.org/wp-content/uploads/2012/03/202.png"><img src="http://bluehua.org/wp-content/uploads/2012/03/202.png" alt="" title="202" width="505" height="290" class="alignnone size-full wp-image-1833" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/03/21/1832.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>node.js中mysql-native的掉线重联</title>
		<link>http://bluehua.org/2012/03/21/1826.html</link>
		<comments>http://bluehua.org/2012/03/21/1826.html#comments</comments>
		<pubDate>Wed, 21 Mar 2012 14:35:25 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mysql-native]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1826</guid>
		<description><![CDATA[由于受一篇性能测试的文章的影响，选择了mysql-native作为node的mysql客户端，由于没有自动重联的功能,长时间运行后就会掉线,所以加了一段判断掉线的代码: var Mysql = null; &#160; function MysqlConnect&#40;&#41; &#123; //... } &#160; MysqlSafeQuery = function&#40;sql&#41; &#123; if &#40;!Mysql &#124;&#124; !Mysql.connection.writable&#41; &#123; MysqlConnect&#40;&#41;; &#125; &#160; return Mysql.query&#40;sql&#41;; &#125;]]></description>
			<content:encoded><![CDATA[<p>由于受一篇<a href="http://cnodejs.org/topic/4f16442ccae1f4aa2700112f">性能测试的文章</a>的影响，选择了mysql-native作为node的mysql客户端，由于没有自动重联的功能,长时间运行后就会掉线,所以加了一段判断掉线的代码:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Mysql <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> MysqlConnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//... }</span>
&nbsp;
MysqlSafeQuery <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Mysql <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>Mysql.<span style="color: #660066;">connection</span>.<span style="color: #660066;">writable</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        MysqlConnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> Mysql.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/03/21/1826.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JsonStream.js</title>
		<link>http://bluehua.org/2012/03/21/1808.html</link>
		<comments>http://bluehua.org/2012/03/21/1808.html#comments</comments>
		<pubDate>Wed, 21 Mar 2012 13:02:32 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JsonStream]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1808</guid>
		<description><![CDATA[JsonStream.js是一个用于node.js的双向通信协议实现，它使用json作为数据包格式，可以用于socket，也可以用于http长连接,同时自带了简单的rpc实现。这段代码现在被用于一个对实时性要求比较高的小项目，本来打算用python+twisted做，但是后来临时决定尝试一下node.js，下面举例说明用法: 第一个例子，最简单的应用，基于socket通信,发送和接受json数据 StreamServer.js var Net = require&#40;'net'&#41;; var JsonStream = require&#40;'./JsonStream.js'&#41;; &#160; //创建一个普通的socket server var server = Net.createServer&#40;function&#40;c&#41; &#123; //当有客户端连接后,socket连接之上创建一个JsonStream var stream = new JsonStream.Stream&#40;c&#41;; &#160; //监听客户端发来的json数据 stream.on&#40;'json', function&#40;json&#41; &#123; console.log&#40;'receiv json from client:'&#41;; console.log&#40;json&#41;; &#125;&#41;; &#160; //没三秒钟向客户端发送一个json数据 setInterval&#40;function&#40;&#41;&#123; stream.write&#40;&#123; data:'hello client', time:new Date&#40;&#41; &#125;&#41;; &#125;, 3000&#41;; &#125;&#41;; &#160; server.listen&#40;7777&#41;; 第二个例子,基于socket，两端互相rpc调用 RpcServer.js var Net = [...]]]></description>
			<content:encoded><![CDATA[<p>JsonStream.js是一个用于node.js的双向通信协议实现，它使用json作为数据包格式，可以用于socket，也可以用于http长连接,同时自带了简单的rpc实现。这段代码现在被用于一个对实时性要求比较高的小项目，本来打算用python+twisted做，但是后来临时决定尝试一下node.js，下面举例说明用法:</p>
<p>第一个例子，最简单的应用，基于socket通信,发送和接受json数据<br />
StreamServer.js</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Net <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'net'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> JsonStream <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./JsonStream.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//创建一个普通的socket server</span>
<span style="color: #003366; font-weight: bold;">var</span> server <span style="color: #339933;">=</span> Net.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//当有客户端连接后,socket连接之上创建一个JsonStream</span>
    <span style="color: #003366; font-weight: bold;">var</span> stream <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> JsonStream.<span style="color: #660066;">Stream</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//监听客户端发来的json数据</span>
    stream.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'receiv json from client:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//没三秒钟向客户端发送一个json数据</span>
    setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        stream.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            data<span style="color: #339933;">:</span><span style="color: #3366CC;">'hello client'</span><span style="color: #339933;">,</span>
            time<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
server.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">7777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>第二个例子,基于socket，两端互相rpc调用<br />
RpcServer.js</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Net <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'net'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> JsonStream <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./JsonStream.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//定义服务端支持的Rpc接口</span>
<span style="color: #003366; font-weight: bold;">var</span> ServerApi <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//这是一个普通的接口,直接返回数据</span>
    hello<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'client call hello'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'hello '</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//这是一个异步返回的方法</span>
    <span style="color: #006600; font-style: italic;">//这里的SimpleDeferred的确不是一个全功能的Deffered</span>
    <span style="color: #006600; font-style: italic;">//只能用在异步返回的情况</span>
&nbsp;
    helloAfter<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> delay<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'client call helloAfter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> defer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> JsonStream.<span style="color: #660066;">SimpleDeferred</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            defer.<span style="color: #660066;">done</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hello '</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' after '</span> <span style="color: #339933;">+</span> delay <span style="color: #339933;">+</span> <span style="color: #3366CC;">'s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> delay <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> defer<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> server <span style="color: #339933;">=</span> Net.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> stream <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> JsonStream.<span style="color: #660066;">Stream</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    stream.<span style="color: #660066;">delegate</span> <span style="color: #339933;">=</span> ServerApi<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//每3秒调用一次客户端的say方法</span>
    setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        stream.<span style="color: #660066;">rpcCall</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'say'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'你好!'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
server.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">7777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>RpcClient.js中的调用部分</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;">stream.<span style="color: #660066;">rpcCall</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hello'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'client a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
stream.<span style="color: #660066;">rpcCall</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'helloAfter'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'client a'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>第三个例子，用于长连接的http双向通信,由于客户端的代码和现有的业务框架结合比较紧密，暂不提供，只示意一下Server端的代码,基本使用方法和socket的类似</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Http <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> JsonStream <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'./JsonStream.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Rpc接口定义</span>
<span style="color: #003366; font-weight: bold;">var</span> ServerApi <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//创建一个http server</span>
<span style="color: #003366; font-weight: bold;">var</span> HttpServer <span style="color: #339933;">=</span> Http.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//让JsonStream处理所有http请求</span>
    JsonStream.<span style="color: #660066;">HttpStream</span>.<span style="color: #660066;">acceptRequest</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
JsonStream.<span style="color: #660066;">HttpStream</span>.<span style="color: #660066;">events</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'new'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>stream<span style="color: #339933;">,</span> request<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'new http stream !!!!!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    stream.<span style="color: #660066;">delegate</span> <span style="color: #339933;">=</span> ServerApi<span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//发送json到浏览器端</span>
    stream.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        data<span style="color: #339933;">:</span><span style="color: #3366CC;">'hello browser'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
HttpServer.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//长连接的最大时长设为30秒</span>
JsonStream.<span style="color: #660066;">HttpStream</span>.<span style="color: #660066;">checkTimeOut</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>更多细节详见源码:),经过一段时间的运行，代码已趋于稳定，可以通过svn获取代码和示例,请容忍我的不爱写注释，呵呵～:</p>
<pre>

http://code-of-emptyhua.googlecode.com/svn/trunk/nodejs/jsonstream
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/03/21/1808.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>定制一个Debian Live启动盘</title>
		<link>http://bluehua.org/2012/03/21/1761.html</link>
		<comments>http://bluehua.org/2012/03/21/1761.html#comments</comments>
		<pubDate>Wed, 21 Mar 2012 08:32:08 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[live]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1761</guid>
		<description><![CDATA[这blog都快荒了～～,前些日子自己做了一个debian live的启动盘，把制作过程分享一下。文章适合喜欢linux并有使用经验的用户。 我做的debian live镜像有136M,包含一个firefox浏览器，一些网卡驱动和一个xterm.它的目标很明确，就是给使用者一个可以上网的环境。 窗口管理器采用了openbox，最开始用gnome,生成的镜像已经500多M了。。自带了一堆小软件，精简起来是个麻烦事。下面的任务栏使用tint2,输入法使用scim,网络管理使用wicd.关于这些软件的配置后面会介绍。 下面开始介绍制作和精简过程： 首先要有一个debian环境，俺用的是虚拟机里装的Debian6.02.有个真机版，但是已经被霸占。 第一步: 安装live制作工具live-build，实际使用的版本是2.0.12-1: sudo apt-get install live-build 第二步：创建工作目录，生成初始配置文件 mkdir ~/live cd ~/live lb config 这时会生成一些默认配置，很多，但是用到的就几个 . ├── auto │   ├── functions │   └── scripts └── config ├── binary ├── binary_debian-installer ├── binary_debian-installer-includes ├── binary_grub ├── binary_local-debs ├── binary_local-hooks ├── binary_local-includes ├── binary_local-packageslists ├── binary_local-udebs ├── binary_rootfs ├── binary_syslinux ├── [...]]]></description>
			<content:encoded><![CDATA[<p>这blog都快荒了～～,前些日子自己做了一个debian live的启动盘，把制作过程分享一下。文章适合喜欢linux并有使用经验的用户。</p>
<p>我做的debian live镜像有136M,包含一个firefox浏览器，一些网卡驱动和一个xterm.它的目标很明确，就是给使用者一个可以上网的环境。</p>
<p><a href="http://bluehua.org/wp-content/uploads/2012/03/debian-live.png"><img src="http://bluehua.org/wp-content/uploads/2012/03/debian-live.png" alt="" title="debian-live" width="548" height="454" class="alignnone size-full wp-image-1790" /></a></p>
<p>窗口管理器采用了openbox，最开始用gnome,生成的镜像已经500多M了。。自带了一堆小软件，精简起来是个麻烦事。下面的任务栏使用tint2,输入法使用scim,网络管理使用wicd.关于这些软件的配置后面会介绍。</p>
<p>下面开始介绍制作和精简过程：</p>
<p>首先要有一个debian环境，俺用的是虚拟机里装的Debian6.02.有个真机版，但是已经被霸占。</p>
<p>第一步: 安装live制作工具live-build，实际使用的版本是2.0.12-1:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> live-build</pre></div></div>

<p>第二步：创建工作目录，生成初始配置文件</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>live
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>live
lb config</pre></div></div>

<p>这时会生成一些默认配置，很多，但是用到的就几个</p>
<pre>
.
├── auto
│   ├── functions
│   └── scripts
└── config
    ├── binary
    ├── binary_debian-installer
    ├── binary_debian-installer-includes
    ├── binary_grub
    ├── binary_local-debs
    ├── binary_local-hooks
    ├── binary_local-includes
    ├── binary_local-packageslists
    ├── binary_local-udebs
    ├── binary_rootfs
    ├── binary_syslinux
    ├── bootstrap
    ├── chroot
    ├── chroot_apt
    ├── chroot_local-hooks
    ├── chroot_local-includes
    ├── chroot_local-packages
    ├── chroot_local-packageslists
    ├── chroot_local-patches
    ├── chroot_local-preseed
    ├── chroot_sources
    ├── common
    ├── includes
    ├── source
    └── templates
</pre>
<p>第三步:修改默认配置文件<br />
修改config/common,</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LB_APT_RECOMMENDS</span>=<span style="color: #ff0000;">&quot;false&quot;</span>
<span style="color: #666666; font-style: italic;">#禁用apt-get的推荐功能</span>
<span style="color: #666666; font-style: italic;">#使用apt-get安装软件时会附带一些它觉的有必要一块装的东西，这无疑会安装一些不必要的软件增大生成live的尺寸</span>
<span style="color: #007800;">LB_CACHE_INDICES</span>=<span style="color: #ff0000;">&quot;true&quot;</span>
<span style="color: #666666; font-style: italic;">#是否缓存apt的软件索引，默认是false,如果网络比较好，建议不要缓存，但是我的网络比较差，不想每次都下载软件包索引</span></pre></div></div>

<p>修改config/bootstrap,live-build在bootstrap阶段会构建一个最基本的debian系统，将会读取该配置文件</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LB_ARCHITECTURE</span>=<span style="color: #ff0000;">&quot;amd64&quot;</span> 
<span style="color: #666666; font-style: italic;">#amd64-&gt;64位版本</span>
<span style="color: #666666; font-style: italic;">#i386 -&gt; 32版本</span>
<span style="color: #666666; font-style: italic;">#这里选64位，现在内存普遍超越4G了</span>
<span style="color: #007800;">LB_DISTRIBUTION</span>=<span style="color: #ff0000;">&quot;squeeze&quot;</span>
<span style="color: #666666; font-style: italic;">#指定debian的发行版本，这里使用最新的稳定版本squeeze</span>
<span style="color: #007800;">LB_ARCHIVE_AREAS</span>=<span style="color: #ff0000;">&quot;main contrib non-free&quot;</span>
<span style="color: #666666; font-style: italic;">#由于要安装一些nonfree的软件，要修改一下apt的“尺度”,默认是 main</span>
<span style="color: #666666; font-style: italic;">#其他还有软件源的配置，我这里用cdn.debian.net反而比163的快</span></pre></div></div>

<p>修改config/chroot, live-build将会在构建live的文件系统时使用该配置</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LB_HOOKS</span>=<span style="color: #ff0000;">&quot;minimal&quot;</span>
<span style="color: #666666; font-style: italic;">#制定一个钩子脚本，lb将在构建完根目录后调用，默认为空</span>
<span style="color: #666666; font-style: italic;">#minimal将会调用/usr/share/live/build/hooks/minimal这个清理脚本</span>
<span style="color: #666666; font-style: italic;">#minimal将会清理apt缓存，删除/var/log下的一些无用文件，但是清理力度</span>
<span style="color: #666666; font-style: italic;">#依然不够，后面我们会添加自己的清理脚本</span>
<span style="color: #007800;">LB_PACKAGES_LISTS</span>=<span style="color: #ff0000;">&quot;bluehua&quot;</span>
<span style="color: #666666; font-style: italic;">#指定我们要安装的软件列表 </span>
<span style="color: #666666; font-style: italic;">#bluehua代表了config/chroot_local-packageslists/bluehua.list这个文件</span></pre></div></div>

<p>然后继续修改config/binary,来定制我们要生成的介质类型</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LB_BINARY_IMAGES</span>=<span style="color: #ff0000;">&quot;iso-hybrid&quot;</span>
<span style="color: #666666; font-style: italic;">#usb-hdd生成可以写入usb的镜像</span>
<span style="color: #666666; font-style: italic;">#iso-hybrid生成可以写入光盘的镜像</span>
<span style="color: #007800;">LB_BOOTAPPEND_LIVE</span>=<span style="color: #ff0000;">&quot;locales=zh_CN.UTF-8&quot;</span>
<span style="color: #666666; font-style: italic;">#定制linux启动参数，这里我们指定一下系统的语言</span>
<span style="color: #007800;">LB_MEMTEST</span>=<span style="color: #ff0000;">&quot;none&quot;</span>
<span style="color: #666666; font-style: italic;">#为了减小尺寸，不要包含memtest</span></pre></div></div>

<p>第四步:定制自己的软件列表<br />
直接给出我的软件列表<br />
config/chroot_local-packageslists/bluehua.list</p>
<pre>
xinit
xserver-xorg
x11-xserver-utils
#基本的X系统

user-setup
#可以在系统启动时自动创建一个用户

locales
#本地化信息

xfonts-wqy
#文泉驿的中文字体

openbox
#openbox窗口管理器

tint2
#任务栏

feh
#feh用来设置桌面壁纸

iceweasel
iceweasel-l10n-zh-cn
#firefox和中文语言包

flashplugin-nonfree
#浏览器的flash插件

wicd-gtk
#网络管理软件

xterm
#简单的终端软件

sudo
#没有sudo的系统怎么可以呢

scim
scim-pinyin
scim-gtk2-immodule
#scim中文输入法

hicolor-icon-theme
#一些常用的图标

alsa-base
alsa-utils
#让系统可以发出声音

firmware-bnx2
firmware-bnx2x
firmware-brcm80211
firmware-iwlwifi
firmware-linux
firmware-linux-free
firmware-linux-nonfree
firmware-ralink
firmware-realtek
#尽可能多的网卡驱动
</pre>
<p>到这里lb build运行一下，已经可以出来一个live的镜像文件，但是结果并不如您所愿，启动起来只是一个丑陋的默认X桌面。<br />
我们要继续对安装的软件进行配置,下面给出部分配置。</p>
<p>首先我们要让openbox代替那个丑陋的默认X桌面</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> config<span style="color: #000000; font-weight: bold;">/</span>chroot_local-includes<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>skel
<span style="color: #666666; font-style: italic;">#通过chroot_local-includes这个目录你可以向生成的live系统的文件系统里追加覆盖文件</span>
<span style="color: #666666; font-style: italic;">#比如新建一个config/chroot_local-includes/test.txt</span>
<span style="color: #666666; font-style: italic;">#那么当启动生成的live系统后，你会在根目录/找到test.txt这个文件</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#/etc/skel这个目录里保存了新建用户目录的默认内容</span>
<span style="color: #666666; font-style: italic;">#比如 sudo echo &quot;set nu&quot; &gt; /etc/skel/.vimrc</span>
<span style="color: #666666; font-style: italic;">#然后通过useradd -m testuser 增加一个新用户</span>
<span style="color: #666666; font-style: italic;">#然后你会找到/home/testuser/.vimrc这个文件</span></pre></div></div>

<p>新建 config/chroot_local-includes/etc/skel/.xinitrc<br />
内容如下</p>
<pre>
exec openbox-session
</pre>
<p>OK,这样openbox就可以启动起来了(至于为什么，请google搜索x系统的启动过程)，然后我们继续配置openbox<br />
新建 config/chroot_local-includes/etc/skel/.config/openbox/autostart.sh 内容如下:</p>
<pre>
#!/bin/sh
export XMODIFIERS="@im=SCIM"
export XIM="SCIM"
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"
scim -d &#038;
#启动输入法
tint2 &#038;
#启动任务栏
(sleep 2 &#038;&#038; iceweasel) &#038;
#启动浏览器
(sleep 2 &#038;&#038; wicd-gtk) &#038;
#启动网络管理器
feh --bg-scale /usr/share/wallpagers/debian.png
#设置一张壁纸
#已经事先放到config/chroot_local-includes/usr/share/wallpagers/debian.png 了
</pre>
<p>之后不要忘了加执行权限</p>
<p>费了这么大功夫，终于算差不多了，运行一下lb build，喝杯茶的功夫再回来，应该看到有生成的binary-hybrid.so,但是大小应该接近200M的样子.下面将介绍我们的清理脚本,清理脚本应该放到config/chroot_local-hooks。这个目录下的脚本，将在live系统的文件系统构建完成之后执行。<br />
cat config/chroot_local-hooks/03-remove-docs.sh 内容如下</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;remove unused packages&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> libg11-mesa-dri
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> <span style="color: #c20cb9; font-weight: bold;">nano</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> manpages
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> openbox-themes 
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> remove <span style="color: #660033;">-y</span> <span style="color: #660033;">--purge</span> iptables 
&nbsp;
<span style="color: #666666; font-style: italic;">#上面将删除一些用不到的软件，man手册比较大</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> autoremove
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> clean 
&nbsp;
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>flash<span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #666666; font-style: italic;">#删除flash插件安装过程中下载的临时文件</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;remvoe all docs&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc-base<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #666666; font-style: italic;">#删除所有文档</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;remove all man docs&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>man<span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #666666; font-style: italic;">#删除自带的一些man文档</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;remove apt lists&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/*</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;remove apt cache&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/*</span>.bin
<span style="color: #666666; font-style: italic;">#删除apt缓存</span>
&nbsp;
locale-gen
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>locale;<span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> -<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> zh_CN<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> locale<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #ff0000;">&quot;{}&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#删除除了zh_CN之外的所有本地化信息</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#remove some driver</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/*/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>drivers<span style="color: #000000; font-weight: bold;">/</span>isdn
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/*/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>drivers<span style="color: #000000; font-weight: bold;">/</span>media
<span style="color: #666666; font-style: italic;">#删除不常用的驱动</span></pre></div></div>

<p>同样不要忘了加执行权限，有了这个神奇的脚本，live的尺寸就可以降到136M～</p>
<p>总结如下:</p>
<p>1 简单的三个命令 lb config 生成默认配置,lb build 构建live系统，lb clean 清理。<br />
2 需要安装的软件列表放到config/chroot_local-packageslists/xxxx.list,并在config/chroot里通LB_PACKAGES_LISTS指定<br />
3 需要覆盖到生成系统中的文件放到config/chroot_local-includes<br />
4 用户home目录的默认配置文件放到config/chroot_local-includes/etc/skel<br />
5 需要在系统构建完成之后执行的动作放到config/chroot_local-hooks</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2012/03/21/1761.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LUPlayer &#8211; mac os下的网络视频播放器</title>
		<link>http://bluehua.org/2011/11/14/1742.html</link>
		<comments>http://bluehua.org/2011/11/14/1742.html#comments</comments>
		<pubDate>Mon, 14 Nov 2011 11:23:53 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[IOS]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[LUPlayer]]></category>
		<category><![CDATA[mac os]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1742</guid>
		<description><![CDATA[周末的时候想写点代码把一个没有完成的想法继续下去，但又不想太无聊，想在youku上找个片看着。这时碰到了个小问题，视频不能弹出，或者即用浏览器插件弹出，应该也不能置顶。于是先解决了一下这个小问题，然后有了这个播放器。播放器使用起来很简单，只要把视频的地址贴到地址栏，然后点播放即可，现在只支持有ipad支持的视频网站（youku，qiyi，sohu，５６都可以)。当然，这还是个非常简陋的播放器，如果不考虑放出来的话，进度条都懒的加了。 有以下优点: 窗口置顶 不用flash，省cpu 没广告 截屏: 下载:LUPlayer_1_0.dmg]]></description>
			<content:encoded><![CDATA[<p>周末的时候想写点代码把一个没有完成的想法继续下去，但又不想太无聊，想在youku上找个片看着。这时碰到了个小问题，视频不能弹出，或者即用浏览器插件弹出，应该也不能置顶。于是先解决了一下这个小问题，然后有了这个播放器。播放器使用起来很简单，只要把视频的地址贴到地址栏，然后点播放即可，现在只支持有ipad支持的视频网站（youku，qiyi，sohu，５６都可以)。当然，这还是个非常简陋的播放器，如果不考虑放出来的话，进度条都懒的加了。</p>
<p>有以下优点:</p>
<ul>
<li>窗口置顶</li>
<li>不用flash，省cpu</li>
<li>没广告</li>
</ul>
<p>截屏:<br />
<a href="http://bluehua.org/wp-content/uploads/2011/11/LUPlayer.jpg"><img src="http://bluehua.org/wp-content/uploads/2011/11/LUPlayer.jpg" alt="" title="LUPlayer" width="428" height="272" class="alignnone size-full wp-image-1743" /></a><br />
<a href="http://bluehua.org/wp-content/uploads/2011/11/LUPlayer2.jpg"><img src="http://bluehua.org/wp-content/uploads/2011/11/LUPlayer2.jpg" alt="" title="LUPlayer2" width="607" height="351" class="alignnone size-full wp-image-1744" /></a></p>
<p>下载:<a href='http://bluehua.org/wp-content/uploads/2011/11/LUPlayer_1_0.dmg_.zip'>LUPlayer_1_0.dmg</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2011/11/14/1742.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>postfix出错一则</title>
		<link>http://bluehua.org/2011/11/05/1734.html</link>
		<comments>http://bluehua.org/2011/11/05/1734.html#comments</comments>
		<pubDate>Sat, 05 Nov 2011 09:12:42 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1734</guid>
		<description><![CDATA[能收到邮件但是发不出去 错误日志如下 Nov 4 20:32:21 localhost postfix/cleanup[4853]: warning: 51CCA2E129: virtual_alias_maps map lookup probl em for xxxx@gmail.com Nov 4 20:33:21 localhost postfix/pickup[4851]: 587A12F5F5: uid=0 from= Nov 4 20:33:21 localhost postfix/cleanup[4853]: warning: connect to mysql server localhost: Can't connec t to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 原因是之前配置了基于mysql的地址映射 virtual_alias_maps = mysql:/etc/postfix/mysql-alias.cf 当一些在chroot环境中运行的postfix组建试图通过/var/run/mysqld/mysqld.sock连接数据库时就报错了，在master.cf里禁用smtp,rewrite,cleanup的chroot即可 smtp inet n - [...]]]></description>
			<content:encoded><![CDATA[<p>能收到邮件但是发不出去</p>
<p>错误日志如下</p>
<pre>
Nov  4 20:32:21 localhost postfix/cleanup[4853]: warning: 51CCA2E129: virtual_alias_maps map lookup probl         em for xxxx@gmail.com
Nov  4 20:33:21 localhost postfix/pickup[4851]: 587A12F5F5: uid=0 from=<root>
Nov  4 20:33:21 localhost postfix/cleanup[4853]: warning: connect to mysql server localhost: Can't connec         t to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
</pre>
<p>原因是之前配置了基于mysql的地址映射</p>
<pre>
virtual_alias_maps = mysql:/etc/postfix/mysql-alias.cf
</pre>
<p>当一些在chroot环境中运行的postfix组建试图通过/var/run/mysqld/mysqld.sock连接数据库时就报错了，在master.cf里禁用smtp,rewrite,cleanup的chroot即可</p>
<pre>
smtp      inet  n       -       n       -       -       smtpd
rewrite   unix  -       -       n       -       -       trivial-rewrite
cleanup   unix  n       -       n       -       0       cleanup
</pre>
<p>#这是一种不安全的fix方法，另一种解决方法是修改my.conf同过3306端口访问mysql，也可以解决问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2011/11/05/1734.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>打理一下IOS项目中的图片资源</title>
		<link>http://bluehua.org/2011/10/24/1722.html</link>
		<comments>http://bluehua.org/2011/10/24/1722.html#comments</comments>
		<pubDate>Mon, 24 Oct 2011 04:56:59 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[IOS]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1722</guid>
		<description><![CDATA[项目经历过大的变动之后会留下一些不再需要的图片文件，写了一个脚本跑了一下，找到150张未用到的图片，给力~ 下面的脚本使用的时候需要根据自己的项目指定图片目录和代码目录 找出不再需要的图片 #如果没有找包含@&#34;imageName&#34;或@&#34;imageName.png&#34;的.h.m文件,则认为项目里不再需要这个图片 find ./Resources -name &#34;*.png&#34; \ &#124;grep -v @ \ &#124;while read line;do iname=$&#40;basename &#34;$line&#34;&#124;sed -e &#34;s/\.png//&#34;&#41;; &#91; -z &#34;`find ./ \( -name &#34;*.m&#34; -or -name &#34;*.h&#34; \)&#124;xargs grep -E &#34;@\\\&#34;${iname}(\\\.png)?\\\&#34;&#34;`&#34; &#93; &#38;&#38; echo $line &#38;&#38; img2x=&#34;`echo &#34;$line&#34;&#124;sed -e &#34;s/\.png/@2x\.png/&#34;`&#34; &#38;&#38; &#91; -e &#34;$img2x&#34; &#93; &#38;&#38; echo $img2x; done 还有一个用来找出只有单倍或双倍的图片 find ./Resources [...]]]></description>
			<content:encoded><![CDATA[<p>项目经历过大的变动之后会留下一些不再需要的图片文件，写了一个脚本跑了一下，找到150张未用到的图片，给力~</p>
<p>下面的脚本使用的时候需要根据自己的项目指定图片目录和代码目录</p>
<p>找出不再需要的图片</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#如果没有找包含@&quot;imageName&quot;或@&quot;imageName.png&quot;的.h.m文件,则认为项目里不再需要这个图片</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span>Resources <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.png&quot;</span> \
    <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #000000; font-weight: bold;">@</span> \
    <span style="color: #000000; font-weight: bold;">|</span><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line;<span style="color: #000000; font-weight: bold;">do</span> 
    <span style="color: #007800;">iname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span>&quot;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/\.png//&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`find ./ \( -name &quot;*.m&quot; -or -name &quot;*.h&quot; \)|xargs grep -E &quot;@\\\&quot;${iname}(\\\.png)?\\\&quot;&quot;`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">img2x</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`echo &quot;$line&quot;|sed -e &quot;s/\.png/@2x\.png/&quot;`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$img2x</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$img2x</span>;
    <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>还有一个用来找出只有单倍或双倍的图片</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span>Resources <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.png&quot;</span> \
    <span style="color: #000000; font-weight: bold;">|</span><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line;<span style="color: #000000; font-weight: bold;">do</span> 
    <span style="color: #007800;">iname</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span>&quot;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/\.png//&quot;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/@2x//&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    <span style="color: #007800;">dname</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(dirname &quot;$line&quot;)</span>/&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${dname}</span><span style="color: #007800;">${iname}</span>.png&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span> 缺少单倍图片&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${dname}</span><span style="color: #007800;">${iname}</span>@2x.png&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span> 缺少2倍图片&quot;</span>
    <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>直接下载脚本:<a href='http://bluehua.org/wp-content/uploads/2011/10/XcodeImageManageTool.zip'>XcodeImageManageTool.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2011/10/24/1722.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.993 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-18 15:30:39 -->

