<?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>Sat, 06 Mar 2010 15:40:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>给图片定宽高减少reflow的一个想法</title>
		<link>http://bluehua.org/2010/03/02/992.html</link>
		<comments>http://bluehua.org/2010/03/02/992.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 15:17:01 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[reflow]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=992</guid>
		<description><![CDATA[近期的前端优化主要集中在提高渲染速度,回家在公车上想的一个方案:
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
页面渲染慢最重要的一个原因就是reflow, 而造成reflow的主要有两大块: 图片和javascript的dom操作,这里主要说图片.未指明宽高的图片,在页面dom渲染完毕时没有加载媒体时宽高是0&#215;0,当一张图片加载完毕,就不得不重新渲染图片宽高变化所影响的区域.
解决这个问题的最佳效果就是给每张图片定宽定高:

&#60;img width=&#34;300&#34; height=&#34;200&#34; src=&#34;abc.gif&#34; /&#62;

问题: 做页面的同学可以给自己切的图定宽高,但是用户上传的图片呢? 新鲜事里充斥了大量用户上传的图片~
参考解决方案:
这个方案的缺点就是需要一个良好的图片存储初期设计&#8230;
比如这是一个普通的图片上传后的地址

fmn041/20100302/2155/p_main_y8Hj_3b9e0000134b2d10.jpg

而这个方案需要在图片上传时就将宽度信息写到图片名称里,让使用它的cgi, httpd, javascript都能看名字就能知道它的三围

fmn041/20100302/2155/p_main_y8Hj_3b9e0000134b2d10_300_500.jpg

然后使用时就很灵活了

//对于新鲜事,使用自己的处理函数
&#60;img width=&#34;&#60;?php echo get_img_width&#40;$url&#41; ?&#62; height=&#34;&#60;?php echo get_img_height&#40;$url&#41; ?&#62;&#34; src=&#34;&#60;?php echo $url?&#62;&#34; /&#62;

而对于日志,帖子内容里的图片则需要输出过滤,给图片加宽高,或者是在发表阶段就通过js定宽高

//smarty里的输出过滤器
$smarty-&#62;load_filter&#40;'output', 'image_url_filter'&#41;;

cgi层过滤的话就不能及时flush输出,所以可以放到apache做http://httpd.apache.org/docs/2.2/filter.html
已有巨大量数据转换图片命名方案也是一件棘手的事&#8230;.
]]></description>
			<content:encoded><![CDATA[<p>近期的前端优化主要集中在提高渲染速度,回家在公车上想的一个方案:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
页面渲染慢最重要的一个原因就是reflow, 而造成reflow的主要有两大块: 图片和javascript的dom操作,这里主要说图片.未指明宽高的图片,在页面dom渲染完毕时没有加载媒体时宽高是0&#215;0,当一张图片加载完毕,就不得不重新渲染图片宽高变化所影响的区域.</p>
<p>解决这个问题的最佳效果就是给每张图片定宽定高:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;300&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;200&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;abc.gif&quot;</span> <span style="color: #339933;">/&gt;</span></pre></div></div>

<p>问题: 做页面的同学可以给自己切的图定宽高,但是用户上传的图片呢? 新鲜事里充斥了大量用户上传的图片~</p>
<p>参考解决方案:<br />
这个方案的缺点就是需要一个良好的图片存储初期设计&#8230;<br />
比如这是一个普通的图片上传后的地址</p>
<pre>
fmn041/20100302/2155/p_main_y8Hj_3b9e0000134b2d10.jpg
</pre>
<p>而这个方案需要在图片上传时就将宽度信息写到图片名称里,让使用它的cgi, httpd, javascript都能看名字就能知道它的三围</p>
<pre>
fmn041/20100302/2155/p_main_y8Hj_3b9e0000134b2d10_300_500.jpg
</pre>
<p>然后使用时就很灵活了</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;">//对于新鲜事,使用自己的处理函数
&lt;img width=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_img_width<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> height=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_img_height<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$url</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;</pre></div></div>

<p>而对于日志,帖子内容里的图片则需要输出过滤,给图片加宽高,或者是在发表阶段就通过js定宽高</p>

<div class="wp_syntax"><div class="code overflow"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//smarty里的输出过滤器</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load_filter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'output'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image_url_filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>cgi层过滤的话就不能及时flush输出,所以可以放到apache做<a href="http://httpd.apache.org/docs/2.2/filter.html">http://httpd.apache.org/docs/2.2/filter.html</a></p>
<p>已有巨大量数据转换图片命名方案也是一件棘手的事&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/03/02/992.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>一种字符串代替数组的场合</title>
		<link>http://bluehua.org/2010/02/25/982.html</link>
		<comments>http://bluehua.org/2010/02/25/982.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 09:22:57 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=982</guid>
		<description><![CDATA[曾经耍过一些小聪明,而且是相当然的,有人问我你做过验证吗,&#8230;.木有,然后也觉得自己很不靠普
下面是验证以前做一个选择器的时候用到的方法,主要是为了加速判断是否已选的操作

&#60;html&#62;
&#60;script&#62;
function ctime&#40;func&#41;
&#123;
    var s = new Date&#40;&#41;.getTime&#40;&#41;;
    func&#40;&#41;;
    return new Date&#40;&#41;.getTime&#40;&#41; - s;
&#125;
var time;
time = ctime&#40;function&#40;&#41;
&#123;
    var i = 0;
    astr = &#91;&#93;;
    while &#40;i &#60; 10000&#41;
    &#123;
       [...]]]></description>
			<content:encoded><![CDATA[<p>曾经耍过一些小聪明,而且是相当然的,有人问我你做过验证吗,&#8230;.木有,然后也觉得自己很不靠普</p>
<p>下面是验证以前做一个选择器的时候用到的方法,主要是为了加速判断是否已选的操作</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> ctime<span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> s <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: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    func<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</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: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> s<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> time<span style="color: #339933;">;</span>
time <span style="color: #339933;">=</span> ctime<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>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    astr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10000</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        astr.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fasdfasdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         
        i <span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>time <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
time <span style="color: #339933;">=</span> ctime<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>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    sstr <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10000</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        sstr <span style="color: #339933;">=</span> sstr <span style="color: #339933;">+</span> <span style="color: #3366CC;">'fasdfasdf'</span><span style="color: #339933;">;</span>         
        i <span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>time <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> is_include<span style="color: #009900;">&#40;</span>arr<span style="color: #339933;">,</span> v<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> j <span style="color: #339933;">=</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> j<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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> v<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
time <span style="color: #339933;">=</span> ctime<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>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">1000</span><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>is_include<span style="color: #009900;">&#40;</span>astr<span style="color: #339933;">,</span> <span style="color: #3366CC;">'12321423'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>         
        i <span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>time <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
time <span style="color: #339933;">=</span> ctime<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>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">1000</span><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>sstr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'12321423'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>         
        i <span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>time <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>运行结果<br />
ie6:</p>
<pre>
20
1342
5699
280
</pre>
<p>ie8:</p>
<pre>
30
30
9163
441
</pre>
<p>ff3.6:</p>
<pre>
1
2
111
97
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/02/25/982.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ie下暴力debug js</title>
		<link>http://bluehua.org/2010/02/25/976.html</link>
		<comments>http://bluehua.org/2010/02/25/976.html#comments</comments>
		<pubDate>Thu, 25 Feb 2010 09:03:43 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=976</guid>
		<description><![CDATA[ie下的脚本错误总是很神秘的样子,告诉你哪个行,确不告诉你哪个文件,Visual Studio带了一个调试工具倒是可以,long long ago之前用过一次,老崩溃的样子~
如果你又遇到了猜不透的bug,可以尝试下面的shell~

//现去firefox里收集一份js列表
var alljs = &#91;&#93;;
XN.array.each&#40;document.getElementsByTagName&#40;'script'&#41;,function&#40;i,v&#41;
&#123;
    if &#40;v.src&#41;
    &#123;
        alljs.push&#40;v.src&#41;;
    &#125;
&#125;&#41;;
console.log&#40;alljs.join&#40;'\n'&#41;&#41;;

把列表保存到一个文件,下面跑段shell,把所有js的报错位置的代码打印出来

// 10 100是ie里提示的错误位置
sh ~/bin/get_line.sh /tmp/jslist 10 100

附:

#!/bin/sh
LIST=&#34;$1&#34;
ROW=&#34;$2&#34;
COL=&#34;$3&#34;
&#160;
if &#91; ! -n &#34;$ROW&#34; &#93;;then
    exit
fi
&#160;
echo &#34;行:${ROW}&#34;
echo &#34;列:${COL}&#34;
&#160;
get_row&#40;&#41;
&#123;
    cat /tmp/js_debug_tmp &#124; sed -n &#34;${ROW}p&#34;
&#125;
&#160;
cat &#34;$LIST&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>ie下的脚本错误总是很神秘的样子,告诉你哪个行,确不告诉你哪个文件,Visual Studio带了一个调试工具倒是可以,long long ago之前用过一次,老崩溃的样子~<br />
如果你又遇到了猜不透的bug,可以尝试下面的shell~</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//现去firefox里收集一份js列表</span>
<span style="color: #003366; font-weight: bold;">var</span> alljs <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
XN.<span style="color: #660066;">array</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>v<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>v.<span style="color: #660066;">src</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        alljs.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>v.<span style="color: #660066;">src</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;">&#41;</span><span style="color: #339933;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>alljs.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>把列表保存到一个文件,下面跑段shell,把所有js的报错位置的代码打印出来</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">//</span> <span style="color: #000000;">10</span> <span style="color: #000000;">100</span>是ie里提示的错误位置
<span style="color: #c20cb9; font-weight: bold;">sh</span> ~<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>get_line.sh <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>jslist <span style="color: #000000;">10</span> <span style="color: #000000;">100</span></pre></div></div>

<p>附:</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>
<span style="color: #007800;">LIST</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
<span style="color: #007800;">ROW</span>=<span style="color: #ff0000;">&quot;$2&quot;</span>
<span style="color: #007800;">COL</span>=<span style="color: #ff0000;">&quot;$3&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ROW</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;行:<span style="color: #007800;">${ROW}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;列:<span style="color: #007800;">${COL}</span>&quot;</span>
&nbsp;
get_row<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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>js_debug_tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ROW}</span>p&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$LIST</span>&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: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-q</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span>&quot;</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>js_debug_tmp 
    <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: #007800;">row</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`get_row`</span>&quot;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${COL}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">row</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`echo \&quot;${row}\&quot; | cut -c ${COL}- `</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$row</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>js_debug_tmp</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/02/25/976.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript做html字符串的截断</title>
		<link>http://bluehua.org/2010/02/01/927.html</link>
		<comments>http://bluehua.org/2010/02/01/927.html#comments</comments>
		<pubDate>Mon, 01 Feb 2010 12:46:46 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=927</guid>
		<description><![CDATA[2010.2.6 日修正
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
2010.2.3 日修正

&#60;html&#62;
&#60;!-- html字符截断第二版 bug修正 + 2.6日修正--&#62;
&#60;script&#62;
function sub_html_str&#40;str, num&#41;
&#123;
    var reg = new RegExp&#40; '&#60;[^&#62;]+&#62;' , 'g' &#41;;
    var rt, rts = &#91;&#93;, indexs = &#91;&#93;, tstr, endstr, rstr, sstr, endtag, rtstr;
&#160;
    //提取所有的html标签和标签在字符串中的位置 
    while &#40; &#40; rt = reg.exec&#40;str&#41; &#41; != null [...]]]></description>
			<content:encoded><![CDATA[<p>2010.2.6 日修正<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
2010.2.3 日修正</p>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span> html字符截断第二版 bug修正 <span style="color: #339933;">+</span> <span style="color: #CC0000;">2.6</span>日修正<span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> sub_html_str<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> reg <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'&lt;[^&gt;]+&gt;'</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'g'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> rt<span style="color: #339933;">,</span> rts <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> indexs <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> tstr<span style="color: #339933;">,</span> endstr<span style="color: #339933;">,</span> rstr<span style="color: #339933;">,</span> sstr<span style="color: #339933;">,</span> endtag<span style="color: #339933;">,</span> rtstr<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//提取所有的html标签和标签在字符串中的位置 </span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> rt <span style="color: #339933;">=</span> reg.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rts.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rt<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        indexs.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rt<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'index'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//删除字符串中所有的html标签</span>
    tstr <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>reg<span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//对剩余的纯字符串进行substr</span>
&nbsp;
    sstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>num<span style="color: #339933;">,</span> tstr.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    tstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #006600; font-style: italic;">//判断有没有把实体腰斩，如果有腰斩的就再接上 </span>
    endstr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&amp;[^&amp;]*$/</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>tstr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> endstr <span style="color: #339933;">!==</span> <span style="color: #3366CC;">''</span> <span style="color: #009900;">&#41;</span> endstr <span style="color: #339933;">+=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^[^;]*;/</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>sstr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^(&amp;\w{1,10};|&amp;#\d+;)$/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>endstr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rtstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&amp;[^&amp;]*$/</span><span style="color: #339933;">,</span> endstr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        rtstr <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//把html标签放回到截断完毕的字符串中，当然有的html标签这时候已经无家可归了</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> rts.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        index <span style="color: #339933;">=</span> indexs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rtstr.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;=</span> index<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            rtstr <span style="color: #339933;">=</span> rtstr.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> index<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> rtstr.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> rtstr.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> lastindex <span style="color: #339933;">=</span> i <span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//下面的代码用来闭合没有闭合的标签</span>
    tstr <span style="color: #339933;">=</span> rtstr<span style="color: #339933;">;</span>
    rstr <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//把闭合的标签全部删除，sstr包含了没有闭合的标签</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> rstr <span style="color: #339933;">!=</span> tstr <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rstr <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
        tstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^\/][^&gt;]*&gt;[^&lt;]*&lt;\/[^&gt;]+&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^&gt;]+ \/&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    sstr <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//在剩余的部分查找没有闭合的标签</span>
    tstr <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>rtstr<span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    rstr <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> rstr <span style="color: #339933;">!=</span> tstr <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rstr <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
        tstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^\/][^&gt;]*&gt;[^&lt;]*&lt;\/[^&gt;]+&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^&gt;]+ \/&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    reg.<span style="color: #660066;">lastIndex</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> endreg <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;<span style="color: #000099; font-weight: bold;">\/</span>[^&gt;]+&gt;'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'g'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//如果存在没有闭合的标签，从无家可归的标签里找下半身</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> reg.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>sstr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <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: #009900;">&#40;</span>rt <span style="color: #339933;">=</span> endreg.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>tstr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
             rtstr <span style="color: #339933;">+=</span> rt<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
             <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> rtstr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;textarea cols=&quot;100&quot; rows=&quot;10&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;嵌套标签截断测试&lt;/oo&gt;&lt;fk&gt;&lt;test&gt;lala&lt;/test&gt;&lt;/fk&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'正常字符串测试'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;带标签的字符串截断&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;嵌套标签截断测试&lt;/oo&gt;&lt;fk&gt;lala&lt;/fk&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;嵌套标签&lt;img src=&quot;http://www.google.com/logo.gif&quot; /&gt;截断测试&lt;/oo&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;实体截断&amp;nbsp;测试测试&lt;/oo&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/textarea&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
最近各位弟兄都很忙的样子，俺则已经沦为做活动页面的了。。html字符的截断一般都会放到后台技术们做，但是春节的这个东西比较紧，偶就前端代劳一下。<br />
运气不错，这么长的函数没调几次就过了。也是按照自己的思路来。。。<br />
这个函数仅能做到</p>
<ul>
<li>截取除了html标签之外的前n个字符，一般的需求都是这样的。。</li>
<li>不会截断html实体</li>
<li>查找并闭合被截断的html标签,但是如果给的html就存在没有闭合的就不管了</li>
</ul>

<div class="wp_syntax"><div class="code overflow"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span> html字符截断第一版 <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> sub_html_str<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> reg <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'&lt;[^&gt;]+&gt;'</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'g'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> rt<span style="color: #339933;">,</span> rts <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> indexs <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> tstr<span style="color: #339933;">,</span> endstr<span style="color: #339933;">,</span> rstr<span style="color: #339933;">,</span> endtag<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//提取所有的html标签和标签在字符串中的位置 </span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> rt <span style="color: #339933;">=</span> reg.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rts.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rt<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        indexs.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rt<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'index'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//删除字符串中所有的html标签</span>
    str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>reg<span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//对剩余的纯字符串进行substr</span>
    tstr <span style="color: #339933;">=</span> str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//判断有没有把实体腰斩，如果有腰斩的就再接上 </span>
    endstr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&amp;[^&amp;]*$/</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>tstr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> endstr <span style="color: #339933;">!==</span> <span style="color: #3366CC;">''</span> <span style="color: #009900;">&#41;</span> endstr <span style="color: #339933;">+=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^[^;]*;/</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>num<span style="color: #339933;">,</span> str.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^(&amp;\w{1,10};|&amp;#\d+;)$/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>endstr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        str <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&amp;[^&amp;]*$/</span><span style="color: #339933;">,</span> endstr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        str <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//把html标签放回到截断完毕的字符串中，当然有的html标签这时候已经无家可归了</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> rts.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        index <span style="color: #339933;">=</span> indexs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;=</span> index<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            str <span style="color: #339933;">=</span> str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> index<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> str.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> lastindex <span style="color: #339933;">=</span> i <span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//下面的代码用来闭合没有闭合的标签</span>
    tstr <span style="color: #339933;">=</span> str<span style="color: #339933;">;</span>
    rstr <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//把闭合的标签全部删除，tstr包含了没有闭合的标签</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> rstr <span style="color: #339933;">!=</span> tstr <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        rstr <span style="color: #339933;">=</span> tstr<span style="color: #339933;">;</span>
        tstr <span style="color: #339933;">=</span> tstr.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^&gt;]+&gt;[^&lt;]*&lt;\/[^&gt;]+&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;[^&gt;]+ \/&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    reg.<span style="color: #660066;">lastIndex</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//如果存在没有闭合的标签，从无家可归的标签里找下半身</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> reg.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>rstr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> lastindex <span style="color: #339933;">&lt;</span> rts.<span style="color: #660066;">length</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            endtag <span style="color: #339933;">=</span> rts<span style="color: #009900;">&#91;</span>lastindex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">//如果它是一个用来闭合的标签,就把它追加到字符串</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^&lt;[ ]*\//</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>endtag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
            <span style="color: #009900;">&#123;</span>
                str <span style="color: #339933;">=</span> str <span style="color: #339933;">+</span> endtag<span style="color: #339933;">;</span>
                lastindex <span style="color: #339933;">++;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #006600; font-style: italic;">//如果它是自闭合的标签</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/&lt;[^&gt;]+ \/&gt;/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>endtag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                lastindex <span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #006600; font-style: italic;">//如果它是一个起始标签</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                lastindex <span style="color: #339933;">+=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;textarea cols=&quot;100&quot; rows=&quot;10&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'正常字符串测试'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;带标签的字符串截断&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;嵌套标签截断测试&lt;/oo&gt;&lt;fk&gt;lala&lt;/fk&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;嵌套标签&lt;img src=&quot;http://www.google.com/logo.gif&quot; /&gt;截断测试&lt;/oo&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span>sub_html_str<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;xx&gt;&lt;oo&gt;实体截断&amp;nbsp;测试测试&lt;/oo&gt;&lt;/xx&gt;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">writeln</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/textarea&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/02/01/927.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>还原用户环境失败&#8230;</title>
		<link>http://bluehua.org/2010/01/29/914.html</link>
		<comments>http://bluehua.org/2010/01/29/914.html#comments</comments>
		<pubDate>Fri, 29 Jan 2010 12:38:53 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[web dev]]></category>
		<category><![CDATA[debug]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=914</guid>
		<description><![CDATA[话说昨天采集了用户的系统和软件信息,今天用虚拟机还原了一个,但是失败了,bug没有重现~
过程还是挺费功夫的:
首先用户用的番茄花园xp sp2, 虚拟机里用迅雷秒杀了,超赞公司网速~
Virtualbox里系统装好,下面就是比较头疼的,按照补丁列表打补丁&#8230;

hualu@lu-hua:patch$ cat /tmp/allsofts.txt &#124; grep -E &#34;\(KB[0-9]{6}&#34; &#124; sed -e 's/.*(\(KB[^)]*\).*/\1/' &#124; wc -l
138

软件列表里一共有138个补丁, 对着列表在360卫士里挨个找着选的话估计我这老眼就废了&#8230;
还是自己写脚本去微软下载

#!/bin/sh
&#160;
ID=&#34;$1&#34;
if &#91; ! -n &#34;$ID&#34; &#93;;then
    exit
fi
echo '-----------------------------------'
BASEURL='http://www.microsoft.com'
&#160;
get_first_link&#40;&#41;
&#123;
   cat &#34;$1&#34; &#124; grep &#34;Windows XP&#34; &#124; grep &#34;&#60;a&#34; &#124; sed -e 's/.*href=&#34;\([^&#34;]*\)&#34;.*/\1/' \
       -e 's/.*;u=//' \
    [...]]]></description>
			<content:encoded><![CDATA[<p>话说昨天采集了用户的系统和软件信息,今天用虚拟机还原了一个,但是失败了,bug没有重现~</p>
<p>过程还是挺费功夫的:<br />
首先用户用的番茄花园xp sp2, 虚拟机里用迅雷秒杀了,超赞公司网速~<br />
Virtualbox里系统装好,下面就是比较头疼的,按照补丁列表打补丁&#8230;</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;">hualu<span style="color: #000000; font-weight: bold;">@</span>lu-hua:<span style="color: #c20cb9; font-weight: bold;">patch</span>$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>allsofts.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;\(KB[0-9]{6}&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;">'s/.*(\(KB[^)]*\).*/\1/'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span>
<span style="color: #000000;">138</span></pre></div></div>

<p>软件列表里一共有138个补丁, 对着列表在360卫士里挨个找着选的话估计我这老眼就废了&#8230;</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;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">ID</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ID</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------'</span>
<span style="color: #007800;">BASEURL</span>=<span style="color: #ff0000;">'http://www.microsoft.com'</span>
&nbsp;
get_first_link<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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;Windows XP&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;&lt;a&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;">'s/.*href=&quot;\([^&quot;]*\)&quot;.*/\1/'</span> \
       <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/.*;u=//'</span> \
       <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/%2f/\//g'</span> \
       <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/%3f/\?/g'</span> \
       <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/%3d/\=/g'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_second_link<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: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'id=&quot;quickCheck&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/.*window\.open('\([^']*\)',.*/\1/&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">url</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASEURL}</span>/downloads/results.aspx?pocId=7&amp;freetext=<span style="color: #007800;">${ID}</span>&amp;DisplayLang=zh-cn&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${url}</span>&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${url}</span>&quot;</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>get_ms_link
&nbsp;
<span style="color: #007800;">surl</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`get_first_link /tmp/get_ms_link`</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${surl}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ID}</span>补丁不存在&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ID}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>patch_not_found.txt
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">surl</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${BASEURL}</span><span style="color: #007800;">${surl}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${surl}</span>&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${surl}</span>&quot;</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>get_ms_link
<span style="color: #007800;">turl</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`get_second_link /tmp/get_ms_link`</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${turl}</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${turl}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ID}</span>补丁不存在&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ID}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>patch_not_found.txt
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${turl}</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'-----------------------------------'</span></pre></div></div>

<p>不知道微软有没有专门的补丁下载入口,不过我还是模仿我知道的方法下载了,先搜索,然后结果里找,使用:sh get_ms_patch.sh KB975467</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;">#取出所有补丁编号</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> allsofts.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;\(KB[0-9]{6}&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;">'s/.*(\(KB[^)]*\).*/\1/'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>allpatch.txt
<span style="color: #666666; font-style: italic;">#下载所有补丁</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>allpatch.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-i</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hualu<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>get_ms_update.sh <span style="color: #ff0000;">&quot;{}&quot;</span>
<span style="color: #666666; font-style: italic;">#生成批量安装补丁的批处理文件</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.exe&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-i</span> <span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-i</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.\{} /passive /norestart&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> install.bat</pre></div></div>

<p>回到虚拟xp里,挂在网络驱动,双击install.bat,开始安装&#8230; 等我吃完午饭,补丁都装完了,灰常激动,立刻重启,打开ie,登录淫淫,进入个人主页, fuck, 没有脚本错误!!!!</p>
<p>估计今天我嘴上的泡就是因为这个起的,真上火&#8230; , 后面,我接着按照软件列表装了瑞星,offcie 2007,均没有看到我期待的脚本错误<img class="xemotion" src="http://bluehua.org/wp-content/plugins/x-emotions/emotions/msn/bofu3_14.gif" border="0" alt="" /></p>
<p>看来我得研究星座了&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/29/914.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>收集windows xp的系统信息</title>
		<link>http://bluehua.org/2010/01/28/904.html</link>
		<comments>http://bluehua.org/2010/01/28/904.html#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:19:54 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[soft]]></category>
		<category><![CDATA[Installed Programs]]></category>
		<category><![CDATA[systeminfo]]></category>
		<category><![CDATA[window xp]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=904</guid>
		<description><![CDATA[最近又遇到了一个不是所有的IE6浏览器都会有的bug,于是今天去一个用户家里上门debug,这已经是第二次了,学乖了一点,提前查了以下收集系统信息的方法
1 . 主要信息
一个cmd命令就可以了

systeminfo &#62; system.txt

2 . 安装的所有软件和补丁列表
搜到一个老外写的vbscript脚本 : InstalledPrograms
恩,有了这两个列表,就可以用来重现一个用户类似的环境~
]]></description>
			<content:encoded><![CDATA[<p>最近又遇到了一个不是所有的IE6浏览器都会有的bug,于是今天去一个用户家里上门debug,这已经是第二次了,学乖了一点,提前查了以下收集系统信息的方法</p>
<p>1 . 主要信息</p>
<p>一个cmd命令就可以了</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;">systeminfo <span style="color: #000000; font-weight: bold;">&gt;</span> system.txt</pre></div></div>

<p>2 . 安装的所有软件和补丁列表</p>
<p>搜到一个老外写的vbscript脚本 : <a href='http://bluehua.org/wp-content/uploads/2010/01/InstalledPrograms.zip'>InstalledPrograms</a></p>
<p>恩,有了这两个列表,就可以用来重现一个用户类似的环境~</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/28/904.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ubuntu下mpd+mpc的安装配置</title>
		<link>http://bluehua.org/2010/01/27/896.html</link>
		<comments>http://bluehua.org/2010/01/27/896.html#comments</comments>
		<pubDate>Wed, 27 Jan 2010 14:18:24 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[mpc]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=896</guid>
		<description><![CDATA[今天大学的一个哥们说在ubuntu下面mpd一直配不好,俺就把俺的配置过程简单写一下
首先

sudo apt-get install mpd mpc

然后复制一份配置文件到自己的用户目录

cd ~
cp /etc/mpd.conf .mpdconf
#创建几个文件夹,后面用到
mkdir .mpd
mkdir .mpd/playlists

之后编辑.mpdconf,修改如下

#mp3所在的文件夹
music_directory		&#34;/media/data/music&#34;
#下面几个的user要替换成自己的用户名
playlist_directory		&#34;/home/user/.mpd/playlists&#34;
db_file			&#34;/home/user/.mpd/tag_cache&#34;
log_file			&#34;/home/hualu/.mpd/mpd.log&#34;
pid_file			&#34;/home/hualu/.mpd/pid&#34;
state_file			&#34;/home/hualu/.mpd/state&#34;
#替换成自己的用户名
user				&#34;user&#34;

除了上面几项,我还修改了下面几个配置,如果改完已上配置就可以运行就没有必要修改下面的了
我注释了下面这行,为了解决mpc报&#8221;unable to bind port 6600&#8243;错误的问题

#bind_to_address		&#34;localhost&#34;

声卡的配置我改成了下面,否则我用mpc调不了音量,而且有flash的时候会报&#8221;Failed to open ALSA device &#8220;plug:dmix&#8221;: Device or resource busy&#8221;

audio_output &#123;
	type		&#34;alsa&#34;
	name		&#34;My ALSA Device&#34;
        options &#34;dev=dmixer&#34;
	mixer_control	&#34;Master&#34;		# optional
	mixer_index	&#34;0&#34;		# optional
&#125;

配置完毕,可以使用了

#首次运行需要初始化一下
mpd --create-db
#把所有曲目添加到播放列表
mpc listall &#124; mpc add
#播放
mpc play

]]></description>
			<content:encoded><![CDATA[<p>今天大学的<a href="http://mindrecorder.info/">一个哥们</a>说在ubuntu下面mpd一直配不好,俺就把俺的配置过程简单写一下<br />
首先</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> mpd mpc</pre></div></div>

<p>然后复制一份配置文件到自己的用户目录</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mpd.conf .mpdconf
<span style="color: #666666; font-style: italic;">#创建几个文件夹,后面用到</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> .mpd
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> .mpd<span style="color: #000000; font-weight: bold;">/</span>playlists</pre></div></div>

<p>之后编辑.mpdconf,修改如下</p>

<div class="wp_syntax"><div class="code overflow"><pre class="text" style="font-family:monospace;">#mp3所在的文件夹
music_directory		&quot;/media/data/music&quot;
#下面几个的user要替换成自己的用户名
playlist_directory		&quot;/home/user/.mpd/playlists&quot;
db_file			&quot;/home/user/.mpd/tag_cache&quot;
log_file			&quot;/home/hualu/.mpd/mpd.log&quot;
pid_file			&quot;/home/hualu/.mpd/pid&quot;
state_file			&quot;/home/hualu/.mpd/state&quot;
#替换成自己的用户名
user				&quot;user&quot;</pre></div></div>

<p>除了上面几项,我还修改了下面几个配置,如果改完已上配置就可以运行就没有必要修改下面的了<br />
我注释了下面这行,为了解决mpc报&#8221;unable to bind port 6600&#8243;错误的问题</p>

<div class="wp_syntax"><div class="code overflow"><pre class="text" style="font-family:monospace;">#bind_to_address		&quot;localhost&quot;</pre></div></div>

<p>声卡的配置我改成了下面,否则我用mpc调不了音量,而且有flash的时候会报&#8221;Failed to open ALSA device &#8220;plug:dmix&#8221;: Device or resource busy&#8221;</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;">audio_output <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">type</span>		<span style="color: #ff0000;">&quot;alsa&quot;</span>
	name		<span style="color: #ff0000;">&quot;My ALSA Device&quot;</span>
        options <span style="color: #ff0000;">&quot;dev=dmixer&quot;</span>
	mixer_control	<span style="color: #ff0000;">&quot;Master&quot;</span>		<span style="color: #666666; font-style: italic;"># optional</span>
	mixer_index	<span style="color: #ff0000;">&quot;0&quot;</span>		<span style="color: #666666; font-style: italic;"># optional</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>配置完毕,可以使用了</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#首次运行需要初始化一下</span>
mpd <span style="color: #660033;">--create-db</span>
<span style="color: #666666; font-style: italic;">#把所有曲目添加到播放列表</span>
mpc listall <span style="color: #000000; font-weight: bold;">|</span> mpc add
<span style="color: #666666; font-style: italic;">#播放</span>
mpc play</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/27/896.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>准备做一个wordpress的离线编辑器</title>
		<link>http://bluehua.org/2010/01/24/886.html</link>
		<comments>http://bluehua.org/2010/01/24/886.html#comments</comments>
		<pubDate>Sun, 24 Jan 2010 07:47:26 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[offline editor]]></category>
		<category><![CDATA[pyqt4]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=886</guid>
		<description><![CDATA[2010.3.6 更新
由于最近的学习充电计划,这个东西暂时搁置了,现在已经可以自动保存了~
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
linux平台上一直没有这样一个所见即所得的blog离线编辑器,昨天试着用pyqt4写了一个小脚本,发现原来python做客户端软件是如此容易.然后下定决心要利用n个周末的时间自己写一个.
开始打算用纯qt的ui控件实现,但是感觉没有wordpress的编辑器这么亲切,于是想到一个界面亲切,实现也方便的方案: ui部分直接用web,框在一个pyqt的webkit组件里,逻辑部分用python的cgihttpserver在本地开一个cgi.
这个东西搞到今天雏形已经有了,可以实现跟wordress完全相同的书写体验.

顺带发那个pyqt的练手之作 :　emlreader.py 一个可以查看eml附件的脚本
]]></description>
			<content:encoded><![CDATA[<p>2010.3.6 更新<br />
由于最近的学习充电计划,这个东西暂时搁置了,现在已经可以自动保存了~<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
linux平台上一直没有这样一个所见即所得的blog离线编辑器,昨天试着用pyqt4写了一个小脚本,发现原来python做客户端软件是如此容易.然后下定决心要利用n个周末的时间自己写一个.</p>
<p>开始打算用纯qt的ui控件实现,但是感觉没有wordpress的编辑器这么亲切,于是想到一个界面亲切,实现也方便的方案: ui部分直接用web,框在一个pyqt的webkit组件里,逻辑部分用python的cgihttpserver在本地开一个cgi.</p>
<p>这个东西搞到今天雏形已经有了,可以实现跟wordress完全相同的书写体验.</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_048.png"><img class="alignnone size-medium wp-image-887" title="screenshot_048" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_048-300x240.png" alt="" width="300" height="240" /></a></p>
<p>顺带发那个pyqt的练手之作 :　<a href="http://bluehua.org/wp-content/uploads/2010/01/emlreader.py_.zip">emlreader.py</a> 一个可以查看eml附件的脚本</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/24/886.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>偶的mpd全局快捷键配置</title>
		<link>http://bluehua.org/2010/01/18/859.html</link>
		<comments>http://bluehua.org/2010/01/18/859.html#comments</comments>
		<pubDate>Mon, 18 Jan 2010 13:08:12 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[mpc]]></category>
		<category><![CDATA[mpd]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=859</guid>
		<description><![CDATA[2010.1.27 更新
发现直接调用mpc next 切歌有时候会把mpd搞死, mpc pause;mpc next;mpc play;这么搞就没问题了&#8230;
mpc.sh.4
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
更新一个高级点的,使用zenity提示搜索

下载:mpc.sh.3
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
2010.1.19 更新
ubuntu.org.cn上开的帖子 http://forum.ubuntu.org.cn/viewtopic.php?f=21&#038;t=253241
更新下脚本:mpc.sh.2
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
换了好多播放器，最终还是回归mpd了&#8230; 配上快捷键和模糊搜索，好用多了。效果如下:
上一首,下一首可以使用notify-send提示

快捷键调出搜索框,跳转到某一首歌

配置过程如下，假设已经装好了mpd和mpc：
1 . 安装notify-send

sudo apt-get install libnotify-bin

2 . 下载一个shell脚本 : mpc.sh,将脚本解压到 ~/bin/ 目录
3 . 配置全局快捷键
可用命令如下

#停止
sh /home/yourname/bin/mpc.sh stop
#播放/暂停
sh /home/yourname/bin/mpc.sh toggle
#下一首
sh /home/yourname/bin/mpc.sh next
#上一首
sh /home/yourname/bin/mpc.sh prev
#弹出一个搜索窗口
sh /home/yourname/bin/mpc.sh popfav

偶的快捷键的配置

]]></description>
			<content:encoded><![CDATA[<p>2010.1.27 更新<br />
发现直接调用mpc next 切歌有时候会把mpd搞死, mpc pause;mpc next;mpc play;这么搞就没问题了&#8230;<br />
<a href='http://bluehua.org/wp-content/uploads/2010/01/mpc.sh.4.zip'>mpc.sh.4</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
更新一个高级点的,使用<a href="http://library.gnome.org/users/zenity/stable/">zenity</a>提示搜索</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_043.png"><img src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_043.png" alt="" title="screenshot_043" width="510" height="301" class="alignnone size-full wp-image-879" /></a></p>
<p>下载:<a href='http://bluehua.org/wp-content/uploads/2010/01/mpc.sh.3.zip'>mpc.sh.3</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
2010.1.19 更新<br />
ubuntu.org.cn上开的帖子 <a href="http://forum.ubuntu.org.cn/viewtopic.php?f=21&#038;t=253241">http://forum.ubuntu.org.cn/viewtopic.php?f=21&#038;t=253241</a><br />
更新下脚本:<a href='http://bluehua.org/wp-content/uploads/2010/01/mpc.sh.2.zip'>mpc.sh.2</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
换了好多播放器，最终还是回归mpd了&#8230; 配上快捷键和模糊搜索，好用多了。效果如下:</p>
<p>上一首,下一首可以使用notify-send提示<br />
<a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_040.png"><img class="alignnone size-full wp-image-861" title="screenshot_040" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_040.png" alt="" width="408" height="292" /></a></p>
<p>快捷键调出搜索框,跳转到某一首歌</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_041.png"><img class="alignnone size-full wp-image-862" title="screenshot_041" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_041.png" alt="" width="530" height="114" /></a></p>
<p>配置过程如下，假设已经装好了mpd和mpc：<br />
1 . 安装notify-send</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> libnotify-bin</pre></div></div>

<p>2 . 下载一个shell脚本 : <a href='http://bluehua.org/wp-content/uploads/2010/01/mpc.sh.zip'>mpc.sh</a>,将脚本解压到 ~/bin/ 目录<br />
3 . 配置全局快捷键<br />
可用命令如下</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#停止</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yourname<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mpc.sh stop
<span style="color: #666666; font-style: italic;">#播放/暂停</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yourname<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mpc.sh toggle
<span style="color: #666666; font-style: italic;">#下一首</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yourname<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mpc.sh next
<span style="color: #666666; font-style: italic;">#上一首</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yourname<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mpc.sh prev
<span style="color: #666666; font-style: italic;">#弹出一个搜索窗口</span>
<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yourname<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mpc.sh popfav</pre></div></div>

<p>偶的快捷键的配置</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_042.png"><img class="alignnone size-full wp-image-864" title="screenshot_042" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_042.png" alt="" width="593" height="446" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/18/859.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>google工具栏牛x的分享按钮</title>
		<link>http://bluehua.org/2010/01/16/842.html</link>
		<comments>http://bluehua.org/2010/01/16/842.html#comments</comments>
		<pubDate>Sat, 16 Jan 2010 13:21:23 +0000</pubDate>
		<dc:creator>小鹿</dc:creator>
				<category><![CDATA[soft]]></category>
		<category><![CDATA[我火星]]></category>
		<category><![CDATA[google toolbar]]></category>
		<category><![CDATA[share button]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=842</guid>
		<description><![CDATA[偶火星了，更新了google的工具栏到7.0.20091216Lb1,发现多了一个牛x的分享功能。许多网站（包括renren）都提供了一个可以分享站外内容的书签，但是已经安装了google的工具栏，再开一个书签栏就太占地方了。这个按钮终于解决了这个问题，而且可以分享到n个站点。


列表里的人人网是我后来添进去的，默认列表里是没有的，一水的e文网站。工具栏还没有提供一个直接添加的方法，但是可以直接修改列表文件。列表文件位于：
~/.mozilla/firefox/这个目录名因人而异/GoogleToolbarData/components/share_providers.json

&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
补充：或直接找

cd ~/.mozilla
find ./ -name &#34;share_providers.json&#34;
#你会找到两个，覆盖我给的那个路径就可以

&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
可以直接下载偶修改好的文件：share_providers.json
曾经的分享按钮一直被冷落在菜单里：

]]></description>
			<content:encoded><![CDATA[<p>偶火星了，更新了google的工具栏到7.0.20091216Lb1,发现多了一个牛x的分享功能。许多网站（包括renren）都提供了一个可以分享站外内容的书签，但是已经安装了google的工具栏，再开一个书签栏就太占地方了。这个按钮终于解决了这个问题，而且可以分享到n个站点。</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_035.png"><img class="alignnone size-full wp-image-843" title="screenshot_035" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_035.png" alt="google toolbar的牛逼分享按钮" width="607" height="526" /></a></p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_034.png"><img class="alignnone size-full wp-image-845" title="screenshot_034" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_034.png" alt="google toolbar的分享按钮" width="310" height="113" /></a><br />
列表里的人人网是我后来添进去的，默认列表里是没有的，一水的e文网站。工具栏还没有提供一个直接添加的方法，但是可以直接修改列表文件。列表文件位于：</p>
<pre>~/.mozilla/firefox/这个目录名因人而异/GoogleToolbarData/components/share_providers.json
</pre>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
补充：或直接找</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>.mozilla
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;share_providers.json&quot;</span>
<span style="color: #666666; font-style: italic;">#你会找到两个，覆盖我给的那个路径就可以</span></pre></div></div>

<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
可以直接下载偶修改好的文件：<a href="http://bluehua.org/wp-content/uploads/2010/01/share_providers.json_.zip">share_providers.json</a></p>
<p>曾经的分享按钮一直被冷落在菜单里：</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_036.png"><img class="alignnone size-full wp-image-852" title="screenshot_036" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_036.png" alt="" width="389" height="456" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/16/842.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 5.223 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-03-11 23:41:53 -->
