Auto margin on RTL page doesn’t work on IE

May 13, 2009 Leave a comment

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;}
Categories: html

Bookmarklet of URL shortener

April 23, 2009 Leave a comment

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.
Categories: bookmarklet, url shortener

Create a small gadget "URL Shortener"

April 23, 2009 Leave a comment

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:
Categories: gadget, url shortener

Paste in Cygwin window

April 7, 2009 Leave a comment

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.
Categories: cygwin

Get viewport size using JavaScript

April 7, 2009 Leave a comment

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};
}

(function(){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};}function fn() {var ele = document.getElementById(“viewport”);if (ele) {var s = getViewportSize();ele.innerHTML = “Viewport size: width=” + s.width + “;height=” + s.height;window.clearTimeout(arguments.callee._timeout);}else {arguments.callee._timeout = window.setTimeout(arguments.callee, 500);}}fn();})();

Categories: javascript, viewport

Add JavaScript code to posts on Blogger

April 7, 2009 Leave a comment
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:
(function(){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();})();
Categories: blogger, javascript

Yahoo! Search BOSS

April 3, 2009 Leave a comment

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.

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.