2010年1月7日星期四

This blog is moved to http://alexcheng1982.wordpress.com/

Because Blogger is not accessible in China, I moved the blog to Wordpress. http://alexcheng1982.wordpress.com/

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:


CHENG Fu's blog

Technology changes life