<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Programming Note</title>
	
	<link>http://programmingnote.com/blog</link>
	<description />
	<lastBuildDate>Tue, 24 Feb 2009 11:49:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ProgrammingNote" /><feedburner:info uri="programmingnote" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>How to Disable WordPress Revisions (No Plugin)</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/ZOpfHfF1EWg/</link>
		<comments>http://programmingnote.com/blog/?p=35#comments</comments>
		<pubDate>Sat, 21 Feb 2009 17:09:24 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/?p=35</guid>
		<description><![CDATA[I am using WordPress 2.7. WordPress has an annoying function: revisions. If you use WordPress 2.6 or above, there may be lots of unuseful revisions in your database. Normally, a post have 5 or more revisions. They make the database larger and larger. Since there are lots of rubbish, the efficiency may become very slow.
Many [...]]]></description>
			<content:encoded><![CDATA[<p>I am using WordPress 2.7. WordPress has an annoying function: revisions. If you use WordPress 2.6 or above, there may be lots of unuseful revisions in your database. Normally, a post have 5 or more revisions. They make the database larger and larger. Since there are lots of rubbish, the efficiency may become very slow.<span id="more-35"></span></p>
<p>Many people want to disable the &#8220;revision&#8221; function, but WordPress doesn&#8217;t provide any option to do it. I see there are some plugins that can turn off the revision function. However, they doesn&#8217;t work well. For example, although you have activated the plugin, when you edit a post, autosave can still produce &#8220;revisions&#8221;. To solve this problem, you can use &#8220;disable autosave&#8221; plugin to turn off autosave. However, I think autosave is a good feature. I want to find a way to solve the problem: disable revisions but not for autosave. Fortunately, WordPress is an open-source application, so I can know the mechanism of it.</p>
<p>By checking the source code, I found that there can&#8217;t be any plugin to satisfy my requirement. So I have to hack WordPress. At last, I found a simple way, only 2 lines need to be changed! Let&#8217;s have a look.</p>
<p>Open wp-includes\default-filters.php and find the line</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'pre_post_update'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_save_post_revision'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It means the function &#8216;wp_save_post_revision&#8217; is hooked &#8216;pre_post&#8217;update&#8217;. i.e. when you update a post, Wordpress will call &#8216;wp_save_post_revision&#8217; function and it will save a revision for the current post. Of cource, the revision isn&#8217;t useful. So I need to <strong>remove or comment</strong> it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// add_action( 'pre_post_update', 'wp_save_post_revision' );</span></pre></div></div>

<p>Now when you update a post, it doesn&#8217;t produce revisions any more. However, when you edit a <strong>published</strong> post in WordPress, the autosave function can still generate a revision draft. It is not what I want, so I must to solve the problem.</p>
<p>Open wp-admin\includes\post.php and found the function wp_create_post_autosave (near line 1030). The last 2 lines should be</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Otherwise create the new autosave as a special post revision</span>
<span style="color: #b1b100;">return</span> _wp_put_post_revision<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Through the comment I see it create a new revision from the $_POST array. I changed it to &#8220;return edit_post();&#8221; and tested in diffent conditions. I found it works well. Now the function wp_create_post_autosave looks like</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> wp_create_post_autosave<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$translated</span> <span style="color: #339933;">=</span> _wp_translate_postdata<span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_wp_error<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$translated</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$translated</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Only store one autosave.  If there is already an autosave, overwrite it.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$old_autosave</span> <span style="color: #339933;">=</span> wp_get_post_autosave<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$new_autosave</span> <span style="color: #339933;">=</span> _wp_post_revision_fields<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$new_autosave</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$old_autosave</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> wp_update_post<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_autosave</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Otherwise create the new autosave as a special post revision</span>
	<span style="color: #666666; font-style: italic;">// return _wp_put_post_revision( $_POST, true );</span>
	<span style="color: #b1b100;">return</span> edit_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>By now, WordPress doesn&#8217;t save the annoying revisions and autosave works well. I think the only disadvantage is that it hacks WordPress core code. Once you upgrade WordPress, you have to change the 2 lines.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/GGeiXEvn5IIrvsT3NJ2urY1nw2k/0/da"><img src="http://feedads.g.doubleclick.net/~a/GGeiXEvn5IIrvsT3NJ2urY1nw2k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/GGeiXEvn5IIrvsT3NJ2urY1nw2k/1/da"><img src="http://feedads.g.doubleclick.net/~a/GGeiXEvn5IIrvsT3NJ2urY1nw2k/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/ZOpfHfF1EWg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=35</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=35</feedburner:origLink></item>
		<item>
		<title>Flickr: Don’t Forget to Set the Image Type</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/79vHPlknB9Q/</link>
		<comments>http://programmingnote.com/blog/?p=34#comments</comments>
		<pubDate>Wed, 31 Dec 2008 12:14:50 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/?p=34</guid>
		<description><![CDATA[I just knew that Flickr doesn&#8217;t like people to upload screenshots or design images. But it allows you to do it. What you need to do is to set the proper content type before uploading.
Above the &#8220;UPLOAD&#8221; button, there is the link &#8220;Show advanced settings&#8230;&#8221;. Click it and you can select the correct type of [...]]]></description>
			<content:encoded><![CDATA[<p>I just knew that Flickr doesn&#8217;t like people to upload screenshots or design images. But it allows you to do it. What you need to do is to set the proper content type before uploading.<span id="more-34"></span></p>
<p>Above the &#8220;UPLOAD&#8221; button, there is the link &#8220;Show advanced settings&#8230;&#8221;. Click it and you can select the correct type of the images.<br />
<a href="http://www.flickr.com/photos/ggggqqqqihc/3152763461/" title="flickr by ggggqqqqihc, on Flickr"><img src="http://farm4.static.flickr.com/3244/3152763461_f263338480_o.png" width="358" height="167" alt="flickr" /></a></p>
<p>Unfortunately I haven&#8217;t found it before. I have uploaded many screenshots (about 40). I have to change the images&#8217; content type one by one. I found how to do it. Its <a href="http://www.flickr.com/help/filters">help</a> says:</p>
<blockquote><p>
You can also change the Content Type after you&#8217;ve uploaded your screenshot, either using the &#8220;Flag your photo&#8221; link under Additional Information on a photo page, or in the Organizr.&#8221;
</p></blockquote>
<p>So, don&#8217;t forget to select the corrent content type before uploading pictures, especially for screenshots.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/TCSOa7PamzA_8QZDiv-oouLyOz8/0/da"><img src="http://feedads.g.doubleclick.net/~a/TCSOa7PamzA_8QZDiv-oouLyOz8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/TCSOa7PamzA_8QZDiv-oouLyOz8/1/da"><img src="http://feedads.g.doubleclick.net/~a/TCSOa7PamzA_8QZDiv-oouLyOz8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/79vHPlknB9Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=34</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=34</feedburner:origLink></item>
		<item>
		<title>Try Again and Again and Again…</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/cTT6QokEVKU/</link>
		<comments>http://programmingnote.com/blog/?p=33#comments</comments>
		<pubDate>Sun, 30 Nov 2008 11:22:54 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/11/try-again-and-again-and-again/</guid>
		<description><![CDATA[God bless all of us&#8230; I can&#8217;t find any words to describe my mood. He is a real hero. Anyone who loves life is a real hero.

]]></description>
			<content:encoded><![CDATA[<p>God bless all of us&#8230; I can&#8217;t find any words to describe my mood. He is a real hero. Anyone who loves life is a real hero.<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Tv1gCa5Us7Q&#038;hl=zh_CN&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Tv1gCa5Us7Q&#038;hl=zh_CN&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>

<p><a href="http://feedads.g.doubleclick.net/~a/5J1VVTUQuR6SzJgpTMM7UD3vQQU/0/da"><img src="http://feedads.g.doubleclick.net/~a/5J1VVTUQuR6SzJgpTMM7UD3vQQU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5J1VVTUQuR6SzJgpTMM7UD3vQQU/1/da"><img src="http://feedads.g.doubleclick.net/~a/5J1VVTUQuR6SzJgpTMM7UD3vQQU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/cTT6QokEVKU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=33</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=33</feedburner:origLink></item>
		<item>
		<title>Old AdSense Code</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/Mcpswwic3xs/</link>
		<comments>http://programmingnote.com/blog/?p=32#comments</comments>
		<pubDate>Sun, 16 Nov 2008 14:50:14 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[AdSense]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/11/old-adsense-code/</guid>
		<description><![CDATA[The old AdSense code is more convenient to change its color and style. However, Google AdSense won&#8217;t provide the old-style code any more. Here are some notes about the old-style AdSense code.
Text Ad:

&#60;script type=&#34;text/javascript&#34;&#62;&#60;!--
google_ad_client = &#34;pub-xxxxxxxxxxxx&#34;;
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = &#34;728x90_as&#34;;
google_ad_type = &#34;text_image&#34;;
google_ad_channel = &#34;&#34;;
google_color_border = &#34;FFFFFF&#34;;
google_color_bg = &#34;FFFFFF&#34;;
google_color_link = &#34;FFFFFF&#34;;
google_color_text = &#34;FFFFFF&#34;;
google_color_url = [...]]]></description>
			<content:encoded><![CDATA[<p>The old AdSense code is more convenient to change its color and style. However, Google AdSense won&#8217;t provide the old-style code any more. Here are some notes about the old-style AdSense code.<span id="more-32"></span></p>
<p><strong>Text Ad</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-xxxxxxxxxxxx&quot;;
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = &quot;728x90_as&quot;;
google_ad_type = &quot;text_image&quot;;
google_ad_channel = &quot;&quot;;
google_color_border = &quot;FFFFFF&quot;;
google_color_bg = &quot;FFFFFF&quot;;
google_color_link = &quot;FFFFFF&quot;;
google_color_text = &quot;FFFFFF&quot;;
google_color_url = &quot;FFFFFF&quot;;
google_ui_features = &quot;rc:0&quot;;
//--&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
  src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</pre></div></div>

<p>&#8220;<strong>google_ad_format</strong>&#8221; indicates the format of the ad. There are 11 options: &#8220;720&#215;90_as&#8221;, &#8220;468&#215;60_as&#8221;, &#8220;234&#215;60_as&#8221;, &#8220;120&#215;600_as&#8221;, &#8220;160&#215;600_as&#8221;, &#8220;120&#215;240_as&#8221;, &#8220;336&#215;280_as&#8221;, &#8220;300&#215;250_as&#8221;, &#8220;250&#215;250_as&#8221;, 180&#215;150_as, 125&#215;125_as.<br />
&#8220;<strong>google_ad_type</strong>&#8221; can be one of the three values: &#8220;text_image&#8221;, &#8220;text&#8221;, &#8220;image&#8221;.<br />
&#8220;<strong>google_ui_features</strong>&#8221; indicates the coner style: &#8220;rc:0&#8243; &#8212; Square, &#8220;rc:6&#8243; &#8212; Slightly rounded, &#8220;rc:10&#8243; &#8212; Very rounded.</p>
<p><strong>Link Unit</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-xxxxxxxxxxxx&quot;;
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = &quot;728x15_0ads_al&quot;;
google_ad_channel =&quot;&quot;;
google_color_border = &quot;FFFFFF&quot;;
google_color_bg = &quot;FFFFFF&quot;;
google_color_link = &quot;FFFFFF&quot;;
//--&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
  src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</pre></div></div>

<p>For link units, there are 6 kinds of ads. &#8220;728&#215;15&#8243;, &#8220;468&#215;15&#8243;, &#8220;200&#215;90&#8243;, &#8220;180&#215;90&#8243;, &#8220;160&#215;90&#8243;, &#8220;120&#215;90&#8243;. &#8220;<strong>google_ad_width</strong>&#8221; and &#8220;<strong>google_ad_height</strong>&#8221; set the size of the link unit. The &#8220;<strong>google_ad_format</strong>&#8221; consists of its &#8220;size&#8221; and a suffix. Some link units have 4 links while other have 5 links. If a link unit has 4 links, the suffix of the &#8220;google_ad_format&#8221; is &#8220;_0ads_al&#8221;, for example, &#8220;728&#215;15_0ads_al&#8221;. For the ones which have 5 links, the suffix is &#8220;_0ads_al_s&#8221;, for example, &#8220;728&#215;15_0ads_al_s&#8221;.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/OEKkxESCrsPXMY3RItbvGYeGBMA/0/da"><img src="http://feedads.g.doubleclick.net/~a/OEKkxESCrsPXMY3RItbvGYeGBMA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OEKkxESCrsPXMY3RItbvGYeGBMA/1/da"><img src="http://feedads.g.doubleclick.net/~a/OEKkxESCrsPXMY3RItbvGYeGBMA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/Mcpswwic3xs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=32</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=32</feedburner:origLink></item>
		<item>
		<title>Anonymous Function in PHP</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/qCEtTZnbciA/</link>
		<comments>http://programmingnote.com/blog/?p=31#comments</comments>
		<pubDate>Sat, 25 Oct 2008 13:16:59 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/10/anonymous-function-in-php/</guid>
		<description><![CDATA[In Lisp or Scheme language, the anonymous function (which is called lambda-style function) is common used. These functions are special because it doesn&#8217;t have a name. So it can be only used once. Usually, these functions are very small and simple.
What these strange functions can be used for? Suppose there is an array that contains [...]]]></description>
			<content:encoded><![CDATA[<p>In Lisp or Scheme language, the anonymous function (which is called lambda-style function) is common used. These functions are special because it doesn&#8217;t have a name. So it can be only used once. Usually, these functions are very small and simple.<span id="more-31"></span></p>
<p>What these strange functions can be used for? Suppose there is an array that contains some integers. For example, $a=array(34,21,58,32,19,6). And we want to use &#8220;array_filter&#8221; function to retrieve the odd integers. The usage of the array_filter is:<br />
array array_filter(array $input [,callback $callback])<br />
The function iterates each element in $input. The $callback is a function which returns true or false. If it returns true, the current element is pushed into the result array. Using array_filter, it is easy to write the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> is_odd<span style="color: #009900;">&#40;</span><span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$n</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">34</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">21</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">58</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">32</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">19</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'is_odd'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Its output is:</p>
<pre>
Array
(
    [1] => 21
    [4] => 19
)
</pre>
<p>Obviously, there is a small function &#8220;is_odd&#8221; to check if an integer is an odd number or not. However, it is used only in array_filter function. So if we can define the small function in array_filter&#8217;s second argument&#8217;s place, it is a better style.</p>
<p>PHP provides &#8220;create_function&#8221; that can create an anonymous function. The usage:<br />
string create_function(string $args, string $code)<br />
Now use this function to rewrite the example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">34</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">21</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">58</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">32</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">19</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$n'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'return ($n%2==1)?true:false;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<p><a href="http://feedads.g.doubleclick.net/~a/cD2OxpzSA7iGZ6geBVF5c6lSoJ4/0/da"><img src="http://feedads.g.doubleclick.net/~a/cD2OxpzSA7iGZ6geBVF5c6lSoJ4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cD2OxpzSA7iGZ6geBVF5c6lSoJ4/1/da"><img src="http://feedads.g.doubleclick.net/~a/cD2OxpzSA7iGZ6geBVF5c6lSoJ4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/qCEtTZnbciA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=31</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=31</feedburner:origLink></item>
		<item>
		<title>Trying reCAPTCHA Plugin</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/xFdf_Djf62Y/</link>
		<comments>http://programmingnote.com/blog/?p=30#comments</comments>
		<pubDate>Sat, 25 Oct 2008 12:34:18 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/10/enabled-recaptcha-plugin/</guid>
		<description><![CDATA[It is very strange that my post Function Overloading in PHP 5 brought many spam comments. I enabled Akismet plugin that has caught about 150 spam comments. However, somtimes Akismet can&#8217;t prevent all the spam comments and it just doesn&#8217;t allow the spam comments to show, the spams are still stored in the database.
Several days [...]]]></description>
			<content:encoded><![CDATA[<p>It is very strange that my post <a href="http://programmingnote.com/blog/?p=21">Function Overloading in PHP 5</a> brought many spam comments. I enabled Akismet plugin that has caught about 150 spam comments. However, somtimes Akismet can&#8217;t prevent all the spam comments and it just doesn&#8217;t allow the spam comments to show, the spams are still stored in the database.</p>
<p>Several days ago I read <a href="http://googlewebmastercentral.blogspot.com/2008/09/keeping-comment-spam-off-your-site-and.html">this article</a> in Google Webmaster Central Blog. It shows some method to avoid comment spam. The first thing is using a captcha. Also, it gives a free script which is called &#8220;<a href="http://recaptcha.net/">reCAPTCHA</a>&#8220;. For WordPress users, reCAPTCHA provides <a href="http://recaptcha.net/plugins/wordpress/">a plugin</a>, so that it is very easy to integrate with WordPress.</p>
<p>I don&#8217;t think the captcha code is a good solution to comment spam. It will make difficult to visitors who want to leave some meaningful comments. However, the comment spam is so serious, I have to do so.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/zBKaau5z4KeKSz8ofy4724F6zQ4/0/da"><img src="http://feedads.g.doubleclick.net/~a/zBKaau5z4KeKSz8ofy4724F6zQ4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zBKaau5z4KeKSz8ofy4724F6zQ4/1/da"><img src="http://feedads.g.doubleclick.net/~a/zBKaau5z4KeKSz8ofy4724F6zQ4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/xFdf_Djf62Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=30</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=30</feedburner:origLink></item>
		<item>
		<title>What is JAVA_HOME in Ubuntu?</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/GCjcLjkNhME/</link>
		<comments>http://programmingnote.com/blog/?p=29#comments</comments>
		<pubDate>Tue, 21 Oct 2008 00:05:44 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/10/what-is-java_home-in-ubuntu/</guid>
		<description><![CDATA[Some Java programs need the environment variable JAVA_HOME, such as Tomcat. In Windows operating system, JAVA_HOME is the directory that the JDK is located. However, in Ubuntu if you install JDK with &#8220;sudo apt-get install sun-java6-jdk&#8221;, the JDK&#8217;s files are extracted to many directories like /usr/bin, /usr/lib, etc. What is JAVA_HOME?
Some people thought it should [...]]]></description>
			<content:encoded><![CDATA[<p>Some Java programs need the environment variable JAVA_HOME, such as Tomcat. In Windows operating system, JAVA_HOME is the directory that the JDK is located. However, in Ubuntu if you install JDK with &#8220;sudo apt-get install sun-java6-jdk&#8221;, the JDK&#8217;s files are extracted to many directories like /usr/bin, /usr/lib, etc. What is JAVA_HOME?</p>
<p>Some people thought it should be /usr because in Windows the Java compiler &#8220;javac&#8221; is in JAVA_HOMEbinjavac. So in Linux it should be JAVA_HOMEbinjavac and JAVA_HOME=/usr. I don&#8217;t think it is the best sulotion. Because I found /usr/bin/javac is not the real Java compiler, it is just a link. I used &#8220;ls -l /usr/bin/javac&#8221; to see what it links to:</p>
<blockquote><p>
/usr/bin/javac -> /etc/alternatives/javac
</p></blockquote>
<p>And /etc/alternatives/javac is also a link. It links to /usr/lib/jvm/java-6-sun/bin/javac. This is the real Java compiler. And the path is similar to that in Windows. So I think JAVA_HOME should be /usr/lib/jvm/java-6-sun in Ubuntu Linux.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/qq_G2aDm5n1qLsr0QZaVWbLeQFg/0/da"><img src="http://feedads.g.doubleclick.net/~a/qq_G2aDm5n1qLsr0QZaVWbLeQFg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qq_G2aDm5n1qLsr0QZaVWbLeQFg/1/da"><img src="http://feedads.g.doubleclick.net/~a/qq_G2aDm5n1qLsr0QZaVWbLeQFg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/GCjcLjkNhME" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=29</feedburner:origLink></item>
		<item>
		<title>The Keyboard doesn’t Work in Virtualbox on Ubuntu 8.04.1</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/X1XGZhoSFIQ/</link>
		<comments>http://programmingnote.com/blog/?p=28#comments</comments>
		<pubDate>Sun, 19 Oct 2008 10:47:30 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/10/the-keyboard-doesnt-work-in-virtualbox-on-ubuntu-8041/</guid>
		<description><![CDATA[I installed Ubuntu Linux 8.04.1 yesterday and removed Windows. But sometimes I need to use Windows, so I have to install VirtualBox.
I used &#8220;sudo apt-get install virtualbox-ose virtualbox-ose-modules-generic&#8221; to install VirtualBox. Its version is 1.5.6. However, I found a serious problem. My keyboard doesn&#8217;t work in VirtualBox. If a virtual machine is running and I [...]]]></description>
			<content:encoded><![CDATA[<p>I installed Ubuntu Linux 8.04.1 yesterday and removed Windows. But sometimes I need to use Windows, so I have to install VirtualBox.</p>
<p>I used &#8220;sudo apt-get install virtualbox-ose virtualbox-ose-modules-generic&#8221; to install VirtualBox. Its version is 1.5.6. However, I found a serious problem. My keyboard doesn&#8217;t work in VirtualBox. If a virtual machine is running and I click the window, the mouse is captured by the virtual machine. When I press the right Ctrl key the mouse should be released. However, it doesn&#8217;t work. I have to press Ctrl+Alt+Backspace to restart X. Some people said that the problem can be solved by disabling support to complex characters. But I need the multi-language support so that this method is unuseful for me.</p>
<p>Finally I found a good solution. I used &#8220;sudo apt-get install scim-bridge-client-qt&#8221; to install the scim-bridge-client-qt package and reboot my computer. Then the keyboard can work in VirtualBox. Although the solution is very simple, I don&#8217;t know why. It may be a bug in Ubuntu 8.04.1.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/klGOxuSmm-7lfw5iCoPlgnFAu3Y/0/da"><img src="http://feedads.g.doubleclick.net/~a/klGOxuSmm-7lfw5iCoPlgnFAu3Y/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/klGOxuSmm-7lfw5iCoPlgnFAu3Y/1/da"><img src="http://feedads.g.doubleclick.net/~a/klGOxuSmm-7lfw5iCoPlgnFAu3Y/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/X1XGZhoSFIQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=28</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=28</feedburner:origLink></item>
		<item>
		<title>Sending AJAX Requests with Prototype</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/cMH73zsnG60/</link>
		<comments>http://programmingnote.com/blog/?p=27#comments</comments>
		<pubDate>Sat, 11 Oct 2008 12:50:53 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/?p=27</guid>
		<description><![CDATA[Several days ago I tried to learn a little about Javascript language and AJAX. Implementing AJAX with pure Javascript is not an easy work. It is not cross-browser so that I have to detect which browser sent the AJAX request. I think some frameworks can solve the problem in a better way and finally I [...]]]></description>
			<content:encoded><![CDATA[<p>Several days ago I tried to learn a little about Javascript language and AJAX. Implementing AJAX with pure Javascript is not an easy work. It is not cross-browser so that I have to detect which browser sent the AJAX request. I think some frameworks can solve the problem in a better way and finally I found a Javascript framework &#8212; Prototype.<span id="more-27"></span></p>
<p>I made a month-day selector using two drop lists. After you select a month, the number of the day drop list may change. For example, at first January is selected and the numbers of the day drop list are from 1 to 31. After you select April, the numbers of the day drop list becomes from 1 to 30. It is very easy to understand. I created two files, demo.html for showing page and response.php for calculate how many days a month has.</p>
<p>demo.html:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;script/prototype-1.6.0.3.js&quot;&gt;&lt;/script&gt;
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">function</span> send<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> length<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</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>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Request</span><span style="color: #009900;">&#40;</span>
			<span style="color: #3366CC;">'./response.php'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
				method<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;get&quot;</span><span style="color: #339933;">,</span>
				parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>month<span style="color: #339933;">:</span> value<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
				onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> days<span style="color: #339933;">=</span>response.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>days<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</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: #339933;">,</span>
				onFailure<span style="color: #339933;">:</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Failed!'</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>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><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>i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">12</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;month&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</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;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">31</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;/head&gt;
&lt;body onload=&quot;init();&quot;&gt;
&lt;p&gt;
	Month: &lt;select id=&quot;month&quot; onChange=&quot;send(this.value);&quot;&gt;&lt;/select&gt;
	Day: &lt;select id=&quot;day&quot;&gt;&lt;/select&gt;
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>response.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$d</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'month'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$days</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">29</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">31</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$days</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$d</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Sending an AJAX request with Prototype is using Ajax.Request. The code below is important:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Request</span><span style="color: #009900;">&#40;</span>
	<span style="color: #3366CC;">'./response.php'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
		method<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;get&quot;</span><span style="color: #339933;">,</span>
		parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>month<span style="color: #339933;">:</span> value<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> days<span style="color: #339933;">=</span>response.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>days<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;day&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</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: #339933;">,</span>
		onFailure<span style="color: #339933;">:</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Failed!'</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></pre></div></div>

<p>The Ajax.Request contructor needs two arguments. The first is the target file and the second is an Ajax.Options object. The second parameter in this example is expressed as a JSON string. &#8220;method&#8221; indicates using &#8220;get&#8221; or &#8220;post&#8221; method. &#8220;onSuccess&#8221; and &#8220;onFailure&#8221; indicate the callback functions. With Prototype framework&#8217;s help, sending AJAX requests is very easy and intuitive.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/rd8Ni1ucvEhik4ol3xmXuv9l5aI/0/da"><img src="http://feedads.g.doubleclick.net/~a/rd8Ni1ucvEhik4ol3xmXuv9l5aI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rd8Ni1ucvEhik4ol3xmXuv9l5aI/1/da"><img src="http://feedads.g.doubleclick.net/~a/rd8Ni1ucvEhik4ol3xmXuv9l5aI/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/cMH73zsnG60" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=27</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=27</feedburner:origLink></item>
		<item>
		<title>Working with an Old Computer</title>
		<link>http://feedproxy.google.com/~r/ProgrammingNote/~3/gnARBKM5sFw/</link>
		<comments>http://programmingnote.com/blog/?p=26#comments</comments>
		<pubDate>Wed, 08 Oct 2008 12:57:08 +0000</pubDate>
		<dc:creator>Wang Jinbo</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://programmingnote.com/blog/2008/10/working-with-an-old-computer/</guid>
		<description><![CDATA[Last month my friend and I exchanged our computers. Unfortunately, her computer&#8217;s memory is 256MB, only a half of mine. The operating system is Windows XP but mine is Ubuntu Linux. I like writing some programmes for fun but with a low memory I can not install some softwares. Eclipse, NetBeans, Visual Studio (Express Edition) [...]]]></description>
			<content:encoded><![CDATA[<p>Last month my friend and I exchanged our computers. Unfortunately, her computer&#8217;s memory is 256MB, only a half of mine. The operating system is Windows XP but mine is Ubuntu Linux. I like writing some programmes for fun but with a low memory I can not install some softwares. Eclipse, NetBeans, Visual Studio (Express Edition) are not fit for me any more. So I have to learn to use some lightweight softwares.<span id="more-26"></span></p>
<p>Developing with IDE seems impossible. I have to find a powerful text editor. Now I find Notepad++ and Vim for Windows are very excellent. Although many people said that Emacs is the most powerful text editor, however, I think it is very hard to use. Sometimes I need to write Java code. So I have to learn how to use &#8220;ant&#8221;, an automatically build utility. In fact, using &#8220;ant&#8221; instead of some IDEs, such as Eclipse or NetBeans, is not very difficult. For C or C++ programming, I installed Cygwin on her computer. Although Cygwin is not only a C/C++ compilers, it seems a Unix shell running on Windows. Since I have been using Ubuntu Linux for about half a year, I like working on Linux and are farmiliar with it.</p>
<p>For most of my tasks, a good text editor is enough. For Notepad++ and Vim, I prefer Notepad++. It runs faster and much easier to learn.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ySAzFhmZ7dePzhmGiFbbqP9ISfA/0/da"><img src="http://feedads.g.doubleclick.net/~a/ySAzFhmZ7dePzhmGiFbbqP9ISfA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ySAzFhmZ7dePzhmGiFbbqP9ISfA/1/da"><img src="http://feedads.g.doubleclick.net/~a/ySAzFhmZ7dePzhmGiFbbqP9ISfA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/ProgrammingNote/~4/gnARBKM5sFw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://programmingnote.com/blog/?feed=rss2&amp;p=26</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://programmingnote.com/blog/?p=26</feedburner:origLink></item>
	</channel>
</rss>
