2009年5月13日星期三

Auto margin on RTL page doesn't work on IE

Auto margin is used extensively to center an element horizentally. But it doesn't work on IE for RTL pages.

A solution is found here :

Set the direction of <html> element to "ltr" while setting the direction of <body> element to "rtl". I tried this solution, it works. Great!

html {direction:ltr;}
body {direction:rtl;}

2009年4月22日星期三

Bookmarklet of URL shortener

I created a bookmarklet for the url shortener and a testing page for it.

Drag the link below to the bookmark bar.



The main motivation behind this small tool is to help me writing tweets. Twitter is smart that it can convert long URLs to short ones using tinyurl, but that only happens when the whole text is shorter than 140 characters, otherwise the "update" button is disabled and you can not go further. So I want this tool which can be accessed quickly in the twitter's page.

Create a small gadget "URL Shortener"

I have to say that there exists several gadgets that do the same thing. Frankly speaking, I don't try them, I just keep telling myself that what I made is the best.

In my gadget, you can choose the URL shortening service to use. Currently, you can choose tinyurl or bit.ly. I used GAE to implement the background service, i.e. the scraping thing.

You can try in on my blog, it's on the right side. Or add it to iGoogle via the link below.


A screenshot:

And the real thing:



2009年4月7日星期二

Paste in Cygwin window

I want to paste some text from Windows to Cygwin's bash window, but I don't want to enable the quick edit mode of the command window, because it may lock the command window.

So I used the context menu to paste the text. Just click the cygwin icon in the top left of the window, you can see the menu. See the screen-shot below.


Get viewport size using JavaScript

The main idea of the JavaScript is stolen from here. I just rewrote the code a little to make common path faster.

function getViewportSize() {
var w = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || document.getElementsByTagName('body')[0].clientWidth;
var h = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || document.getElementsByTagName('body')[0].clientHeight;
return {width : w, height : h};
}





Add JavaScript code to posts on Blogger


I tried to add some JavaScript code in my post, but it seemed to be harder than I thought. I googled a lot of pages about it and found pages like [1], [2] and [3]. For JavaScript code that not run immediately after the page is loaded, using plan <script> tag is ok. But my JavaScript code needs to be executed after the page is loaded, I tried the approach using <code>, it didn't work. Then I decided to use window.setTimeout to hack that. It works.


See the script below, the content of "viewport" is modified by script after the page is loaded. Note, the script should be only one line to avoid <br> tags inserted by Blogger.

<script type="text/javascript">function fn() {var ele = document.getElementById("test");if (ele) {ele.innerHTML = "Content set by script ";window.clearTimeout(arguments.callee._timeout);}else {arguments.callee._timeout = window.setTimeout(arguments.callee, 500);}}fn();</script>
<span id="test"></span>



The script in action:


2009年4月3日星期五

Yahoo! Search BOSS

Yahoo! is continuing to open up its search platform. It has SearchMonkey, and now the BOSS. BOSS means "Build your Own Search Service". It's free now but will have a fee structure in the near feature. What interests me is the mashup framework, a Python library to manipulate data.

2009年4月2日星期四

Apache's Ftp Server

Maybe I'm out of date now, but I just found Apache's ftp server yesterday. I've tried many ftp servers, such as Serv-U, Cerberus, and several other home-made software. All these software I used are quite good. But I have to say Apache's ftp server is what I need as a programmer. The GUI is fancy and great, but my favorite is still XML configuration.

Just download the package, unzip it and run the bat script. It's simple but enough. Remember, YAGNI.

2009年3月24日星期二

Maven 2.0.9 doesn't work with IBM JDK 6 SR1 - An interesting problem of JDK

I was trying to compile Apache Axiom using Maven 2.0.9. But it didn't work when I was using IBM JDK 6 SR1.  Then I found this issue. It turns out to be a very interesting problem with IBM JDK 6 SR1.

So I repeated the same test on my machine.  Yeah, I have to say the output is quite weird. How can you image this kind of problem occurs in the JDK?

2009年3月11日星期三

Will web workers be shipped with Firefox 3.1?

Update: The next release of Firefox will be Firefox 3.5 instead of Firefox 3.1. See the news : Firefox 3.1 may become Firefox 3.5


It has been said for a long time that web workers will be shipped with Firefox 3.1. That was really a great news. But when I was reading the article of "Using web workers", I found out that it's said in this article that web workers would be shipped with Firefox 3.5. This change was made in March 6. Any mistakes here or the plan has been changed? I took a look at the plan, but it seems that the plan is the same.

See the screen-shot below. The top is the latest version and the bottom is previous version.





2009年3月2日星期一

Safari 4.0

Safari 4.0 public beta is there. At the first sight, it reminds me of Google Chrome. Just like Chrome, it adds "fast dial" for mostly used web sites. Safari 4.0 calls it as "Top Sites". I think Firefox would provide the same function without the extension "fast dial".

I used "UA Profiler" to test it and the result shows that Safari 4.0 supports parallel scripts, which is a great improvement to Safari 3.x.

2009年3月1日星期日

Firefox uses different fonts for input and textarea

By default, Firefox uses different fonts for input and textarea. If you don't set the font family used by input or textarea, even though the font size of them is identical, the display of text in them is different.  This is because that Firefox uses monospace fonts for textarea, but variable-width fonts for input

So besides setting the font size of input and textarea, you need to set the font family directly in CSS. A sample can be found here

input, textarea
{
color: red;
font-family: Verdana,Arial,Sans-serif;
font-size: 0.8em;
}


Disable Firefox cache

Firefox's cache can be quite annoying when you're developing web applications. You may have to manually clear it to let the browser load the latest version of you code.

So a good approach is to disable it, then you don't need to clear it. A good instruction can be found here.

Basic steps:
1) Type "about:config" in the address bar
2) Filter the configuration using "cache"
3) Change the value to "false" if it is "true"

2009年2月23日星期一

Check directories and files existence in Ant

Well, it's common to check whether a directory or file exists before using it in Ant scripts. I just did some quick searches and find out a general solution in here.

Taks <available>is used.

Just copy from that post.

<available file=\"${your.file.path.here}\" property=\"your.file.path.here.present\"/>

<if>
<equals arg1=\"${your.file.path.here.present}\" arg2=\"true\"/>
<then>
</then>
<else>
</else>
</if>

Technology changes life