Monday, April 30, 2007

The dollar-dollar ($$) function in prototype.

Since I am going to be working with the dollar-dollar ($$) function from prototype pretty soon, might as well do some research and write about it.

It turns out that the newest versions of prototype 1.5.0 and 1.5.1_rc4 include a lot of cool features for the $$ css selector function. Some of the very useful ones include Attribute selectors (~= $= *=).

For details, please refer to and w3c css selector reference.

Friday, April 27, 2007

New things in Javascript 1.7

As the Javascript is becoming more than more mature, it is starting to show some really neat features that you can find in programming other scripting language, such as Ruby and Python. Here, I will just pick a couple of them to do some neat tricks that we would probably find useful.

Destructuring assignment makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.

The object and array literal expressions provide an easy way to create ad-hoc packages of data. Once you’ve created these packages of data, you can use them any way you want to. You can even return them from functions.

One particularly useful thing you can do with destructuring assignment is to read an entire structure in a single statement, although there are a number of interesting things you can do with them, as shown in the section full of examples that follows.

This capability is similar to features present in languages such as Perl and Python.

Trick 1: Swapping values between two variables without using the temporary variable.

I still remember when I was learning assembly language programming, one of my friend was so proud of showing off the XOR Swap Trick. It was indeed the coolest thing I saw then, since it saves 1 register. ;-)

Now, how can you do it in Javascript? Use Destructing Assignment.

var a = 1;
var b = 3;

[a, b] = [b, a];

Ha! One line does it all, and it is quite readable!

Trick 2: Parse a URL and get the parts from it using as few lines of code as possible.

var url = '';
var parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url);
var [, protocol, fullhost, fullpath] = parsedURL;

Notices that we ignored the first value from the result, and we are able to extract and assign all of the parts of the URL in one line!

For detailed explanation of what’s new in Javascript 1.7, please visit

Thursday, April 26, 2007

Cheat Sheets for programmers

My cheat sheet discovery didn’t just end with regular expression. ;-) I went on and found a great cheat sheet collection for programmers like me!

More help on regular expressions ;-)

Even though you’ve got the Awesome Free Regular Expression Generator, there are times that you will still trying to scratch your head for some of the regex syntax details. Here is the link to the Regular Expression Cheatsheet! Oh, did I forget to say~ “It’s really awesome, too!”


Wednesday, April 25, 2007

Awesome Free Regular Expression Generator

Ever had “Not again~!” time with regular expression coming in your way? I had a lot of them recently. Fortunately, someone has already wrote regex generator for it. While there are tons of them out there, not a lot of them do what I want, or as easy to use and free. After a while, I found The regex generator provided by text2re is really simple to use; it’s works from the browser, so you don’t have to install anything, and virtually use it anywhere; it even gives you the generated regular expression code in 15 computer languages (ruby, perl, python, php, javascript, c, c++, c#, etc.), ;-) and most important of all, it is FREE!


Use Javascript to detect Vista?

I encountered a strange bug today, where the same piece of javascript code works perfectly on ie 7 (7.0.6000.16386) on xp, but fails randomly on the same version of ie7 on vista. I know how to use object detection technique to figure out which version of browser it is and what kind of functionality it supports, but how am I gonna use that to tell the two supposedly the same browser from 2 different OS?

Object detection is not an option now, and the best I can find online is to check User Agent, which is not very reliable.

You can try the following code on your browser address bar:


Notices the IE versions:

2K is version 5
XP is version 5.1
vista is version 6
[1] Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20060508 Firefox/
[2] Opera/9.00 (Windows NT 6.0; U; en)
[3] Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)



Just for the heck of it, I am adding the link of textile reference to my collection ;-)

Tuesday, April 24, 2007

ie6 and ie7 on the same machine

As the firefox went nuts on my windows workstation, it seems that there isn’t much I can do to fix it even after numerous reinstalls and clearing of the left over files. Even worse, after my workstation was reinstalled with a new image, my working ie6 was gone, and I got ie7 instead ;-(.

How am I gonna fix the ie6 specific bugs now.

Here is what I found out:

Thank God! At least Microsoft has a blogging place for its developers.

Friday, April 20, 2007

Mephisto liquid references

During the process of creating my own Mephisto theme, I found it very difficult not to copy from the other existing themes. Yet, not all of them have the functions that I need. After digging into the code and spend hours to figure out what I can do with the liquid in mephisto with out much efficiency, I finally come across these 2 links on Slash7.

Hope these will help you a lot in creating a custom mephisto theme! ;-)

Wednesday, April 18, 2007

How to remove the default background in Mediawiki?

Assuming that you are going to make changes to the monobook skin, go to skins/monobook/main.css, and comment out the background line in body like following.

body {
font: x-small sans-serif;
/*background: #f9f9f9 url(headbg.jpg) 0 0 no-repeat;*/
color: black;
margin: 0;
padding: 0;

Sunday, April 15, 2007

Helpful notes on administrative tasks on Mediawiki.

After playing around with Mediawiki, I came through some of the good documents for administrative tasks.

Tuesday, April 10, 2007

How do I delete a page from mediawiki?

As recent playing with Mediawiki, I had a hard time finding the page deletion option just from the user interface. It turns out that there isn’t one! ;-) Here is how you delete a page in Mediawiki.

  1. Go to the page that you want to delete.
  2. Append “&action=delete” to the end of the url, and press enter.

For more detailed description, see Deleting a page.

Monday, April 9, 2007

How to clean up the change history of the mediawiki?

From time to time, I make lots of changes into the mediawiki. How can I delete the unwanted history of a page?

Start the command line, and go to the maintenance directory of the mediawiki installation. Finally, enter the following command:

# php deleteOldRevisions.php --delete

Note: You have to have php5 installed, in order to execute this command. Depending on your system configuration, on Dreamhost, it is /usr/local/dh/cgi-system/php5.cgi instead.

Sunday, April 8, 2007

How to get rid of the caching problem in Mediawiki?

Sometimes you will find that the Mediawiki is not updating its content. This is sometimes due to client side caching. To disable this, edit LocalSettings.php as following:

# Client-side caching:
$wgCachePages = false; # Allow client-side caching of pages

How to change the content of Navigation Bar in Mediawiki?


How to set the timezone for mediawiki?

There are times when the physical server and the mediawiki users are in different timezones. Here is how to adjust the timezone in mediawiki. Add the following lines to your LocalSettings.php

$wgLocalTZoffset = date("Z") / 60;

Note: You can find your local time zone text here.

How to enable file upload in Mediawiki?

In LocalSettings.php, Change

$wgEnableUploads = true;

Once you have done that, you can find the “Upload file” link in your “Toolbox” section.

How to make mediawiki not editable by public?

In LocalSettings.php, add the following

/* Disable anonymous user from creating account and editing
pages */
$wgGroupPermissions['*' ]['createaccount'] = false;
$wgGroupPermissions['*' ]['read'] = true;
$wgGroupPermissions['*' ]['edit'] = false;
$wgGroupPermissions['*' ]['createpage'] = false;
$wgGroupPermissions['*' ]['createtalk'] = false;

/* Allow user to login */
$wgWhitelistRead = array ("Special:Userlogin");

/* Make sure that user have to have a valid email address
before edit */
$wgEmailConfirmToEdit = true;

How to make Mediawiki readonly?

This is usually very useful when you want to freeze the database changes to do migrations, upgrades, etc.

  1. make sure the /image directory is writable
  2. go to /image directory and write whatever reason for a readonly wiki in lock_yBgMBwiR.


  1. Change $wgReadOnly in LocalSettings.php to the reason for a readonly wiki.

Sunday, April 1, 2007

Why this? Why now?

I have actually started blogging back in 2001. Had a lot more time back then. I started with hard coding html, copying layouts from and the Final Fantasy gamers blog rings. Later, I moved on with simple php mysql stuff when I started to help people with their dynamic websites.

After that, I started to blog when ever there is a new blogging software or blogging engine. Really just to try them out, but the sad thing is, the blog entries were never kept together and archived. Now, they are scattered all over the place.

So far, there hasn’t been any blogging solution that really fits my needs. The need to have a place to dump all of my daily info, thoughts, files, schedules, emails, contacts in, and being able to search whatever I want with absolute ease and clarity.

So why this? and why now?

As the information that I would like to record grew over the years, I just decided to have a place to dump them first. Hopefully, after a short while, migrating them wouldn’t be such a big pain. ;-)

About me

As you have probably guessed from the tag line, Steve Jobs is one of my greatest inspirations. ;-)

I was one of the luckiest few Shanghai kid, who got to spend my 17th birthday as a high school exchange student in Kissimmee, Florida with my foreign host family. My American high school, Osceola High School, had the finest football team in the entire Florida, and tons of funny stories from me, the 6’2” skinny teen ‘Borat’ from China.

After trying out Mechanical Polymer Engineering, Electrical Engineering and Computer Engineering, I finally settled with Computer Science, as I found it teaching me the things that I am mostly interested in. While enduring the coldest winters of my life in (Akron, Ohio), where I finished my Bachelors in University of Akron, I drove across the country three times exploring my dream place – Silicon Valley.

Being an evangelist of web and the technologies around it, I shortly started my career as a software engineer in Bay Area. I found my first real job after college in Manhattan Associates through one of my former mentors I worked for. While I was there, I helped the R&D of the company wide next generation user interface framework with the architect. Then, I got into Visa, where I worked on the then "next generation" credit card message gateway as a system engineer, and developed a multiple products build and release automation process and tools.

After a brief period of (now Fanbox) as a member of their infrastructure and performance team in San Diego, I came back to Bay Area for a great internet security company Qualys Inc, where I became one of the core developers of QualysGard. While working along side with the security veterans, I became more involved with enterprise UI and cross browser support for our award winning On Demand Vulnerability Management System.

I became a Yahoo! several months before the summer Olympics of 2008, and has been a member of the Yahoo Frontpage group ever since. There, I learned and relearned a whole bunch of things that I thought I learned well before. Never knew that aggregation of the even smallest mistakes, tinyist performance enhancement could make such a big difference. I am so grateful that my team as well as the teams I worked with have taught me so much about the web, and I was given lots of opportunities to work on so many parts of the product. It has truly been an eye opening experience on how one of the most visited pages was made. At the same time, I found out how important data is, and fell in love with it.

My interest in data soon got me into Netflix. As a member of the subscriber acquisition team, we helped optimizing their customer conversion from various marketing channels. I would have to say that Netflix has one of the best marketing teams in the world, and one of the best user funnel management systems ever.

I am currently working for a startup called Outright, where I actually got to design and build their entire data stack. We are trying to make accounting and tax preparation painless for all of the small businesses around the country.

I usually like to keep my brains busy, or having them entertained by the web feeds. Whenever I get a break, I love playing volley ball, soccer, basket ball, and now foosball and table tennis ;-)

Oh, the last but not the least, my latest contributions to open source communities can be found on the right side of this page, or in my linkedin profile.

Thanks for reading!

You can always reach me at lei [dot] sun [at] gmail [dot] com.