<?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>余心烦错 &#187; Web Programming</title>
	<atom:link href="http://blog.efrees.com/category/web-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.efrees.com</link>
	<description>We shall meet in the place where there is no darkness.</description>
	<lastBuildDate>Mon, 09 Aug 2010 07:57:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Garb</title>
		<link>http://blog.efrees.com/garb.html</link>
		<comments>http://blog.efrees.com/garb.html#comments</comments>
		<pubDate>Mon, 09 Aug 2010 07:42:06 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=211</guid>
		<description><![CDATA[Garb是一个用于从Google Analytics 中查询数据的Ruby 类。相关链接： garb garb rdoc garb wiki 安装 $ sudo gem install garb 用法 用户验证 Garb::Session.login&#40;'someone@gmail.com', password&#41; &#160; 取回账户列表 Garb::Account.all &#160; 查找配置文件 Garb::Profile.first&#40;id&#41; &#160; id可以是统计代码中形如UA-247543-9的web_property_id,亦可是查看配置时网址https://www.google.com/analytics/reporting/?reset=1&#38;id=4662047中形如4662047的数字ID。 不可按域名查找。因为Google Analytics的配置文件并不是和域名绝对绑定的。但如果配置文件的名称就是域名的话，可以Garb::Profile.all取回所有配置文件再用域名比对title。 创建报告 Garb::Session.login&#40;'someone@gmail.com', password&#41; profile=Garb::Profile.first&#40;‘UA-247543-9’&#41; report = Garb::Report.new&#40;profile,:limit=&#62;50&#41; report.metrics :visits,:pageviews report.dimensions :keyword,:page_path report.sort :visits.desc report.filters :keyword.does_not_match =&#62; '&#40;not set&#41;' report.results &#160; 此报告取回热门关键词来源及相对应的Page，如: puts report.results.first ##&#60;OpenStruct visits=&#34;91&#34;, pageviews=&#34;106&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Garb是一个用于从Google Analytics 中查询数据的Ruby 类。相关链接：</p>
<ul>
<li><a href="http://github.com/vigetlabs/garb">garb</a></li>
<li><a href="http://rdoc.info/projects/vigetlabs/garb">garb rdoc</a></li>
<li><a href="http://wiki.github.com/vigetlabs/garb/">garb wiki</a></li>
</ul>
<span id=""><h2>安装</h2></span>
<p><code>$ sudo gem install garb</code></p>
<span id="_1"><h2>用法</h2></span>
<span id="_2"><h3>用户验证</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;">Garb::Session.<span style="color:#9900CC;">login</span><span style="color:#006600; font-weight:bold;">&#40;</span>'someone@gmail.<span style="color:#9900CC;">com</span>', password<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;</div>
<span id="_3"><h3>取回账户列表</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;">Garb::Account.<span style="color:#9900CC;">all</span><br />
&nbsp;</div>
<span id="_4"><h3>查找配置文件</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;">Garb::Profile.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span>id<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp;</div><br />
id可以是统计代码中形如<u>UA-247543-9</u>的web_property_id,亦可是查看配置时网址<i>https://www.google.com/analytics/reporting/?reset=1&amp;id=4662047</i>中形如<u>4662047</u>的数字ID。</p>
<p>不可按域名查找。因为Google Analytics的配置文件并不是和域名绝对绑定的。但如果配置文件的名称就是域名的话，可以Garb::Profile.all取回所有配置文件再用域名比对title。</p>
<span id="_5"><h3>创建报告</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;"><br />
Garb::Session.<span style="color:#9900CC;">login</span><span style="color:#006600; font-weight:bold;">&#40;</span>'someone@gmail.<span style="color:#9900CC;">com</span>', password<span style="color:#006600; font-weight:bold;">&#41;</span><br />
profile=Garb::Profile.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span>‘UA<span style="color:#006666;">-247543</span><span style="color:#006666;">-9</span>’<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
report = Garb::Report.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>profile,:limit=&gt;<span style="color:#006666;">50</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
report.<span style="color:#9900CC;">metrics</span> :visits,:pageviews<br />
report.<span style="color:#9900CC;">dimensions</span> :keyword,:page_path<br />
report.<span style="color:#9900CC;">sort</span> :visits.<span style="color:#9900CC;">desc</span><br />
<br />
report.<span style="color:#9900CC;">filters</span> :keyword.<span style="color:#9900CC;">does_not_match</span> =&gt; '<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">not</span> set<span style="color:#006600; font-weight:bold;">&#41;</span>'<br />
<br />
report.<span style="color:#9900CC;">results</span><br />
<br />
&nbsp;</div><br />
此报告取回热门关键词来源及相对应的Page，如:<br />
<div class="code ruby" style="font-family: Georgia,serif;"><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> report.<span style="color:#9900CC;">results</span>.<span style="color:#9900CC;">first</span><br />
<span style="color:#008000; font-style:italic;">##&lt;OpenStruct visits=&quot;91&quot;, pageviews=&quot;106&quot;, keyword=&quot;example&quot;, page_path=&quot;/garb.html&quot;&gt;</span><br />
<br />
&nbsp;</div>
<span id="_6"><h4>可用的参数</h4></span>
<ul>
<li>:start_date</li>
<li>:end_date</li>
<li>:limit</li>
<li>:offset</li>
</ul>
<span id="_7"><h4>指标和纬度</h4></span>
<p>metrics 和 dimensions 可参考 analytics 创建自定义报告中的<strong>指标</strong>和<strong>纬度</strong>，详细列表可查看Google官方文档：<a href="http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html">Dimensions &#038; Metrics</a>。</p>
<span id="_8"><h4>排序</h4></span>
<p>sort 默认升序排列，在参数后加.desc即为降序。</p>
<span id="_9"><h4>过滤</h4></span>
<p>指标可用的过滤语法<br />
<code><br />
eql => '==',<br />
not_eql => '!=',<br />
gt => '>',<br />
gte => '>=',<br />
lt => '<',<br />
lte => '<='<br />
</code><br />
纬度可用的语法<br />
<code><br />
matches => '==',<br />
does_not_match => '!=',<br />
contains => '=~',<br />
does_not_contain => '!~',<br />
substring => '=@',<br />
not_substring => '!@'<br />
</code><br />
示例<br />
<div class="code ruby" style="font-family: Georgia,serif;">report.<span style="color:#9900CC;">filters</span> :keyword.<span style="color:#9900CC;">does_not_match</span> =&gt; '<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">not</span> set<span style="color:#006600; font-weight:bold;">&#41;</span>',:visits.<span style="color:#9900CC;">gt</span> =&gt; <span style="color:#006666;">50</span><br />
&nbsp;</div>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=211&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/garb.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分析域名可能用到的Ruby脚本</title>
		<link>http://blog.efrees.com/domain-parse-ruby-scripts.html</link>
		<comments>http://blog.efrees.com/domain-parse-ruby-scripts.html#comments</comments>
		<pubDate>Fri, 23 Jul 2010 06:34:39 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=199</guid>
		<description><![CDATA[解析出TLD TLD即我们常谓的域名后缀。可用的TLD可分两类： 非国家类 如使用多年的arpa, com, edu, gov, int, mil, net, org等,以及新增的aero, biz, coop, info, museum, name, pro等等. 国家类 如cn,us,jp等，亦含com.cn,ac.cn,co.rw之类。 此外还有暂不能在互联网上使用仅用于测试等其它用途的几个后缀：example, invalid, localhost,test，详见RFC2606。 详细的可用TLD列表可参见firefox所用的tld列表。 分析TLD可以自行下载上述列表，假以分析。 亦可直接使用已有的类，如TLD lib , domainatrix gem。 domainatrix示例 &#160; &#160; require 'domainatrix' &#160; &#160; # &#160; &#160; url = Domainatrix.parse&#40;&#34;http://blog.efrees.com&#34;&#41; &#160; &#160; puts url.inspect &#160; &#160; puts url.public_suffix&#160; &#160; &#160; # =&#62; &#34;com&#34; [...]

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/libxml2-encoding-error-output-conversion-failed-due-to-conv-error.html' rel='bookmark' title='Permanent Link: libxml2 encoding error : output conversion failed due to conv error'>libxml2 encoding error : output conversion failed due to conv error</a> <small>Anemone是一个用Ruby写的Web Spider，在使用它爬取一个网站的时候，从入口页面进去，读不到任何链接。列出页面源码得到如下提示： encoding error : output conversion failed due to...</small></li>
<li><a href='http://blog.efrees.com/garb.html' rel='bookmark' title='Permanent Link: Garb'>Garb</a> <small>Garb是一个用于从Google Analytics 中查询数据的Ruby 类。相关链接： garb garb rdoc garb wiki 安装...</small></li>
<li><a href='http://blog.efrees.com/adsense-dianzi-zhuanzhang-fukuan.html' rel='bookmark' title='Permanent Link: Adsense中国用户可以使用电子转账付款？'>Adsense中国用户可以使用电子转账付款？</a> <small>在发生了无法收取adsense付款的事情之后，我很无奈的再一次阅读了adsense帮助。意外的发现，Google声称他们提供电子转账付款。...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><span id="TLD"><h2>解析出TLD</h2></span>
<p>TLD即我们常谓的域名后缀。可用的TLD可分两类：</p>
<ul>
<li>非国家类<br />
如使用多年的arpa, com, edu, gov, int, mil, net, org等,以及新增的aero, biz, coop, info, museum, name, pro等等.</li>
<li>国家类</li>
<p>如cn,us,jp等，亦含com.cn,ac.cn,co.rw之类。</ul>
<p>此外还有暂不能在互联网上使用仅用于测试等其它用途的几个后缀：example, invalid, localhost,test，详见<a href="http://www.ietf.org/rfc/rfc2606.txt">RFC2606</a>。</p>
<p>详细的可用TLD列表可参见<a href="http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1">firefox所用的tld列表</a>。</p>
<p>分析TLD可以自行下载上述列表，假以分析。<br />
亦可直接使用已有的类，如<a href="http://tldlib.rubyforge.org/index.html">TLD lib</a> , <a href="http://github.com/pauldix/domainatrix">domainatrix gem</a>。</p>
<span id="domainatrix"><h3>domainatrix示例</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;"><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> 'domainatrix'<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; url = Domainatrix.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://blog.efrees.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">inspect</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">public_suffix</span>&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; &quot;com&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">domain</span>&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; &quot;efrees&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">canonical</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;com.efrees.blog&quot;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#</span><br />
&nbsp; &nbsp; url = Domainatrix.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://blog.efrees.co.rw/category/google-adsense&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">public_suffix</span>&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># =&gt; &quot;co.rw&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">domain</span>&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; &quot;efrees&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">subdomain</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;blog&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">path</span>&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; &quot;/category/google-adsense&quot;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> url.<span style="color:#9900CC;">canonical</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;rw.co.efrees.blog/category/google-adsense&quot;</span><br />
<br />
&nbsp;</div><br />
使用的tld列表文件为<a href="http://github.com/pauldix/domainatrix/blob/master/lib/effective_tld_names.dat">effective_tld_names.dat</a>。</p>
<span id="Whois"><h2>Whois</h2></span>
<p>推荐<a href="http://www.ruby-whois.org/">ruby-whois</a>。</p>
<span id="Ruby-Whois"><h3>Ruby-Whois用法</h3></span>
<div class="code ruby" style="font-family: Georgia,serif;"><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> 'whois'<br />
&nbsp; &nbsp; a = Whois.<span style="color:#9900CC;">whois</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;efrees.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; #&lt;Whois::Answer ...&gt;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> a.<span style="color:#9900CC;">available</span>?<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; false</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> a.<span style="color:#9900CC;">registered</span>?<br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; true</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> a.<span style="color:#9900CC;">created_on</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># =&gt; Thu Jul 19 00:00:00 +0800 2007&nbsp; &nbsp;</span><br />
&nbsp; &nbsp; a.<span style="color:#9900CC;">nameservers</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |nameserver|<br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> nameserver<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; mns01.domaincontrol.com</span><br />
<span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; mns02.domaincontrol.com</span><br />
<span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; ns51.domaincontrol.com</span><br />
<span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; ns52.domaincontrol.com</span><br />
<br />
&nbsp;</div><br />
相关链接:</p>
<ul>
<li><a href="http://github.com/weppos/whois">ruby-whois@github</a></li>
<li><a href="http://www.ruby-whois.org/api/">ruby-whois rdoc</a></li>
<li><a href="http://www.ruby-whois.org/manual/installation.html">ruby-whois manual</a></li>
</ul>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=199&type=feed" alt="" />

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/libxml2-encoding-error-output-conversion-failed-due-to-conv-error.html' rel='bookmark' title='Permanent Link: libxml2 encoding error : output conversion failed due to conv error'>libxml2 encoding error : output conversion failed due to conv error</a> <small>Anemone是一个用Ruby写的Web Spider，在使用它爬取一个网站的时候，从入口页面进去，读不到任何链接。列出页面源码得到如下提示： encoding error : output conversion failed due to...</small></li>
<li><a href='http://blog.efrees.com/garb.html' rel='bookmark' title='Permanent Link: Garb'>Garb</a> <small>Garb是一个用于从Google Analytics 中查询数据的Ruby 类。相关链接： garb garb rdoc garb wiki 安装...</small></li>
<li><a href='http://blog.efrees.com/adsense-dianzi-zhuanzhang-fukuan.html' rel='bookmark' title='Permanent Link: Adsense中国用户可以使用电子转账付款？'>Adsense中国用户可以使用电子转账付款？</a> <small>在发生了无法收取adsense付款的事情之后，我很无奈的再一次阅读了adsense帮助。意外的发现，Google声称他们提供电子转账付款。...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/domain-parse-ruby-scripts.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用旧版i18n gem</title>
		<link>http://blog.efrees.com/%e4%bd%bf%e7%94%a8%e6%97%a7%e7%89%88i18n-gem.html</link>
		<comments>http://blog.efrees.com/%e4%bd%bf%e7%94%a8%e6%97%a7%e7%89%88i18n-gem.html#comments</comments>
		<pubDate>Sun, 27 Jun 2010 09:18:56 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=189</guid>
		<description><![CDATA[rails升级到2.3.8之后，一个之前使用rails 2.3.5的app出问题了。 该app使用了active_scaffold插件，当页面需要显示datetime类型的数据时，就会出错，错误提示： Showing vendor/plugins/active_scaffold/frontends/default/ views/_list_record_columns.html.erb where line #3 raised: missing interpolation argument in "%Y-%m-%{count}" ({:object=&#62;Thu, 19 Jul 2007} given) 查看了一下server log，此app默认用了i18n新版0.4.1，此前使用的是0.3.7。 使用bundle用回0.3.7，该问题没再出现。 配置bundle的方法见官方说明：Using Bundler with Rails 2.3。在Gemfile里加入一行 gem "i18n", '0.3.7' 再运行命令 bundle install 重启服务器即可。]]></description>
			<content:encoded><![CDATA[<p></p><p>rails升级到2.3.8之后，一个之前使用rails 2.3.5的app出问题了。</p>
<p>该app使用了active_scaffold插件，当页面需要显示datetime类型的数据时，就会出错，错误提示：</p>
<blockquote><p>Showing<br />
<em>vendor/plugins/active_scaffold/frontends/default/<br />
views/_list_record_columns.html.erb</em><br />
where line <strong>#3</strong> raised:<br />
<code>missing interpolation argument in "%Y-%m-%{count}" ({:object=&gt;Thu, 19 Jul 2007} given)</code>
</p></blockquote>
<p>查看了一下server log，此app默认用了i18n新版0.4.1，此前使用的是0.3.7。</p>
<p>使用bundle用回0.3.7，该问题没再出现。</p>
<p>配置bundle的方法见官方说明：<a href="http://gembundler.com/rails23.html">Using Bundler with Rails 2.3</a>。在Gemfile里加入一行<br />
<code>gem "i18n", '0.3.7'</code><br />
再运行命令<br />
<code>bundle install</code><br />
重启服务器即可。</p>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=189&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/%e4%bd%bf%e7%94%a8%e6%97%a7%e7%89%88i18n-gem.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql按数字大小排序String字段</title>
		<link>http://blog.efrees.com/mysql-numeric-sort-on-string-column.html</link>
		<comments>http://blog.efrees.com/mysql-numeric-sort-on-string-column.html#comments</comments>
		<pubDate>Sun, 23 May 2010 03:53:08 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=180</guid>
		<description><![CDATA[标题有点难以理解，事实是我不知道怎样用一句话来描述此种情形。 问题是这样的，当我们按由大到小的顺序排序一组数字的时候，它应该如此： 9800 8000 900 但如果是这些数字是以String类型存储的话，直接排序的结果会是这样: 9800 900 8000 当然多数情况下我们会把数字存储为数字型，就可避免这一问题。但还是有一些情形，数字被存储为String。 比如wordpress的postmetas表，它的meta_value已经固定了就是String。当我们需要把meta_value按数字大小排序的时候，直接写order by meta_value就不能达到我们所需要的目的。 如 SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY meta_value DESC; 得到的结果: 9800 900 8000 解决的方法是，在排序语句里把meta_value转成数字再排序，写作-meta_value。 如 SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY -meta_value ASC; 得到的结果: 9800 8000 900 此时采用的是按meta_value的负值排序，所以如需得到由大到小的效果，需要使用ASC而非DESC。当然也可以直接用--meta_value DESC。 如 SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>标题有点难以理解，事实是我不知道怎样用一句话来描述此种情形。</p>
<p>问题是这样的，当我们按由大到小的顺序排序一组数字的时候，它应该如此：</p>
<ol>
<li> 9800</li>
<li>8000</li>
<li>900</li>
</ol>
<p>但如果是这些数字是以String类型存储的话，直接排序的结果会是这样:</p>
<ol>
<li>9800</li>
<li>900</li>
<li>8000</li>
</ol>
<p>当然多数情况下我们会把数字存储为数字型，就可避免这一问题。但还是有一些情形，数字被存储为String。</p>
<p>比如wordpress的postmetas表，它的meta_value已经固定了就是String。当我们需要把meta_value按数字大小排序的时候，直接写order by meta_value就不能达到我们所需要的目的。</p>
<p>如</p>
<p><code>SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY meta_value DESC;</code><br />
得到的结果:</p>
<ol>
<li> 9800</li>
<li>900</li>
<li>8000</li>
</ol>
<p>解决的方法是，在排序语句里把meta_value转成数字再排序，写作<code>-meta_value</code>。</p>
<p>如</p>
<p><code>SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY -meta_value ASC;</code><br />
得到的结果:</p>
<ol>
<li> 9800</li>
<li>8000</li>
<li>900</li>
</ol>
<p>此时采用的是按meta_value的负值排序，所以如需得到由大到小的效果，需要使用ASC而非DESC。当然也可以直接用<code>--meta_value DESC</code>。</p>
<p>如</p>
<p><code>SELECT meta_value FROM postmeta WHERE meta_key="count" ORDER BY --meta_value DESC;</code><br />
得到的结果一样是:</p>
<ol>
<li> 9800</li>
<li>8000</li>
<li>900</li>
</ol>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=180&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/mysql-numeric-sort-on-string-column.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails中创建RSS</title>
		<link>http://blog.efrees.com/creating-a-rss-feed-in-ruby-on-rails.html</link>
		<comments>http://blog.efrees.com/creating-a-rss-feed-in-ruby-on-rails.html#comments</comments>
		<pubDate>Thu, 22 Apr 2010 04:25:49 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=176</guid>
		<description><![CDATA[PostsController &#160; def index &#160; &#160; @posts = Item.all&#40;:limit=&#62;10&#41; &#160; &#160; respond_to do &#124;format&#124; &#160; &#160; &#160; format.html &#160; &#160; &#160; format.xml&#160; &#123; render :template=&#62;'posts/rss.rxml'&#125; &#160; &#160; end &#160; end &#160; 使用respond_to可以根据需要返回不同的文档类型，如 访问http://localhost/posts,返回html 访问http://localhost/posts.xml,返回xml 是以，不是一定需要为feed新建一个action，直接用返回的xml作为RSS即可。上述代码中，访问/posts时，使用默认的posts/index.html.erb模板，访问posts.xml时，使用posts/rss.rxml模板。 app/views/posts/rss.rxml xml.instruct! xml.rss &#34;version&#34; =&#62; &#34;2.0&#34;, &#34;xmlns:dc&#34; =&#62; &#34;http://purl.org/dc/elements/1.1/&#34; do &#160;xml.channel do &#160; &#160;xml.title&#160; &#160; &#160; &#160;&#34;feed title&#34; &#160; &#160;xml.link&#160; [...]

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/farewell-google.html' rel='bookmark' title='Permanent Link: 别了，谷歌'>别了，谷歌</a> <small>壮士断腕，义无再辱 from 阮一峰的网络日志 三言二拍：Google退出中国 from 对牛乱弹琴 | Playin&#8217; with IT...</small></li>
<li><a href='http://blog.efrees.com/cakephp-tutorial-no-1-categories-acts-as-tree.html' rel='bookmark' title='Permanent Link: CakePHP 实例教程: Categories Acts as Tree'>CakePHP 实例教程: Categories Acts as Tree</a> <small>Tree是CakePHP 1.2的核心Behaviors之一，可以用来轻易的实现无限极分类，并呈现树状列表。 图片来源:Tree traversa,WIKIPEDIA 基础实例 建立数据表 CREATE TABLE `categories` &#40;...</small></li>
<li><a href='http://blog.efrees.com/linode-cpu-overload.html' rel='bookmark' title='Permanent Link: Deep link engine引致CPU占用过高'>Deep link engine引致CPU占用过高</a> <small>早上起来收到连串邮件，警告CPU占用过高。 登录上服务器一看，mysql的CPU占比竟然随时都在200%以上。 虽然心里也疑惑，CPU整体占用不过100%，何以mysql的数据会这么高？ 但也没细想，其中一个站数据量大，以前在godaday就曾引起过数据库超标， 当时的直接肇因是插件yet another related posts plugin。 于是先把服务器上几个站可能引起超标的插件都暂时禁用，...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><span id="PostsController"><h2>PostsController</h2></span>
<div class="code ruby" style="font-family: Georgia,serif;"><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> index<br />
&nbsp; &nbsp; @posts = Item.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>:limit=&gt;<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; respond_to <span style="color:#9966CC; font-weight:bold;">do</span> |format|<br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span>&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> render :template=&gt;'posts/rss.<span style="color:#9900CC;">rxml</span>'<span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp;</div><br />
使用respond_to可以根据需要返回不同的文档类型，如</p>
<ol>
<li>访问http://localhost/posts,返回html</li>
<li>访问http://localhost/posts.xml,返回xml</li>
</ol>
<p>是以，不是一定需要为feed新建一个action，直接用返回的xml作为RSS即可。上述代码中，访问/posts时，使用默认的posts/index.html.erb模板，访问posts.xml时，使用posts/rss.rxml模板。</p>
<span id="appviewspostsrss.rxml"><h2>app/views/posts/rss.rxml</h2></span>
<div class="code ruby" style="font-family: Georgia,serif;"><br />
xml.<span style="color:#9900CC;">instruct</span>!<br />
<br />
xml.<span style="color:#9900CC;">rss</span> <span style="color:#996600;">&quot;version&quot;</span> =&gt; <span style="color:#996600;">&quot;2.0&quot;</span>, <span style="color:#996600;">&quot;xmlns:dc&quot;</span> =&gt; <span style="color:#996600;">&quot;http://purl.org/dc/elements/1.1/&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp;xml.<span style="color:#9900CC;">channel</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp;xml.<span style="color:#9900CC;">title</span>&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#996600;">&quot;feed title&quot;</span><br />
&nbsp; &nbsp;xml.<span style="color:#9900CC;">link</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#996600;">&quot;url&quot;</span><br />
&nbsp; &nbsp;xml.<span style="color:#9900CC;">description</span> <span style="color:#996600;">&quot;description&quot;</span><br />
&nbsp; &nbsp;@posts.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |post|<br />
&nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">item</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">title</span>&nbsp; &nbsp; &nbsp; &nbsp;post.<span style="color:#9900CC;">title</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">link</span>&nbsp; &nbsp; &nbsp; &nbsp; post_url<span style="color:#006600; font-weight:bold;">&#40;</span>post<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">description</span> post.<span style="color:#9900CC;">content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">guid</span>&nbsp; &nbsp; &nbsp; &nbsp; post_url<span style="color:#006600; font-weight:bold;">&#40;</span>post<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;">#optional</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">category</span>&nbsp; &nbsp; post.<span style="color:#9900CC;">category</span>.<span style="color:#9900CC;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">author</span>&nbsp; &nbsp; &nbsp; post.<span style="color:#9900CC;">author</span>.<span style="color:#9900CC;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">pubdate</span>&nbsp; &nbsp; &nbsp;post.<span style="color:#9900CC;">updated_at</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;xml.<span style="color:#9900CC;">comments</span>&nbsp; &nbsp; post_url<span style="color:#006600; font-weight:bold;">&#40;</span>post<span style="color:#006600; font-weight:bold;">&#41;</span>+'<span style="color:#008000; font-style:italic;">#comments'</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp;</div>
<span id="configroutes.rb"><h2>config/routes.rb</h2></span>
<p>现下访问/posts.xml即可得到rss文档。需要的话，可以重写/feed到这个地址以符合惯例。<br />
<div class="code ruby" style="font-family: Georgia,serif;">map.<span style="color:#9900CC;">feed</span> 'feed',:controller =&gt; <span style="color:#996600;">&quot;posts&quot;</span>,:<span style="color:#CC0066; font-weight:bold;">format</span>=&gt;'xml'<br />
&nbsp;</div><br />
如此feed_url就等同于http://localhost/feed，其实际等同于/posts.xml 。</p>
<span id="appviewslayoutsapplication.html.erb"><h2>app/views/layouts/application.html.erb</h2></span>
<p>在head里添加feed link，以便浏览器识别<br />
<div class="code ruby" style="font-family: Georgia,serif;">auto_discovery_link_tag :rss, feed_url, :title =&gt; <span style="color:#996600;">&quot;Feed name&quot;</span><br />
&nbsp;</div><br />
即可.</p>
<span id=""><h2>参考链接</h2></span>
<ul>
<li><a href="http://paulsturgess.co.uk/articles/show/13-creating-an-rss-feed-in-ruby-on-rails">Creating an RSS feed in Ruby on Rails</a></li>
</ul>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=176&type=feed" alt="" />

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/farewell-google.html' rel='bookmark' title='Permanent Link: 别了，谷歌'>别了，谷歌</a> <small>壮士断腕，义无再辱 from 阮一峰的网络日志 三言二拍：Google退出中国 from 对牛乱弹琴 | Playin&#8217; with IT...</small></li>
<li><a href='http://blog.efrees.com/cakephp-tutorial-no-1-categories-acts-as-tree.html' rel='bookmark' title='Permanent Link: CakePHP 实例教程: Categories Acts as Tree'>CakePHP 实例教程: Categories Acts as Tree</a> <small>Tree是CakePHP 1.2的核心Behaviors之一，可以用来轻易的实现无限极分类，并呈现树状列表。 图片来源:Tree traversa,WIKIPEDIA 基础实例 建立数据表 CREATE TABLE `categories` &#40;...</small></li>
<li><a href='http://blog.efrees.com/linode-cpu-overload.html' rel='bookmark' title='Permanent Link: Deep link engine引致CPU占用过高'>Deep link engine引致CPU占用过高</a> <small>早上起来收到连串邮件，警告CPU占用过高。 登录上服务器一看，mysql的CPU占比竟然随时都在200%以上。 虽然心里也疑惑，CPU整体占用不过100%，何以mysql的数据会这么高？ 但也没细想，其中一个站数据量大，以前在godaday就曾引起过数据库超标， 当时的直接肇因是插件yet another related posts plugin。 于是先把服务器上几个站可能引起超标的插件都暂时禁用，...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/creating-a-rss-feed-in-ruby-on-rails.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP exec导入mysql数据</title>
		<link>http://blog.efrees.com/php-exec-import-mysql-data.html</link>
		<comments>http://blog.efrees.com/php-exec-import-mysql-data.html#comments</comments>
		<pubDate>Tue, 30 Mar 2010 10:08:57 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=167</guid>
		<description><![CDATA[如前迁移MYSQL数据所述，往mysql导入数据只需一句mysql -u username -p dbname &#60; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。 $cmd=sprintf&#40;'mysql -h %s -u %s --password=%s %s &#60; %s 2&#62;&#38;1', $db_host,$db_user,$db_pwd,$db_name,$file&#41;; exec&#40;$cmd,$out,$bin&#41;; print_r&#40;$out&#41;; &#160; 需要说明的是: 上述语句中，如果用-p的话，password需要另外输入，无法包含在语句之内。所以需要换用--password=。 脚本执行需时，加一句set_time_limit(0)可以延长执行时限。但set_time_limit和max_execution_time都只影响脚本自身执行时间，调用system、exec等函数时耗费的时间不包含在内。如果数据量比较大，当脚本中止之后，数据可能并未导完——exec的语句尚未执行完成。耐心等待一段时间，再去查看数据库是否导入完成即可。]]></description>
			<content:encoded><![CDATA[<p></p><p>如前<a href="http://blog.efrees.com/%E8%BF%81%E7%A7%BBmysql%E6%95%B0%E6%8D%AE.html">迁移MYSQL数据</a>所述，往mysql导入数据只需一句mysql -u username -p dbname &lt; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。</p>
<div class="code php" style="font-family: Georgia,serif;"><br />
<span style="color: #0000ff;">$cmd</span>=<a href="http://www.php.net/sprintf"><span style="color: #000066;">sprintf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mysql -h %s -u %s --password=%s %s &lt; %s 2&gt;&amp;1'</span>,<br />
<span style="color: #0000ff;">$db_host</span>,<span style="color: #0000ff;">$db_user</span>,<span style="color: #0000ff;">$db_pwd</span>,<span style="color: #0000ff;">$db_name</span>,<span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;<br />
<a href="http://www.php.net/exec"><span style="color: #000066;">exec</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$cmd</span>,<span style="color: #0000ff;">$out</span>,<span style="color: #0000ff;">$bin</span><span style="color: #66cc66;">&#41;</span>;<br />
<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$out</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div>
<p>需要说明的是:</p>
<ol>
<li> 上述语句中，如果用-p的话，password需要另外输入，无法包含在语句之内。所以需要换用<code>--password=</code>。</li>
<li>脚本执行需时，加一句set_time_limit(0)可以延长执行时限。但set_time_limit和max_execution_time都只影响脚本自身执行时间，调用system、exec等函数时耗费的时间不包含在内。如果数据量比较大，当脚本中止之后，数据可能并未导完——exec的语句尚未执行完成。耐心等待一段时间，再去查看数据库是否导入完成即可。</li>
</ol>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=167&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/php-exec-import-mysql-data.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>libxml2 encoding error : output conversion failed due to conv error</title>
		<link>http://blog.efrees.com/libxml2-encoding-error-output-conversion-failed-due-to-conv-error.html</link>
		<comments>http://blog.efrees.com/libxml2-encoding-error-output-conversion-failed-due-to-conv-error.html#comments</comments>
		<pubDate>Thu, 18 Mar 2010 07:59:49 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[anemone]]></category>
		<category><![CDATA[nokogiri]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=161</guid>
		<description><![CDATA[Anemone是一个用Ruby写的Web Spider，在使用它爬取一个网站的时候，从入口页面进去，读不到任何链接。列出页面源码得到如下提示： encoding error : output conversion failed due to conv error, bytes 0xCE 0xE8 0xBD 0xAE I/O error : encoder error &#160; Google了一下，这个提示广见于各种语言，并不限于Ruby。其共同点是，出现问题的地方，都用了Libxml2。在这个地方可以看到如下说明： libxml2 has a set of default converters for the following encodings (located in encoding.c): UTF-8 is supported by default (null handlers) UTF-16, both little and big endian ISO-Latin-1 (ISO-8859-1) covering most [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Anemone是一个用Ruby写的Web Spider，在使用它爬取一个网站的时候，从入口页面进去，读不到任何链接。列出页面源码得到如下提示：<br />
<div class="code ruby" style="font-family: Georgia,serif;"><br />
encoding error : output conversion failed due to conv error, bytes 0xCE 0xE8 0xBD 0xAE<br />
I/O error : encoder error<br />
<br />
&nbsp;</div><br />
Google了一下，这个提示广见于各种语言，并不限于Ruby。其共同点是，出现问题的地方，都用了Libxml2。在<a href="http://xmlsoft.org/encoding.html#Default">这个地方</a>可以看到如下说明：</p>
<blockquote><p>libxml2 has a set of default converters for the following encodings (located in encoding.c):</p>
<ul>
<li> UTF-8 is supported by default (null handlers)</li>
<li>UTF-16, both little and big endian</li>
<li>ISO-Latin-1 (ISO-8859-1) covering most western languages</li>
<li>ASCII, useful mostly for saving</li>
<li>HTML, a specific handler for the conversion of UTF-8 to ASCII with HTML predefined entities like © for the Copyright sign.</li>
</ul>
</blockquote>
<p>Anemone调用Nokogiri对抓取回来的页面进行分析，而Nokogiri则调用Libxml2。具体问题在哪我无从追究，但解决我眼前的问题倒也简单。经测试，目标网站是GB2312编码时才有此问题，只需在解析html之前先给它转码成UTF-8就好了。</p>
<p>在Page里添加一个函数<br />
<div class="code ruby" style="font-family: Georgia,serif;"><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> conv_body<span style="color:#006600; font-weight:bold;">&#40;</span>encoding<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp;<span style="color:#CC0066; font-weight:bold;">require</span> 'iconv'<br />
&nbsp; &nbsp;@body = Iconv.<span style="color:#9900CC;">conv</span><span style="color:#006600; font-weight:bold;">&#40;</span>'UTF<span style="color:#006666;">-8</span>//IGNORE',encoding,@body<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp;@body.<span style="color:#CC0066; font-weight:bold;">gsub</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>Regexp.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>encoding,Regexp::IGNORECASE<span style="color:#006600; font-weight:bold;">&#41;</span>,'utf<span style="color:#006666;">-8</span>'<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp;</div><br />
抓取的时候先执行一下<br />
<div class="code ruby" style="font-family: Georgia,serif;"><br />
Anemone.<span style="color:#9900CC;">crawl</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri,:verbose=&gt;true<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |anemone|<br />
&nbsp; anemone.<span style="color:#9900CC;">on_every_page</span> <span style="color:#9966CC; font-weight:bold;">do</span> |page|<br />
&nbsp; &nbsp;page.<span style="color:#9900CC;">conv_body</span><span style="color:#006600; font-weight:bold;">&#40;</span>'GB2312'<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp;<span style="color:#CC0066; font-weight:bold;">puts</span> page.<span style="color:#9900CC;">doc</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp;</div>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=161&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/libxml2-encoding-error-output-conversion-failed-due-to-conv-error.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>迁移MYSQL数据</title>
		<link>http://blog.efrees.com/%e8%bf%81%e7%a7%bbmysql%e6%95%b0%e6%8d%ae.html</link>
		<comments>http://blog.efrees.com/%e8%bf%81%e7%a7%bbmysql%e6%95%b0%e6%8d%ae.html#comments</comments>
		<pubDate>Sat, 20 Feb 2010 10:09:58 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=159</guid>
		<description><![CDATA[导出: shell&#62; mysqldump -u username -p dbname &#62; backup.sql，需要SSH登录; shell&#62; mysqldump -h hostname -u username -p dbname &#62; backup.sql，需要数据库支持远程连接; 用phpMyAdmin导出为文件，多数主机都有。没有的话可以自己装。 导入: shell&#62; mysql -u username -p dbname &#60; backup.sql，需要SSH登录; shell&#62; mysql -h hostname -u username -p dbname &#60; backup.sql，需要数据库支持远程连接，比较慢，但能对付大文件; 用phpMyAdmin导入。一般有文件大小限制，默认为2M。即使没有，文件大的情况下也极易超时。 直接迁移: shell&#62; mysqldump --opt dbname &#124; mysql -h hostname -C dbname 很好用，最近常用。年前受了15个独立IP的诱惑，买了一份ixwebhosting的Unlimited Pro Plan。计划逐步把一些站迁过去，然后才发现ixwebhosting不支持SSH，没法直接导入数据，phpMyAdmin又只支持2M，对大文件一点办法都没有。好在经测试发现其数据库支持远程连接，这才省却一些麻烦。 额外一提的是，ixwebhosting的mysql管理面板里没有CPanel那样的连接权限管理，默认支持所有远程连接。这应该算是一个安全隐患吧。 [...]

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/php-exec-import-mysql-data.html' rel='bookmark' title='Permanent Link: PHP exec导入mysql数据'>PHP exec导入mysql数据</a> <small>如前迁移MYSQL数据所述，往mysql导入数据只需一句mysql -u username -p dbname &lt; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。 $cmd=sprintf&#40;'mysql -h %s...</small></li>
<li><a href='http://blog.efrees.com/mysqldump-utf8-encoding.html' rel='bookmark' title='Permanent Link: MySQLdump诡异的编码问题'>MySQLdump诡异的编码问题</a> <small>很诡异的问题。 当我mysqldump得到的文件打开显示乱码的时候，我按照手册所示加上了--default-character-set=utf8。但得到的文件仍旧不是utf8。 再一次依赖Google大神的帮助，找到了这个页面: mysqldump double encodes utf-8 innodb tables ....</small></li>
<li><a href='http://blog.efrees.com/migrate-wordpress-to-new-server-2.html' rel='bookmark' title='Permanent Link: 迁移WordPress到新主机'>迁移WordPress到新主机</a> <small>记录一下从Godaddy share hosting上搬家到Godaddy VPS的过程。 1.新主机设置 绑定域名、新建数据库之类操作。具体到Godaddy VPS，登录进simple control panel后： Domains...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><span id=":"><h2>导出:</h2></span>
<ol>
<li><code>shell&gt; mysqldump -u username -p dbname &gt; backup.sql</code>，需要SSH登录;</li>
<li><code>shell&gt; mysqldump -h hostname -u username -p dbname &gt; backup.sql</code>，需要数据库支持远程连接;</li>
<li>用phpMyAdmin导出为文件，多数主机都有。没有的话可以自己装。</li>
</ol>
<span id=":_1"><h2>导入:</h2></span>
<ol>
<li><code>shell&gt; mysql -u username -p dbname &lt; backup.sql</code>，需要SSH登录;</li>
<li><code>shell&gt; mysql -h hostname -u username -p dbname &lt; backup.sql</code>，需要数据库支持远程连接，比较慢，但能对付大文件;</li>
<li>用phpMyAdmin导入。一般有文件大小限制，默认为2M。即使没有，文件大的情况下也极易超时。</li>
</ol>
<span id=":_2"><h2>直接迁移:</h2></span>
<p><code>shell&gt; mysqldump --opt dbname | mysql -h hostname -C dbname</code><br />
很好用，最近常用。年前受了15个独立IP的诱惑，买了一份ixwebhosting的Unlimited Pro Plan。计划逐步把一些站迁过去，然后才发现ixwebhosting不支持SSH，没法直接导入数据，phpMyAdmin又只支持2M，对大文件一点办法都没有。好在经测试发现其数据库支持远程连接，这才省却一些麻烦。</p>
<p>额外一提的是，ixwebhosting的mysql管理面板里没有CPanel那样的连接权限管理，<strong>默认</strong>支持所有远程连接。这应该算是一个安全隐患吧。</p>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=159&type=feed" alt="" />

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/php-exec-import-mysql-data.html' rel='bookmark' title='Permanent Link: PHP exec导入mysql数据'>PHP exec导入mysql数据</a> <small>如前迁移MYSQL数据所述，往mysql导入数据只需一句mysql -u username -p dbname &lt; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。 $cmd=sprintf&#40;'mysql -h %s...</small></li>
<li><a href='http://blog.efrees.com/mysqldump-utf8-encoding.html' rel='bookmark' title='Permanent Link: MySQLdump诡异的编码问题'>MySQLdump诡异的编码问题</a> <small>很诡异的问题。 当我mysqldump得到的文件打开显示乱码的时候，我按照手册所示加上了--default-character-set=utf8。但得到的文件仍旧不是utf8。 再一次依赖Google大神的帮助，找到了这个页面: mysqldump double encodes utf-8 innodb tables ....</small></li>
<li><a href='http://blog.efrees.com/migrate-wordpress-to-new-server-2.html' rel='bookmark' title='Permanent Link: 迁移WordPress到新主机'>迁移WordPress到新主机</a> <small>记录一下从Godaddy share hosting上搬家到Godaddy VPS的过程。 1.新主机设置 绑定域名、新建数据库之类操作。具体到Godaddy VPS，登录进simple control panel后： Domains...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/%e8%bf%81%e7%a7%bbmysql%e6%95%b0%e6%8d%ae.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>开心餐厅自动做菜脚本</title>
		<link>http://blog.efrees.com/kaixin001-cafe-helper.html</link>
		<comments>http://blog.efrees.com/kaixin001-cafe-helper.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 03:40:43 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=156</guid>
		<description><![CDATA[前几天晚上无聊的时候都在用手机玩开心餐厅。反反复复的去烧菜，都快强迫症了。在耗费了无数大好光阴之后，终于想起那句至理名言：磨刀不误砍柴工。于是写了两个自动做菜脚本，一个Javascript版，一个PHP版。 Javascript版开心餐厅助手 用于GreaseMonkey的javascript脚本，在此下载。 用法： 在firefox里访问开心网手机版(http://wap.kaixin001.com )登录至餐厅。启用脚本，即开始自动做菜。 需要说明的是，这是一个比较简陋的仅满足自用的非通用脚本，没有设置。使用前务必先看说明。默认是每45秒刷新一次，随机做红烧茄子或炸酱面，做别的菜请参照说明自行更改——需要一点Javascript基础。 存在的问题： 偶尔网络延迟时从google载入JQuery会超时，使得脚本没运行，此时需手动刷新。 PHP版开心餐厅自动做菜脚本 部署在服务器上，用免费的WEBCRON服务每6分钟执行一次，不需要自己开机，比Javascript版的更省心，也更稳定可靠一些。但就需要自己有主机方可。 昨晚睡觉前挂上这脚本做宫保鸡丁，今早起来攒了18000多份——执行周期设错了，不然应该更多才对。升到13级后才发现原来参照的那份收益表有问题，现在按新的收益表挂着做红烧茄子。 另，godaddy的cron服务执行周期最短为1个小时，做宫保鸡丁要15分钟，红烧茄子5分钟，炸酱面3分钟，实在不敷应用。google找到一个cron服务，SETCRONJOB。免费帐号支持每5分钟执行，10天过期。收费服务可支持到1分钟，只要5-20美元每年。 开心餐厅收益表 开心网上转贴里流传着一个餐厅实用秘籍，但里边的收益表数据老旧了。google找到份新的：]]></description>
			<content:encoded><![CDATA[<p></p><p>前几天晚上无聊的时候都在用手机玩开心餐厅。反反复复的去烧菜，都快强迫症了。在耗费了无数大好光阴之后，终于想起那句至理名言：磨刀不误砍柴工。于是写了两个自动做菜脚本，一个Javascript版，一个PHP版。</p>
<span id="Javascript"><h3>Javascript版开心餐厅助手</h3></span>
<p>用于GreaseMonkey的javascript脚本，<a href="http://userscripts.org/scripts/show/69361">在此下载</a>。</p>
<p>用法：<br />
在firefox里访问开心网手机版(http://wap.kaixin001.com )登录至餐厅。启用脚本，即开始自动做菜。</p>
<p><strong>需要说明的是，这是一个比较简陋的仅满足自用的非通用脚本，没有设置。使用前务必先看说明。默认是每45秒刷新一次，随机做红烧茄子或炸酱面，做别的菜请参照说明自行更改——需要一点Javascript基础。</strong></p>
<p>存在的问题：</p>
<p>偶尔网络延迟时从google载入JQuery会超时，使得脚本没运行，此时需手动刷新。</p>
<span id="PHP"><h3>PHP版开心餐厅自动做菜脚本</h3></span>
<p>部署在服务器上，用免费的WEBCRON服务每6分钟执行一次，不需要自己开机，比Javascript版的更省心，也更稳定可靠一些。但就需要自己有主机方可。</p>
<p>昨晚睡觉前挂上这脚本做宫保鸡丁，今早起来攒了18000多份——执行周期设错了，不然应该更多才对。升到13级后才发现原来参照的那份收益表有问题，现在按新的收益表挂着做红烧茄子。</p>
<p>另，godaddy的cron服务执行周期最短为1个小时，做宫保鸡丁要15分钟，红烧茄子5分钟，炸酱面3分钟，实在不敷应用。google找到一个cron服务，<a href="http://www.setcronjob.com">SETCRONJOB</a>。免费帐号支持每5分钟执行，10天过期。收费服务可支持到1分钟，只要5-20美元每年。</p>
<span id=""><h3>开心餐厅收益表</h3></span>
<p>开心网上转贴里流传着一个<a href="http://www.kaixin001.com/!repaste/detail.php?uid=108301&#038;urpid=1426866464">餐厅实用秘籍</a>，但里边的收益表数据老旧了。google找到份新的：</p>
<p><a href="http://blog.efrees.com/wp-content/uploads/2010/02/kaixin-cafe2.jpg"><img src="http://blog.efrees.com/wp-content/uploads/2010/02/kaixin-cafe2-450x387.jpg" alt="" title="开心餐厅收益表" width="450" height="387" class="alignnone size-medium wp-image-158" /></a></p>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=156&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/kaixin001-cafe-helper.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WordPress机能备忘</title>
		<link>http://blog.efrees.com/wordpress-plugin-dev-notes.html</link>
		<comments>http://blog.efrees.com/wordpress-plugin-dev-notes.html#comments</comments>
		<pubDate>Sat, 02 Jan 2010 09:22:59 +0000</pubDate>
		<dc:creator>muzik</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.efrees.com/?p=145</guid>
		<description><![CDATA[每次写点小插件都会想不起那些繁杂的filters到底叫些什么，此帖用于不定期记录以备忘。 添加URL重写规则 经常性需求。比如需要添加一个/submit而又不想新建页面，又或想增强文章列表以使得其能按某几种特定规则排序。添加Rewrite规则可以有两种形式： 在后台设置固定链接的过程中添加。此种方式通过一次设置把处理过的新规则写入数据库。 在每个访问请求时添加，好处是写代码时便于测试。 前一种在一些常用插件中会有存在。后一种比较少见，牵涉到的filter是transient_rewrite_rules，变量$rules。相关的文件及函数列表: /wp-includes/rewrite.php,WP_Rewrite::wp_rewrite_rules() /wp-includes/functions.php,get_transient() 以上filter在2.9.2版中已移除。 添加Query Vars 经常性需求，与上一段关系密切。filter是query_vars，变量$vars。 列印所有数据库查询 先作一个常量声明，$wpdb就会把所有的查询记录下来。 define&#40;'SAVEQUERIES',true&#41;; &#160; 在页面底部输出即可 global $wpdb; printf&#40;'&#60;pre&#62;%s&#60;/pre&#62;',print_r&#40;$wpdb-&#62;queries,true&#41;&#41;; &#160; 可以先在页面底部输出查询数，如查询数过高，再来列印详细找出问题所在。 printf&#40;'%d queries. %s seconds.', get_num_queries&#40;&#41;, timer_stop&#40;0, 3&#41;&#41;; &#160; 更换域名或网址 先确认需要替换的行 mysql> select option_value from wp_options where option_value like 'http://%'; mysql> update wp_options set option_value = 'http://newaddress' where option_value like 'http://olddomain%' Related posts:PHP exec导入mysql数据 [...]

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/php-exec-import-mysql-data.html' rel='bookmark' title='Permanent Link: PHP exec导入mysql数据'>PHP exec导入mysql数据</a> <small>如前迁移MYSQL数据所述，往mysql导入数据只需一句mysql -u username -p dbname &lt; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。 $cmd=sprintf&#40;'mysql -h %s...</small></li>
<li><a href='http://blog.efrees.com/wordpress-theme-berita-hack.html' rel='bookmark' title='Permanent Link: WordPress主题berita几处修改记录'>WordPress主题berita几处修改记录</a> <small>前阵子看到这篇《使用WordPress定制企业网站》介绍的berita这个主题。界面我很喜欢，以前也确曾帮朋友用wordpress做过企业网站，于是就去下载了官方原版来用。 当然世事无完美，更没有什么主题能够完全适应各种需求。使用中发现了一些小问题，或者仅仅是不符合个人需求之处，做了一些改动，特此记录。 选择空分类作为博客页 设置面板里Blog Section Settings->Pick Category for Your Blog...</small></li>
<li><a href='http://blog.efrees.com/archives/xmlrpc-use-to-publish-articles-wordpress' rel='bookmark' title='Permanent Link: 使用XMLRPC发布文章到wordpress'>使用XMLRPC发布文章到wordpress</a> <small>&nbsp; &nbsp;&nbsp; &nbsp;$xmlrpcurl='http://efrees.com/blog/xmlrpc.php'; &nbsp; &nbsp;&nbsp; &nbsp;$username='admin'; &nbsp; &nbsp;&nbsp; &nbsp;$password='password'; &nbsp;...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p></p><p>每次写点小插件都会想不起那些繁杂的filters到底叫些什么，此帖用于不定期记录以备忘。</p>
<p><span id="more-145"></span><br />
<div class='toc wptoc'>
<h2>Contents</h2>
<ol class='toc-odd level-1'>
	<li>
		<a href="#URL">添加URL重写规则</a>
	</li>
	<li>
		<a href="#Query_Vars">添加Query Vars</a>
	</li>
	<li>
		<a href="#">列印所有数据库查询</a>
	</li>
	<li>
		<a href="#_1">更换域名或网址</a>
	</li>
</ol>
</ol>
</ol>
</div>
<div class='wptoc-end'>&nbsp;</div></p>
<span id="URL"><h3>添加URL重写规则</h3></span>
<p>经常性需求。比如需要添加一个/submit而又不想新建页面，又或想增强文章列表以使得其能按某几种特定规则排序。添加Rewrite规则可以有两种形式：</p>
<ol>
<li>在后台设置固定链接的过程中添加。此种方式通过一次设置把处理过的新规则写入数据库。</li>
<li>在每个访问请求时添加，好处是写代码时便于测试。</li>
</ol>
<p>前一种在一些常用插件中会有存在。后一种比较少见，牵涉到的filter是<code>transient_rewrite_rules</code>，变量$rules。相关的文件及函数列表:</p>
<ol>
<li>/wp-includes/rewrite.php,WP_Rewrite::wp_rewrite_rules()</li>
<li>/wp-includes/functions.php,get_transient()</li>
</ol>
<p><ins datetime="2010-02-20T10:26:41+00:00">以上filter在2.9.2版中已移除。</ins></p>
<span id="Query_Vars"><h3>添加Query Vars</h3></span>
<p>经常性需求，与上一段关系密切。filter是<code>query_vars</code>，变量$vars。</p>
<span id=""><h3>列印所有数据库查询</h3></span>
<p>先作一个常量声明，$wpdb就会把所有的查询记录下来。<br />
<div class="code php" style="font-family: Georgia,serif;"><br />
<a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SAVEQUERIES'</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div><br />
在页面底部输出即可<br />
<div class="code php" style="font-family: Georgia,serif;"><br />
<a href="http://www.php.net/global"><span style="color: #000066;">global</span></a> <span style="color: #0000ff;">$wpdb</span>;<br />
<a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&lt;pre&gt;%s&lt;/pre&gt;'</span>,<a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$wpdb</span>-&gt;<span style="color: #006600;">queries</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div><br />
可以先在页面底部输出查询数，如查询数过高，再来列印详细找出问题所在。<br />
<div class="code php" style="font-family: Georgia,serif;"><br />
<a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'%d queries. %s seconds.'</span>, get_num_queries<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, timer_stop<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp;</div>
<span id="_1"><h3>更换域名或网址</h3></span>
<p>先确认需要替换的行<br />
<code>mysql> select option_value from wp_options where option_value like 'http://%';</code></p>
<p><code>mysql> update wp_options set option_value = 'http://newaddress' where option_value like 'http://olddomain%'</code></p>
<img src="http://blog.efrees.com/?ak_action=api_record_view&id=145&type=feed" alt="" />

<h3>Related posts:</h3><ol><li><a href='http://blog.efrees.com/php-exec-import-mysql-data.html' rel='bookmark' title='Permanent Link: PHP exec导入mysql数据'>PHP exec导入mysql数据</a> <small>如前迁移MYSQL数据所述，往mysql导入数据只需一句mysql -u username -p dbname &lt; backup.sql就可以了。但在服务器不支持ssh的情况下，一般就只能用PHP脚本来导入。除了读入数据一条条去mysql_query之外，用exec来执行上述语句会快许多——如果服务器支持的话。 $cmd=sprintf&#40;'mysql -h %s...</small></li>
<li><a href='http://blog.efrees.com/wordpress-theme-berita-hack.html' rel='bookmark' title='Permanent Link: WordPress主题berita几处修改记录'>WordPress主题berita几处修改记录</a> <small>前阵子看到这篇《使用WordPress定制企业网站》介绍的berita这个主题。界面我很喜欢，以前也确曾帮朋友用wordpress做过企业网站，于是就去下载了官方原版来用。 当然世事无完美，更没有什么主题能够完全适应各种需求。使用中发现了一些小问题，或者仅仅是不符合个人需求之处，做了一些改动，特此记录。 选择空分类作为博客页 设置面板里Blog Section Settings->Pick Category for Your Blog...</small></li>
<li><a href='http://blog.efrees.com/archives/xmlrpc-use-to-publish-articles-wordpress' rel='bookmark' title='Permanent Link: 使用XMLRPC发布文章到wordpress'>使用XMLRPC发布文章到wordpress</a> <small>&nbsp; &nbsp;&nbsp; &nbsp;$xmlrpcurl='http://efrees.com/blog/xmlrpc.php'; &nbsp; &nbsp;&nbsp; &nbsp;$username='admin'; &nbsp; &nbsp;&nbsp; &nbsp;$password='password'; &nbsp;...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://blog.efrees.com/wordpress-plugin-dev-notes.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: blog.efrees.com @ 2010-09-06 12:17:27 -->