As pointed out by Jon’s blog post, simply use the dojo/dijit objects on the top window within an iframe won’t work for dojo APIs in most cases, because “the top level dojo object has no Out of the Box knowledge of the iframes or their content”.

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.

Both of them have identical signature:

dojo.withGlobal(/*Object*/globalObject, /*Function*/callback,/*Object?*/thisObject, /*Array?*/cbArguments)

In order to use them, you can wrap your code in a function first, like this:

function iframefunc(){
    dojo.byId(‘foo’);
    dijit.byId(‘foo’);
    dojo.query(‘a.foo’);
}

and call the function as this in an iframe:

dojo.withGlobal(window,iframefunc)

You can also call dojo APIs directly use dojo.withGlobal. Say you want to run dojo.byId(‘foo’) in an iframe, you can do:

dojo.withGlobal(window,'byId',dojo,['foo'])

Note that, the above code can also run correctly in the context of the top window.

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.

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, when editing dojo based javascript files, komodo can not pick up any classes declared using dojo.declare and it does not support dojo.extend either.

(more…)

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 year of rat.

I will upload pictures of our little baby to the online gallery soon.

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 with ebuild/emerge. I found another way, and you don’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):

#define HAVE_LUTIMES 1

then make and make install, all should be fine now.

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 under /etc/conf.d and rename it as ec2, then move file ec2 to /etc/init.d

Before you can use it, you have to set some parameters in file /etc/conf.d/ec2, please consult the comments in that file.

In order to register IP address whenever the AMI is getting booted, a final step is needed:

rc-update add ec2 default

Just before generating the manifest file, ec2-bundle-vol under gentoo, throws this error at me:

Googling around, it turns out that, it’s due to my “too recent” version of ruby (I only use stable packages in gentoo, but we all know gentoo is always cutting edge, even its stable branch, isn’t it?), which has a backward incompability. The fix is trivial:

— rexml/text.rb.orig 2007-10-22 08:00:04.000000000 +0100
+++ rexml/text.rb 2007-10-22 08:00:33.000000000 +0100
@@ -286,7 +286,7 @@
EREFERENCE = /&(?!#{Entity::NAME};)/
# Escapes all possible entities
def Text::normalize( input, doctype=nil, entity_filter=nil )
- copy = input
+ copy = input.to_s
# Doing it like this rather than in a loop improves the speed
#copy = copy.gsub( EREFERENCE, ‘&’ )
copy = copy.gsub( “&”, “&” )

— rexml/document.rb.orig 2007-10-22 08:02:36.000000000 +0100
+++ rexml/document.rb 2007-10-22 08:03:01.000000000 +0100
@@ -183,7 +183,7 @@
output = Output.new( output, xml_decl.encoding )
end
formatter = if indent > -1
- if transitive
+ if trans
REXML::Formatters::Transitive.new( indent, ie_hack )
else
REXML::Formatters::Pretty.new( indent, ie_hack )

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 you have to do it manually. The following is what I have done to make it work

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

After that, you should be able to run ec2-bundle-vol and others just fine.

Another tip: I have this in my ~/.bash_profile (~/.bashrc will do too):

#for Amazon EC2 AMI bundle
EC2_BUNDLE="-k /path/to/your/pk/pem -c /path/to/your/cert/.pem -u <user_id>"
alias ec2-bundle-vol="ec2-bundle-vol $EC2_BUNDLE"
alias ec2-bundle-image="ec2-bundle-image $EC2_BUNDLE"

So that you don’t need to specify all those mandatory options every time you invoke these commands.

Today saw a post from Steve on his blog about ” Fast String Multiplication with Regular Expressions, Exponential Concatenation, and Binary Interpolation“. Basically, it deals with how to fast multiplicate a string n times in javascript.

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:

function mul5(str, n) {
 	var r=[];
 	while(n){
 		if(n%2)
 			r.push(str);
 		str+=str;
 		n >>=1;
 	}
 	return r.join(”);
}

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).

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:

function mul5(str, n) {
 	var r=[],t=[str];
 	while(n){
 		if(n%2)
 			r.push.apply(r,t);
 		t.push.apply(t,t);
 		n >>=1;
 	}
 	return r.join(”);
}

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.

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:

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 >>=1;
	}
	return r.join(”);
	@*/
	while(n){
		if(n%2)
			r.push(str);
		str+=str;
		n >>=1;
	}
	return r.join(”);
}

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)

Try it yourself here. Changes compared to the original one:

  1. mul1 and mul2 are slow, so removed from the test
  2. the number of repetition and the length of the input str are slightly different from the original one
  3. A table is used to present the result, rather than a list

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) , also support me throughout my PhD study.

This research was made possible under the excellent supervision of Prof. Andy Tyrrell and Dr. Julian Miller. 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.

Credits should also go to my friends, labmates, thanks for the assistance and suggestions, as well as the laughs and times shared with me.

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…

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 access them. If you know me personally, please ask me for that.

Next Page »