New API: Expand URL

Today, the Internet is flooded with shortened URL. All links shared on Twitter are shortened (start with There is nothing wrong with it. I just don’t feel comfortable clicking a shortened URL without knowing where it will bring me to. How paranoid I am! There are several reason I don’t trust shortened URL: They might contain tracking or referral code. SlickDeals heavily uses it (to make money, of course). Again, there is nothing wrong with it. They provide you a service and they deserve to get some money out of it. They might hide malicious URL, like XSS I hate them! There are several expand URL services out there, however they just support a very limited set of URL shorten service. What I want is something more. I want to be able to track the final URL after a bunch of redirections. So I wrote this API:<your_url_here_no_escape_needed> For example: Here is the API result. You will be amazed how many hops it take to the final destination:!GQ96-PAKTEzy%3C1DD9%3A%2F%2FGGG.3x8A8wI.w86%3ASK%2Fw52w4-LMMPMQR-LKOOKSTR%3C%3Ca%3C1DD9C%3A%2F%2FGGG.08805y.w86%2F%3C Suggestions welcome!

Free course: The Complete iOS 7 Course – Learn by Building 14 Apps (was $499)

I always want to learn how use build an iOS app, and I have some idea in mind. However, I’m just lazy and procrastinating to do so. Today I found a free course (via Slickdeal) to build an iOS app, and already registered (and you should). It’s free (was $499). Link:

Markdown is available for self-hosted WordPress through Jetpack

Jay! I’ve just noticed that. It’s funny when searching for Markdown on WordPress return this article: Write (More) Effortlessly With Markdown Basically, they mentioned that Markdown is only available for blog, by a simple switch in configuration. I am skeptical, so I always try to use “official” version of plugins. Yes, there are many Markdown plugins out there When I check my Jetpack version, it’s already there! So if you want to write in Markdown style (like Github and StackOverflow), just enable it (why not?).

Today I Leaned (the hard way): The difference between dict and list and Python

Lookup time for dict() is O(1) and for list() is O(n) no matter what the number of elements is. Given a list of elements in a file, this piece of code: from itertools import izip lists = map(str.strip, open(‘dict.txt’).readlines()) i = iter(lists) j = range(len(lists)) dicts = dict(izip(i, j)) index = dicts[w] is n time faster than this piece of code: dicts = map(str.strip, open(‘dict.txt’).readlines()) index = dicts.index(w) I learned that the hard way. My dict has 5,000,000 elements, which mean my code will run 5 millions time slower than it should be. As such, I ran my code on 20 machines, each with 64 cores and it took ~10 hours without finish. Changing from list to dict, it took about 900 seconds on a single machine (of course 64 cores) Next time, when you want to do lookup in Python, use dict(). Happy coding!

How to connect to NYU-Poly wifi using Nokia E71 (and other Symbian phones)

I’ve been struggling with connecting to Poly-WiFi network using my Nokia E71. This page gives instruction to connect for iPhone, Windows and Mac but not for Symbian. Fortunately, after some finding on Internet and researching Poly network, I can define the correct configuration that enables my E71 to connect to Poly wireless. Here is the configuration detail: Step 1: Go to Menu -> Tools -> Settings -> Connection -> Access points and add new access point with the following information: Connection  name: Poly-WiFi Data bearer: Wireless LAN WLAN network name: Poly-WiFi Network status: Public WLAN network mode: Infrastructure WLAN security mode: WPA/WPA2 Homepage: None Step 2: Enter WLAN security setting and define: WPA/WPA2: EAP WPA2 only mode: Off Step 3: Enter EAP plug-in settings and disable ALL plug-ins except EAP-PEAP. Enter EAP-PEAP and define: Personal certificate: Not defined Authority certificate: GeoTrust Global CA User name in use: User defined User name: Your Poly ID, for example abc01 Realm in use: User defiined Realm: Leave blank Allow PEAPv0, PEAPv1 and PEAPv2: Yes Step 4; Switch to EAPs tab and disable ALL plug-ins except EAP-MSCHAPv2. Enter EAP-MSCHAPv2 and define: User name: Combine Your Poly ID and ‘’, for example Prompt password: No Password: Your password Step 5: Go back until you see home screen. You will be able to connect now. Bingo!

Thử một bài viết có rất nhiều tiếng Việt

Bài viết này lẽ ra đã không được publish. Mục đích của mình chỉ là kiểm tra xem WordPress 3.4 xử lý tiếng Việt trong Permalink như thế nào. Trước 3.4, WordPress xử lý việc này không tốt, cụ thể là với tiêu đề như trên, WordPress sẽ xử lý thành “thử-một-bai-viết-co-rất-nhiều-tiếng-việt”. WordPress 3.4 đã xử lý việc này rất tốt, URL trở thành “thu-mot-bai-viet-co-rat-nhieu-tieng-viet”. Dưới đây là đoạn code được mình viết và đặt trong file wp-includes/formatting.php để xử lý tiếng Việt trong Permalink. WordPress 3.4 cũng có một đoạn xử lý tương tự nhưng đã tối ưu và loại bỏ các ký tự trùng với các phần sẵn có trong WordPress. [code] // Decompositions for Vietnamese chr(65) => ‘A’,chr(97) => ‘a’, chr(196).chr(130) => ‘A’,chr(196).chr(131) => ‘a’, chr(195).chr(130) => ‘A’,chr(195).chr(162) => ‘a’, chr(195).chr(128) => ‘A’,chr(195).chr(160) => ‘a’, chr(225).chr(186).chr(176) => ‘A’,chr(225).chr(186).chr(177) => ‘a’, chr(225).chr(186).chr(166) => ‘A’,chr(225).chr(186).chr(167) => ‘a’, chr(195).chr(129) => ‘A’,chr(195).chr(161) => ‘a’, chr(225).chr(186).chr(174) => ‘A’,chr(225).chr(186).chr(175) => ‘a’, chr(225).chr(186).chr(164) => ‘A’,chr(225).chr(186).chr(165) => ‘a’, chr(225).chr(186).chr(162) => ‘A’,chr(225).chr(186).chr(163) => ‘a’, chr(225).chr(186).chr(178) => ‘A’,chr(225).chr(186).chr(179) => ‘a’, chr(225).chr(186).chr(168) => ‘A’,chr(225).chr(186).chr(169) => ‘a’, chr(195).chr(131) => ‘A’,chr(195).chr(163) => ‘a’, chr(225).chr(186).chr(180) => ‘A’,chr(225).chr(186).chr(181) => ‘a’, chr(225).chr(186).chr(170) => ‘A’,chr(225).chr(186).chr(171) => ‘a’, chr(225).chr(186).chr(160) => ‘A’,chr(225).chr(186).chr(161) => ‘a’, chr(225).chr(186).chr(182) => ‘A’,chr(225).chr(186).chr(183) => ‘a’, chr(225).chr(186).chr(172) => ‘A’,chr(225).chr(186).chr(173) => ‘a’, chr(69) => ‘E’,chr(101) => ‘e’, chr(195).chr(138) => ‘E’,chr(195).chr(170) => ‘e’, chr(195).chr(136) => ‘E’,chr(195).chr(168) => ‘e’, chr(225).chr(187).chr(128) => ‘E’,chr(225).chr(187).chr(129) => ‘e’, chr(195).chr(137) => ‘E’,chr(195).chr(169) => ‘e’, chr(225).chr(186).chr(190) => ‘E’,chr(225).chr(186).chr(191) => ‘e’, chr(225).chr(186).chr(186) => ‘E’,chr(225).chr(186).chr(187) => ‘e’, chr(225).chr(187).chr(130) => ‘E’,chr(225).chr(187).chr(131) => ‘e’, chr(225).chr(186).chr(188) => ‘E’,chr(225).chr(186).chr(189) => ‘e’, chr(225).chr(187).chr(132) => ‘E’,chr(225).chr(187).chr(133) => ‘e’, chr(225).chr(186).chr(184) => ‘E’,chr(225).chr(186).chr(185) => ‘e’, chr(225).chr(187).chr(134) => ‘E’,chr(225).chr(187).chr(135) => ‘e’, chr(73) => ‘I’,chr(105) => ‘i’, chr(195).chr(140) => ‘I’,chr(195).chr(172) => ‘i’, chr(195).chr(141) => ‘I’,chr(195).chr(173) => ‘i’, chr(225).chr(187).chr(136) => ‘I’,chr(225).chr(187).chr(137) => ‘i’, chr(225).chr(187).chr(138) => ‘I’,chr(225).chr(187).chr(139) => ‘i’, chr(79) => ‘O’,chr(111) => ‘o’, chr(195).chr(148) =>

How to disable comment box from Facebook like widget

It have been a long time since the last time I used Facebook like widget on my blog. At that time, I feel that Facebook scripts take a lot of time to load, hence slowdown my site and affect its performance. Today, I changed my mind and add it back. With just 2 pieces of code (one load all.js at bottom and one load the like button), Facebook like button appears again on my site. Sweet and simple! But wait. When I test by click on Like button, an ugly comment box appear: As this is unexpected, I want to disable it. But Facebook Developer page does not give me any information about this. Fortunately, with just one simple CSS trick, I can hide that ugly comment box so the Facebook like become beautiful (like it should) .fb_edge_widget_with_comment span.fb_edge_comment_widget iframe.fb_ltr { display: none !important; } Happy hacking!

How to format bytes to kilobytes, megabytes, gigabytes in PHP

This is the best function I found on StackOverflow: function formatBytes($bytes, $precision = 2) { $units = array(‘B’, ‘KB’, ‘MB’, ‘GB’, ‘TB’); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) – 1); // Uncomment one of the following alternatives // If 1 kilobytes = 1024 bytes // $bytes /= pow(1024, $pow); // If 1 kilobytes = 1000 bytes // $bytes /= (1 < < (10 * $pow)); return round($bytes, $precision) . ' ' . $units[$pow]; }

CSS: How to add width and height attributes to anchor tag

You might face this problem sometimes: You want to add width and height to an anchor instead of giving these attributes to its container. Surprisingly, width and height attribute are not works. For example, consider the following codes: a.ansok { width:86px; height:41px; line-height:41px; background-image: url(../images/layout/button.png); } And here is what you will get (instead of beautiful buttons): So, what is the reason and how to fix it? Well, anchor tags are not block level HTML elements but rather inline elements. So what is the difference between the two? Here is the definition of the two items: Inline Element definition: Inline elements typically may only contain text and other inline elements. When rendered visually, inline elements do not usually begin on a new line. Block Element: Block-level elements typically contain inline elements and other block-level elements. When rendered visually, block-level elements usually begin on a new line. So, all you have to do is just add display:block to CSS class of anchor. And here is the result: Some useful links: HTML inline elements HTML Block Elements

How to make Cufon works in IE9

IE, and probably Microsoft, has a lot of surprises for you. As you know, each IE version has its own behavior. And don’t surprise if IE9 does not render Cufón at all Meaning that every beautiful things you see in Firefox, Chrome, … will not even show up in IE9. Nothing. You will only see a blank space. Then, how to fix it? First, you need to download the latest version of Cufón. It’s 1.09i, which has support for IE9. Download here Second, add the following lines to your code: And it works. Combination of the two method will give you a great look of your website in IE9. Have fun.