<?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"
	>

<channel>
	<title>Fly together Forever</title>
	<atom:link href="http://www.liucougar.net/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.liucougar.net/blog</link>
	<description></description>
	<pubDate>Fri, 22 Feb 2008 18:10:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6-bleeding</generator>
	<language>en</language>
			<item>
		<title>share dojo among iframes</title>
		<link>http://www.liucougar.net/blog/archives/88</link>
		<comments>http://www.liucougar.net/blog/archives/88#comments</comments>
		<pubDate>Fri, 22 Feb 2008 18:07:33 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/88</guid>
		<description><![CDATA[
As pointed out by   
Jon&#8217;s blog post, simply use the dojo/dijit objects on the top window within an iframe won&#8217;t work for dojo APIs in most cases, because &#8220;the top level dojo object has no Out of the Box knowledge of the iframes or their content&#8221;.
Actually, dojo has two APIs in the core [...]]]></description>
			<content:encoded><![CDATA[
<p>As pointed out by   
<a href="http://jpsykes.com/126/dojo-and-iframes-tip">Jon&#8217;s blog post</a>, simply use the dojo/dijit objects on the top window within an iframe won&#8217;t work for dojo APIs in most cases, because &#8220;the top level dojo object has no Out of the Box knowledge of the iframes or their content&#8221;.</p>
<p>Actually, dojo has two APIs in the core to support running code in the context of an iframe:  dojo.withGlobal and dojo.withDoc. However, they do not have much attention, as most of their usage is only seen in the dijit.Editor code. Actually, they were introduced for the sole purpose of dojo.widget.Editor (which is the dojo 0.4 Editor widget) for dojo 0.4 in the first place.</p>
<p>Both of them have identical signature:</p>
<pre>dojo.withGlobal(/*Object*/globalObject, /*Function*/callback,/*Object?*/thisObject, /*Array?*/cbArguments)</pre>
<p>In order to use them, you can wrap your code in a function first, like this:</p>
<pre>function iframefunc(){
    dojo.byId(‘foo’);
    dijit.byId(‘foo’);
    dojo.query(‘a.foo’);
}</pre>
<p>and call the function as this in an iframe:</p>
<pre>dojo.withGlobal(window,iframefunc)</pre>
<p>You can also call dojo APIs directly use dojo.withGlobal. Say you want to run dojo.byId(‘foo’) in an iframe, you can do:</p>
<pre>dojo.withGlobal(window,'byId',dojo,['foo'])</pre>
<p>Note that, the above code can also run correctly in the context of the top window.</p>
<p>The differences between dojo.withGlobal and dojo.withDoc is the first argument: if you want to only change document of a function call operates on, you can use dojo.withDoc instead and pass it with the document of an iframe.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/88/feed</wfw:commentRss>
		</item>
		<item>
		<title>dojo.{declare,extend} support for Komodo</title>
		<link>http://www.liucougar.net/blog/archives/85</link>
		<comments>http://www.liucougar.net/blog/archives/85#comments</comments>
		<pubDate>Thu, 21 Feb 2008 17:06:02 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/85</guid>
		<description><![CDATA[
As an open source editor,      
komodo editor is targeted at dynamic programming language editing, which supports javascript, php, python and perl,      
among others.
One of the features for those supported  dynamic languages is auto-generation of a list of available functions defined in a script. However, [...]]]></description>
			<content:encoded><![CDATA[
<p>As an open source editor,      
<a href="http://www.openkomodo.com/">komodo editor</a> is targeted at dynamic programming language editing, which supports javascript, php, python and perl,      
<a href="http://www.activestate.com/Products/komodo_edit/features.plex">among others</a>.</p>
<p>One of the features for those supported  dynamic languages is auto-generation of a list of available functions defined in a script. However, when editing dojo based javascript files, komodo can not pick up any classes declared using      
<a href="http://www.dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/object-orientation/declaring-class">dojo.declare</a> and it does not support dojo.extend either.</p><span id="more-85"></span>
<p>As it is open source, so I can have a look at the code briefly to find out where that is handled. It turns out to be a python script (to be pricise, it is KOMODO_INSTALL_DIR\lib\mozilla\python\komodo\codeintel2\lang_javascript.py). There are some YUI special handling in it to support yahoo.extend and yahoo.lang.extend. After some trail and failure, I managed to change that to support dojo.declare and dojo.extend pretty well.</p>
<p>For those impatient, you can download the     
<a href="content:2008/02/lang_javascript.py" title="dojo.{declare,extend} support for Komodo">modified lang_javascript.py</a> and replace the file in your installation (this is for komodo editor 4.2.x or IDE 4.2.x, not sure whether it works for previous versions of komodo). After restarting your komodo, classes declared using dojo.declare should be recognized and shown in the object browser tab. Autocompletion should also work for these classes, as well as additions to a function inplanted using dojo.extend.</p>
<p>Although komodo has a plugin framework just as firefox, I can see no way to add logics to the functions defined in the file lang_javascript.py. If anyone knows how, I may try to convert this to a plugin of komodo. The modification is also available in     
<a href="content:2008/02/lang_javascript.patch" title="patch for komodo lang_javascript.py">diff format</a>.</p>
<p>If you want to add dojo API support to komodo, try the      
<a href="http://community.activestate.com/komodo-extension/dojo-api-catalog-collection">dojo extension</a>.</p>
<p>As a side note: the modified lang_javascript.py does not keep the original YUI support any more.</p>
<p>
<strong>Edit on 22/2/2008</strong>:  a cleaner patch is 
<a href="http://bugs.activestate.com/show_bug.cgi?id=75069">submitted</a> to komodo bugzilla. It is cleaner than the patch linked here and fixes several issues. However, that is against the latest revision of that file, rather than the one shipped with komodo editor/IDE 4.2.x.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/85/feed</wfw:commentRss>
		</item>
		<item>
		<title>Our first child is arrived</title>
		<link>http://www.liucougar.net/blog/archives/84</link>
		<comments>http://www.liucougar.net/blog/archives/84#comments</comments>
		<pubDate>Wed, 06 Feb 2008 22:38:08 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/84</guid>
		<description><![CDATA[
Our first child, a little boy, nick named haohao (full name still needs to be decided) was just borned naturally today in York Hospital at 15:13 London time (which is 23:13, 6/Feb/2008, Beijing time). As 6/Feb/2008 is the chinese new year eve, so haohao is still born in the year of 
pig, rater than the [...]]]></description>
			<content:encoded><![CDATA[
<p>Our first child, a little boy, nick named haohao (full name still needs to be decided) was just borned naturally today in York Hospital at 15:13 London time (which is 23:13, 6/Feb/2008, Beijing time). As 6/Feb/2008 is the chinese new year eve, so haohao is still born in the year of 
<a href="http://en.wikipedia.org/wiki/Pig_%28zodiac%29">pig</a>, rater than the year of 
<a href="http://en.wikipedia.org/wiki/Rat_%28zodiac%29">rat</a>.</p>
<p>I will upload pictures of our little baby to the online gallery soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/84/feed</wfw:commentRss>
		</item>
		<item>
		<title>latest rsync incompatible with EC2 kernel</title>
		<link>http://www.liucougar.net/blog/archives/83</link>
		<comments>http://www.liucougar.net/blog/archives/83#comments</comments>
		<pubDate>Thu, 24 Jan 2008 22:26:25 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/83</guid>
		<description><![CDATA[
I just noticed that re-bundling in EC2 instance is not working. Google told me that it is due to the  
incompatibility between latest rsync and relatively old kernel used by EC2 (2.6.16).
In the  
thread about this issue, 5 possible workarounds are presented. However, none of them are easy under gentoo without messing up [...]]]></description>
			<content:encoded><![CDATA[
<p>I just noticed that re-bundling in EC2 instance is not working. Google told me that it is due to the  
<a href="http://developer.amazonwebservices.com/connect/thread.jspa?messageID=75989">incompatibility</a> between latest rsync and relatively old kernel used by EC2 (2.6.16).</p>
<p>In the  
<a href="http://developer.amazonwebservices.com/connect/thread.jspa?messageID=75989">thread</a> about this issue, 5 possible workarounds are presented. However, none of them are easy under gentoo without messing up with ebuild/emerge. I found another way, and you don&#8217;t need to regenerate the configure file for rsync at all, all you need is to comment the following line in the config.h file (which is generated after you run the configure script):</p>
<p>#define HAVE_LUTIMES 1</p>
<p>then make and make install, all should be fine now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/83/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic dns setup for gentoo EC2 AMI</title>
		<link>http://www.liucougar.net/blog/archives/80</link>
		<comments>http://www.liucougar.net/blog/archives/80#comments</comments>
		<pubDate>Sat, 22 Dec 2007 23:23:49 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/80</guid>
		<description><![CDATA[
If you are using a dns service provider with dynamic dns support, and using a gentoo based EC2 AMI, then you may find 
this script to be useful. It can update the IP address for a specified domain name whenver the gentoo AMI is booted.
To use this script, just extract the file, and place ec2.conf [...]]]></description>
			<content:encoded><![CDATA[
<p>If you are using a dns service provider with dynamic dns support, and using a gentoo based EC2 AMI, then you may find 
<a href="content:2007/12/dyndnsec2tar.bz2">this script</a> to be useful. It can update the IP address for a specified domain name whenver the gentoo AMI is booted.</p>
<p>To use this script, just extract the file, and place ec2.conf under /etc/conf.d and rename it as ec2, then move file ec2  to /etc/init.d</p>
<p>Before you can use it, you have to set some parameters in file /etc/conf.d/ec2, please consult the comments in that file.</p>
<p>In order to register IP address whenever the AMI is getting booted, a final step is needed:</p>
<pre>rc-update add ec2 default</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/80/feed</wfw:commentRss>
		</item>
		<item>
		<title>text.rb:292:in `normalize&#8217;: private method `gsub&#8217; called for 35:Fixnum (NoMethodError)</title>
		<link>http://www.liucougar.net/blog/archives/78</link>
		<comments>http://www.liucougar.net/blog/archives/78#comments</comments>
		<pubDate>Wed, 21 Nov 2007 15:12:36 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/78</guid>
		<description><![CDATA[
Just before generating the manifest file, ec2-bundle-vol under gentoo, throws this error at me:
Googling around, it turns out that, it&#8217;s due to my &#8220;too recent&#8221; version of ruby (I only use stable packages in gentoo, but we all know gentoo is always cutting edge, even its stable branch, isn&#8217;t it?), which has a backward incompability. [...]]]></description>
			<content:encoded><![CDATA[
<p>Just before generating the manifest file, ec2-bundle-vol under gentoo, throws this error at me:</p>
<p>Googling around, it turns out that, it&#8217;s due to my &#8220;too recent&#8221; version of ruby (I only use stable packages in gentoo, but we all know gentoo is always cutting edge, even its stable branch, isn&#8217;t it?), which has a backward incompability. The fix is  
<a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/c2e2f3b9a6ffac50">trivial</a>:</p>
<p> 
<font class="fixed_width" face="Courier, Monospaced">&#8212; rexml/text.rb.orig  2007-10-22 08:00:04.000000000 +0100
<br />
+++ rexml/text.rb       2007-10-22 08:00:33.000000000 +0100
<br />
@@ -286,7 +286,7 @@
<br />
EREFERENCE = /&amp;(?!#{Entity::NAME};)/
<br />
# Escapes all possible entities
<br />
def Text::normalize( input, doctype=nil, entity_filter=nil )
<br />
-      copy = input
<br />
+      copy = input.to_s
<br />
# Doing it like this rather than in a loop improves the speed
<br />
#copy = copy.gsub( EREFERENCE, &#8216;&amp;&#8217; )
<br />
copy = copy.gsub( &#8220;&amp;&#8221;, &#8220;&amp;&#8221; )
<br />
</font>
</p>
<font class="fixed_width" face="Courier, Monospaced">&#8212; rexml/document.rb.orig      2007-10-22 08:02:36.000000000 +0100
<br />
+++ rexml/document.rb   2007-10-22 08:03:01.000000000 +0100
<br />
@@ -183,7 +183,7 @@
<br />
output = Output.new( output, xml_decl.encoding )
<br />
end
<br />
formatter = if indent &gt; -1
<br />
-          if transitive
<br />
+          if trans
<br />
REXML::Formatters::Transitive.new( indent, ie_hack )
<br />
else
<br />
REXML::Formatters::Pretty.new( indent, ie_hack ) </font>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/78/feed</wfw:commentRss>
		</item>
		<item>
		<title>Install Amazon EC2 AMI Tools in gentoo host</title>
		<link>http://www.liucougar.net/blog/archives/77</link>
		<comments>http://www.liucougar.net/blog/archives/77#comments</comments>
		<pubDate>Wed, 21 Nov 2007 13:39:10 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/77</guid>
		<description><![CDATA[
  
Amazon EC2 AIM tools are necessary if you want to create your own images (by either doing it from scratch or modifying others AIM) to use on   
Amazon EC2 service. That tool is only supporting linux, so they provide a RPM (maybe primarily targeted for FC?).
If you are a gentooer, then [...]]]></description>
			<content:encoded><![CDATA[
<p>  
<a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368&amp;categoryID=88">Amazon EC2 AIM tools</a> are necessary if you want to create your own images (by either doing it from scratch or modifying others AIM) to use on   
<a href="http://www.amazon.com/ec2">Amazon EC2</a> service. That tool is only supporting linux, so they provide a RPM (maybe primarily targeted for FC?).</p>
<p>If you are a gentooer, then you have to do it manually. The following is what I have done to make it work</p>
<pre>rpm2targz ec2-ami-tools.noarch.rpm #if you don't have rpm2targz, run emerge rpm2targz first
tar xvfz ec2-ami-tools.noarch.tar.gz
mv usr/local/* /usr/local/
mv usr/lib/site_ruby/ /usr/lib/
mv etc/aes/ /etc/
ln -s /usr/lib/site_ruby/aes /usr/lib/ruby/site_ruby/1.8/i686-linux/aes</pre>
<p>After that, you should be able to run ec2-bundle-vol and others just fine.</p>
<p>Another tip: I have this in my ~/.bash_profile (~/.bashrc will do too):</p>
<pre>#for Amazon EC2 AMI bundle
EC2_BUNDLE="-k /path/to/your/pk/pem -c /path/to/your/cert/.pem -u &lt;user_id&gt;"
alias ec2-bundle-vol="ec2-bundle-vol $EC2_BUNDLE"
alias ec2-bundle-image="ec2-bundle-image $EC2_BUNDLE"</pre>
<p>So that you don&#8217;t need to specify all those mandatory options every time you invoke these commands.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/77/feed</wfw:commentRss>
		</item>
		<item>
		<title>Fast Repeating of String using Exponential Concatenation</title>
		<link>http://www.liucougar.net/blog/archives/76</link>
		<comments>http://www.liucougar.net/blog/archives/76#comments</comments>
		<pubDate>Sun, 18 Nov 2007 19:28:36 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[dojo]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/76</guid>
		<description><![CDATA[
Today saw a post from Steve on his     
blog about &#8221;    
Fast String Multiplication with Regular Expressions, Exponential Concatenation, and Binary Interpolation&#8220;. Basically, it deals with how to fast multiplicate a string     
n times in javascript.
When I first saw the post, only 3 algorithms [...]]]></description>
			<content:encoded><![CDATA[
<p>Today saw a post from Steve on his     
<a href="http://blog.stevenlevithan.com/" target="_blank">blog</a> about &#8221;    
<a href="http://blog.stevenlevithan.com/archives/fast-string-multiply" target="_blank">Fast String Multiplication with Regular Expressions, Exponential Concatenation, and Binary Interpolation</a>&#8220;. Basically, it deals with how to fast multiplicate a string     
<em>n</em> times in javascript.</p>
<p>When I first saw the post, only 3 algorithms were presented. Looking at the 3rd algorithm, I think it can receive some improvement if exponential concatenation is used more efficiently. By the time I implement the improved version, Steve added a 4th one to his post, which is quite similar to what I have here:</p>
<pre class="code">function mul5(str, n) {
 	var r=[];
 	while(n){
 		if(n%2)
 			r.push(str);
 		str+=str;
 		n &gt;&gt;=1;
 	}
 	return r.join(&#8221;);
}</pre>
<p>The main difference is that it is more compact. My tests show that, in Firefox and Safari 3.0.4, mul5 is as fast as mul4. However, similar to mul4, mul5 is about 30% slower than mul3 in IE (mult5 performs as good as mul4 in IE).</p>
<p>The reason of slowdown in IE compared to mul3  is this part: str+=str. IE does not handle that direct string concatenation well if the string is quite long.  What if we use array.push there as well? After several fail-and-error, I found out one solution which will actually boost the performance for IE:
<br />
</p>
<pre class="code">function mul5(str, n) {
 	var r=[],t=[str];
 	while(n){
 		if(n%2)
 			r.push.apply(r,t);
 		t.push.apply(t,t);
 		n &gt;&gt;=1;
 	}
 	return r.join(&#8221;);
}</pre>
<p>As shown above, the trick is to use array.push.apply(array,anotherArray) to add all elements in anotherArray to array. This IE version is as good as mul3, or even slightly faster than it.</p>
<p>However, this modification will slow down other browsers. We can use conditional compilation support in IE to work around this. The merged version is like this:</p>
<pre class="code">function mul5(str, n) {
	var r=[];
	/*@cc_on //for IE
	var t=[str];
	while(n){
		if(n%2)
			r.push.apply(r,t);
		t.push.apply(t,t);
		n &gt;&gt;=1;
	}
	return r.join(&#8221;);
	@*/
	while(n){
		if(n%2)
			r.push(str);
		str+=str;
		n &gt;&gt;=1;
	}
	return r.join(&#8221;);
}</pre>
<p>If using dojo, the conditional compilation should be changed to just test dojo.isIE. (conditional compilation is not supported by dojo builder, so it will be lost when building dojo)</p>
<p>Try it yourself  
<a href="content:/repeat.html">here</a>. Changes compared to the original one:</p>
<ol>
<li>mul1 and mul2 are slow, so removed from the test</li>
<li>the number of repetition and the length of the input str are slightly different from the original one</li>
<li>A table is used to present the result, rather than a list</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/76/feed</wfw:commentRss>
		</item>
		<item>
		<title>Passed PhD viva</title>
		<link>http://www.liucougar.net/blog/archives/75</link>
		<comments>http://www.liucougar.net/blog/archives/75#comments</comments>
		<pubDate>Fri, 16 Nov 2007 16:55:16 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/75</guid>
		<description><![CDATA[
After 4 years of PhD study, finally I passed my viva (or defence in US) on Wednesday 14, Nov, 2007.
Thanks first go to my family, including my parents, who  made my PhD study possible finacially and they are always ready to encourage me whenever I am struggling with whatever issues. My wife, (was my girlfriend) [...]]]></description>
			<content:encoded><![CDATA[
<p>After 4 years of PhD study, finally I passed my viva (or defence in US) on Wednesday 14, Nov, 2007.</p>
<p>Thanks first go to my family, including my parents, who  made my PhD study possible finacially and they are always ready to encourage me whenever I am struggling with whatever issues. My wife, (was my girlfriend) , also support me throughout my PhD study.</p>
<p>This research was made possible under the excellent supervision of 
<a href="http://www.elec.york.ac.uk/staff/academic/amt.html" target="_blank">Prof. Andy Tyrrell</a> and 
<a href="http://www.elec.york.ac.uk/staff/academic/jfm.html" target="_blank">Dr. Julian Miller</a>. I would like to thank them for their continuous support and guidance of the project as well as their suggestions and direction. In addition, I highly appreciate the efforts they exerted to find financial support for my further research.</p>
<p>Credits should also go to my friends, labmates, thanks for the assistance and suggestions, as well as the laughs and times shared with me.</p>
<p>I think this should be the last degree in my life, or anyone know is there a higher degree to pursue? (I know postdoctor is not considered as a degree, but rather a job) Although, even if there is a higher one, I doubt whether I am willing to consider it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/75/feed</wfw:commentRss>
		</item>
		<item>
		<title>Wedding photos are uploaded to Gallery</title>
		<link>http://www.liucougar.net/blog/archives/73</link>
		<comments>http://www.liucougar.net/blog/archives/73#comments</comments>
		<pubDate>Tue, 28 Aug 2007 14:45:06 +0000</pubDate>
		<dc:creator>liucougar</dc:creator>
		
		<category><![CDATA[Life]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.liucougar.net/blog/archives/73</guid>
		<description><![CDATA[I got married several months ago, but did not have time to put up all the photos to share with my families and friends all over the world.
Just installed   
Gallery 2 and   
WPG2 for Wordpress and all   
wedding photos are all uploaded. However, you do need a login/password to [...]]]></description>
			<content:encoded><![CDATA[I got married several months ago, but did not have time to put up all the photos to share with my families and friends all over the world.
<p>Just installed   
<a href="http://gallery.menalto.com/">Gallery 2</a> and   
<a href="http://wpg2.galleryembedded.com/">WPG2</a> for Wordpress and all   
<a href="http://www.liucougar.net/gallery/v/7/">wedding photos</a> are all uploaded. However, you do need a login/password to access them. If you know me personally, please ask me for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liucougar.net/blog/archives/73/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
