<?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://www.tiddr.de/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tiddr.de/blog</link>
	<description>tiddr</description>
	<lastBuildDate>Sat, 03 Dec 2011 14:55:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHPUnit, treat our programmer better</title>
		<link>http://www.tiddr.de/blog/2011/11/18/better-treat-our-programmer-phpunit/</link>
		<comments>http://www.tiddr.de/blog/2011/11/18/better-treat-our-programmer-phpunit/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 11:25:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=403</guid>
		<description><![CDATA[While no doubt PHPUnit is an excellent project, today i was so frustrated because of it. Look at the following code, first I declared an mock then defined some behavior of the mock. Since I did some re-factoring and use CatetoryId instead of Category here, I renamed mock method from &#8216;getCategory&#8217; to &#8216;getCategoryId&#8217;. Then when [...]]]></description>
			<content:encoded><![CDATA[<p>While no doubt PHPUnit is an excellent project, today i was so frustrated because of it.</p>
<p>Look at the following code, first I declared an mock then defined some behavior of the mock.<br />
Since I did some re-factoring and use <strong>CatetoryId</strong> instead of <strong>Category</strong> here, I renamed mock <strong>method</strong> from &#8216;getCategory&#8217; to &#8216;getCategoryId&#8217;. Then when the getCategoryId is called in the test, it will not return 2, because this method is not declared. I didn&#8217;t notice it for a long time, and check all possibilities. </p>
<p>I&#8217;m totally fine with two steps workflow, i.e. First declare then define. But why there is no warning/error when I try to define a mock method, which is not declared.<br />
<div id="gist-1376183" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="x">$product = $this-&gt;getMock(&#39;Product&#39;, array(&#39;getId&#39;, &#39;getCategory&#39;, &#39;getPrice&#39;));</span></div><div class='line' id='LC2'><span class="x">$product = $this-&gt;expects($this-&gt;any())</span></div><div class='line' id='LC3'><span class="x">                -&gt;method(&#39;getCategoryId&#39;)</span></div><div class='line' id='LC4'><span class="x">                -&gt;will($this-&gt;returnValue(2));</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1376183/de40a3c65951842d7fb9cbcb94c981ba9aecae24/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1376183#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1376183">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/11/18/better-treat-our-programmer-phpunit/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/11/18/better-treat-our-programmer-phpunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send complex json request</title>
		<link>http://www.tiddr.de/blog/2011/10/17/send-complex-json-request/</link>
		<comments>http://www.tiddr.de/blog/2011/10/17/send-complex-json-request/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 14:14:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=392</guid>
		<description><![CDATA[As using Backbone.js I wanted to send a whole JSON object to the back end, which is implemented with Zend Framework. Tim White has written a very good article about it. What I have done is converting the JSON object to a string and send it per POST to the back end. Then let back [...]]]></description>
			<content:encoded><![CDATA[<p>As using Backbone.js I wanted to send a whole JSON object to the back end, which is implemented with Zend Framework.</p>
<p>Tim White has written a <a title="article" href="http://www.zulius.com/how-to/send-multidimensional-arrays-php-with-jquery-ajax/">very good article</a> about it.</p>
<p>What I have done is converting the JSON object to a string and send it per POST to the back end. Then let back end decode this string.</p>
<p>The code of frontend is:</p>
<pre class="javascript">
           $.ajax({
               url: '/controller1/action1/format/json',
               type: 'POST',
               data: JSON.stringify(data),
               contentType: 'application/json',
               success: function(resp) {cb(resp);},
               error: function(resp){errorCb(resp);}
            });
</pre>
<p>JSON.stringify is used here to serialize the JSON to string.</p>
<p>The backend code is like:</p>
<pre class="php">        $data = json_decode($this->getRequest()->getRawBody());</pre>
<p>Since the string of json is send per post payload, you can not use</p>
<pre class="php">$this->getRequest()->getParams();</pre>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/10/17/send-complex-json-request/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/10/17/send-complex-json-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tail complains  cannot watch `var/log/system.log&#8217;: No space left on device</title>
		<link>http://www.tiddr.de/blog/2011/09/09/tail-complains-cannot-watch-varlogsystem-log-no-space-left-on-device/</link>
		<comments>http://www.tiddr.de/blog/2011/09/09/tail-complains-cannot-watch-varlogsystem-log-no-space-left-on-device/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 08:11:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=381</guid>
		<description><![CDATA[Solution: sudo sysctl fs.inotify.max_user_watches=999999999 edit /etc/sysctl.conf add fs.inotify.max_user_watches=999999999 see http://unix.stackexchange.com/questions/13751/kernel-inotify-watch-limit-reached]]></description>
			<content:encoded><![CDATA[<p>Solution:<br />
    sudo sysctl fs.inotify.max_user_watches=999999999</p>
<p>edit<br />
    /etc/sysctl.conf<br />
add<br />
    fs.inotify.max_user_watches=999999999</p>
<p>see http://unix.stackexchange.com/questions/13751/kernel-inotify-watch-limit-reached</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/09/09/tail-complains-cannot-watch-varlogsystem-log-no-space-left-on-device/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/09/09/tail-complains-cannot-watch-varlogsystem-log-no-space-left-on-device/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solve the problem about sending email per sendmail extremely slow</title>
		<link>http://www.tiddr.de/blog/2011/09/08/fix-send-mail-extremely-slow/</link>
		<comments>http://www.tiddr.de/blog/2011/09/08/fix-send-mail-extremely-slow/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 12:38:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=379</guid>
		<description><![CDATA[error message     My unqualified host name (ting-Vostro-460) unknown; sleeping for retry solution: Adding your host name (my host name is ting-Vostro-460, replace it with your host name) into /etc/hosts like following         127.0.0.1 localhost ting-Vostro-460 ting-Vostro-460. The &#8220;.&#8221; after the host name is very important. &#160; You may need to [...]]]></description>
			<content:encoded><![CDATA[<h2><span style="color: #003366;">error message</span></h2>
<p><em><strong>    My unqualified host name (ting-Vostro-460) unknown; sleeping for retry</strong></em></p>
<h2><em><strong></strong></em><br />
<span style="color: #003366;">solution:</span></h2>
<p>Adding your host name (my host name is ting-Vostro-460, replace it with your host name) into /etc/hosts like following</p>
<p><em><strong>        127.0.0.1 localhost ting-Vostro-460 ting-Vostro-460.</strong></em></p>
<p><em><strong></strong></em><br />
The <strong>&#8220;.&#8221;</strong> after the host name is very important.</p>
<p>&nbsp;</p>
<p>You may need to add the following line into /etc/mail/sendmail.mc your mail</p>
<pre>FEATURE(`accept_unresolvable_domains')dnl</pre>
<pre>After changing the config using make to generate sendmail.cf. Then restart the sendmail &gt;sudo /etc/init.d/sendmail restart.</pre>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/09/08/fix-send-mail-extremely-slow/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/09/08/fix-send-mail-extremely-slow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento cache</title>
		<link>http://www.tiddr.de/blog/2011/09/07/magento-cache/</link>
		<comments>http://www.tiddr.de/blog/2011/09/07/magento-cache/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 10:48:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bad]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=377</guid>
		<description><![CDATA[If your/var/cache has not write right for www-data, magento will save the cache file into /tmp/magento/var/cache]]></description>
			<content:encoded><![CDATA[<p>If your/var/cache has not write right for www-data, magento will save the cache file into /tmp/magento/var/cache</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/09/07/magento-cache/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/09/07/magento-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>install nltk on mac os lion</title>
		<link>http://www.tiddr.de/blog/2011/09/06/install-nltk-on-mac-os-lion/</link>
		<comments>http://www.tiddr.de/blog/2011/09/06/install-nltk-on-mac-os-lion/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 19:10:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nltk]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=372</guid>
		<description><![CDATA[If you try to install nltk with easy_install you will get an error, setup.py can not be found. Using src file directly can solve this problem ➜ ~ sudo easy_install pyyaml ➜ ~ sudo easy_install http://pypi.python.org/packages/source/n/nltk/nltk-2.0.1rc1.tar.gz]]></description>
			<content:encoded><![CDATA[<p>If you try to install nltk with easy_install you will get an error, setup.py can not be found. Using src file directly can solve this problem </p>
<p>➜  ~  sudo easy_install pyyaml</p>
<p>➜  ~  sudo easy_install http://pypi.python.org/packages/source/n/nltk/nltk-2.0.1rc1.tar.gz</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/09/06/install-nltk-on-mac-os-lion/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/09/06/install-nltk-on-mac-os-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>clone an php object</title>
		<link>http://www.tiddr.de/blog/2011/08/16/clone-an-php-object/</link>
		<comments>http://www.tiddr.de/blog/2011/08/16/clone-an-php-object/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 09:02:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=373</guid>
		<description><![CDATA[Array and Object in PHP are all reference. If you assign a variable with an array or an object, this variable is a reference of that array/object. Using clone you can copy an object. php> class a { public $name; public function __costruct($name) {$this->name = $name;}} php> $a = new a('wang'); php> $b = $a; [...]]]></description>
			<content:encoded><![CDATA[<p>Array and Object in PHP are all reference. If you assign a variable with an array or an object, this variable is a reference of that array/object. Using clone you can copy an object.</p>
<pre name="code" class="php">

php> class a { public $name; public function __costruct($name) {$this->name = $name;}}

php> $a  = new a('wang');

php> $b = $a;

php> $b->name = 'ting';

php> var_dump($a);
object(a)#2 (1) {
  ["name"]=>
  string(4) "ting"
}

php> $c = clone $a;

php> var_dump($c);
object(a)#3 (1) {
  ["name"]=>
  string(4) "ting"
}

php> $c->name = 'jjj';

php> var_dump($a);
object(a)#2 (1) {
  ["name"]=>
  string(4) "ting"
}

php> var_dump($c);
object(a)#3 (1) {
  ["name"]=>
  string(3) "jjj"
}

php>
</pre>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/08/16/clone-an-php-object/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/08/16/clone-an-php-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Controller in Ajax Context Testing</title>
		<link>http://www.tiddr.de/blog/2011/08/10/zend-controller-in-ajax-context-testing/</link>
		<comments>http://www.tiddr.de/blog/2011/08/10/zend-controller-in-ajax-context-testing/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 10:41:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=368</guid>
		<description><![CDATA[We can use AjaxContext action helper to define a context of an action. public function init() { $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('get-zip-code', 'json') ->initContext(); } public function getZipCodeAction() { // that is all! you don't need to do any for json encode $this->view->zip = '123'; } Since we use AjaxContext then we don&#8217;t need to create [...]]]></description>
			<content:encoded><![CDATA[<p>We can use <a title="AjaxContext" href="http://framework.zend.com/manual/de/zend.controller.actionhelpers.html" target="_blank">AjaxContext</a> action helper to define a context of an action.</p>
<pre name="code" class="php">
    public function init()
    {
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('get-zip-code', 'json')
                    ->initContext();
    }
    public function getZipCodeAction()
    {
        // that is all! you don't need to do any for json encode
        $this->view->zip = '123';
    }
</pre>
<p>Since we use AjaxContext then we don&#8217;t need to create a get-zip-code.phtml.<br />
Till this step everything is fine.<br />
Then I want to write a unit test for it. </p>
<pre name="code" class="php">
class ZipControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
    public function setUp()
    {
        $this->bootstrap = new Zend_Application(
            APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        parent::setUp();
    }

    /**
     * testICanGetZipCodeAsJsonString
     *
     * @return void
     * @group now
     */
    public function testICanGetHashForCheckingCredit()
    {
        $this->dispatch(
            '/checkout/payone/get-hash-for-checking-credit/format/json');
        $this->assertResponseCode(200);
        $this->assertEquals('{"zip":"123"}', $this->getResponse()->getBody());
    }
}
</pre>
<p>The second assertion fails. And using var_dump($this->getResponse()->getBody()) we can find out the layout is not disable. Why? Doesn&#8217;t AjaxContext work? After a little hacking the  Zend_Controller_Action_Helper_AjaxContext I found the AjaxContext will chech the type of Request. It works just when the Request is a Xml Http Request. </p>
<p>In order let test to work, we have to forge the Request before dispatch it.</p>
<pre name="code" class="php">

    /**
     * testICanGetZipCodeAsJsonString
     *
     * @return void
     * @group now
     */
    public function testICanGetHashForCheckingCredit()
    {
        // forge the request as an XMLHttpRequest!
        $this->getRequest()->setHeaders(array('X_REQUESTED_WITH' => 'XMLHttpRequest'));

        $this->dispatch(
            '/checkout/payone/get-hash-for-checking-credit/format/json');
        $this->assertResponseCode(200);
        $this->assertEquals('{"zip":"123"}', $this->getResponse()->getBody());
    }
</pre>
<p>Now the test working fine.</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/08/10/zend-controller-in-ajax-context-testing/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/08/10/zend-controller-in-ajax-context-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby using gems</title>
		<link>http://www.tiddr.de/blog/2011/07/29/ruby-using-gems/</link>
		<comments>http://www.tiddr.de/blog/2011/07/29/ruby-using-gems/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 09:53:16 +0000</pubDate>
		<dc:creator>tiw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby vagrant]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=355</guid>
		<description><![CDATA[Recently i tried to install vagrant on my ubuntu box and met some problem. I know ruby very little, perhaps someone can explain there problem. After installing vagrant by gem i can not run it directly, this is because vagrant is in /var/lib/gems/1.8/gems/vagrant-0.8.2/bin/vagrant which is not in my PATH. Ok link this file to /usr/bin [...]]]></description>
			<content:encoded><![CDATA[<p>Recently i tried to install vagrant on my ubuntu box and met some problem.<br />
I know ruby very little, perhaps someone can explain there problem.</p>
<p> After installing vagrant by gem i can not run it directly, this is because vagrant is in /var/lib/gems/1.8/gems/vagrant-0.8.2/bin/vagrant which is not in my PATH. Ok link this file to /usr/bin which is in my path.</p>
<p>After that still vagrant can not be run. Error message shows vagrant lib can not be found. It seams that the ruby can not find vagrant. </p>
<p>Add require &#8216;rubygems&#8217; before require &#8216;vagrant&#8217; solves the problem.</p>
<p>These problems just happen in ubuntu, i have installed vagrant per gem on my imac, and there is no problem at all. Is gem for mac and  for linux not the same?</p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/07/29/ruby-using-gems/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/07/29/ruby-using-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>js is weird</title>
		<link>http://www.tiddr.de/blog/2011/06/01/js-is-weird/</link>
		<comments>http://www.tiddr.de/blog/2011/06/01/js-is-weird/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 21:23:51 +0000</pubDate>
		<dc:creator>tiw</dc:creator>
				<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.tiddr.de/blog/?p=352</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tiddr.de/blog/wp-content/uploads/2011/06/js.png"><img src="http://www.tiddr.de/blog/wp-content/uploads/2011/06/js.png" alt="" width="289" height="173" class="alignnone size-full wp-image-353" /></a></p>
<div class="plus-one-wrap"><g:plusone href="http://www.tiddr.de/blog/2011/06/01/js-is-weird/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://www.tiddr.de/blog/2011/06/01/js-is-weird/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

