Today, I found that one of my PHP scripts stop working. After some investigations, I found that it was the function, imagecreatefrompng, which caused the problem. Interestingly, other similar functions such as imagecreatefromgif and imagecreatefromjpeg were completely working fine. The program stopped working when calling imagecreatefrompng only. Initially, I thought the problem was coming from the PHP side. Therefore, I tried to get...
Read More[PHP]imagecreatefrompng Error (After upgrading FreeBSD)
Natural Sort. MySQL. Sorting a 2D Array By Multiple Columns in PHP Naturally. Array_MultiSort with Natural Sort
MySQL has a biggest missing feature: It does not sort naturally. This has been an opened request since 2003, and MySQL team has no plan to fix this in a near future. I have looked for a solution to solve this problem for a while. Unfortunately, I found nothing useful. Here is a summary: The + 0 Trick Many developers suggest this solution: SELECT names FROM your_table ORDER BY age + 0 ASC This is not a good solution because it only works...
Read More[PHP]How to get the number of CPU cores in Fedora, Ubuntu, and FreeBSD
I am working on a PHP application which needs to be deploy to multiple places. One of the variables is the number of CPU core. Since each server has different number of CPU cores, I need to specify the number of CPU core in my application for each server. I think there should be a smarter way to do it. PHP is a scripting language, it has limit support on accessing the hardware level information. In short, there is no library or function...
Read MoreWeird JavaScript Date Bug
Today I found a very weird bug in JavaScript – The date function. I never expected to see a bug in the standard JavaScript implementation. Here is my code. It does nothing more than adding 21 days on the reference date: var referenceDateObject = new Date(2011, 9, 10); var deliveryDateObj = new Date(referenceDateObject.getTime() + 24 * 60 * 60 * 1000 * 21); var deliveryDateMonth = parseInt(deliveryDateObj.getUTCMonth()); var...
Read MoreA letter to Microsoft Internet Explorer Development Team
Dear Microsoft Internet Explorer Development Team, Would you like to take the source of Firefox (or any browser besides Internet Explorer) and call it Internet Explorer 10? Thanks. –Derrick
Read MoreEnough “Rails Surprise”! Goodbye Ruby On Rails.
Couple months ago, I published an article about Ruby On Rails. I was wrong. The idea of Ruby On Rails is really good. You can create a very simple database-driven web application (i.e., User can add, browse, remove and search records) in less than half an hour. There is no way to do something similar in such a short time using other programming languages. However – perhaps this is the tradition of the Rails development team, it comes...
Read MoreRuby On Rails gives no “surprise” in the latest version
I haven’t upgraded my Ruby On Rails and related Ruby gems for 5 months. One of the reasons is that Rails development team likes to break the backward compatibility, such as: NameError: uninitialized constant ApplicationController To avoid this kind of surprises, I tend to stick with a working, stable version. Recently, I upgrade the entire Ruby On Rails family(2.3.2 -> 2.3.4), and surprisingly, my Ruby On Rails apps work...
Read MoreIE is “fxxking”, but it is not an excuse to leave bug in the codes
Today, my co-worker found that the web-application he developed worked only in Firefox, and it didn’t work in Internet Explorer(IE). He immediately asked me if we should ignore the IE users or not. I know that he was working on JQuery(Javascript). It is not surprised that IE does not support the standard JQuery. However, it doesn’t mean that we can simply remove our support to IE users. In fact, IE still have more than 55% of...
Read MoreInterviewing a software engineer / developer / programmer
I am going to have a face-to-face interview with a candidate of a PHP programmer position this afternoon. I was told to prepare some technical questions for the interview. If a candidate earns an face-to-face interview opportunity, that means his resume should have a very good match to the position requirement. However, people can put anything on their resumes, there is no way to tell whether the information on the resume is true or not...
Read MoreExample PHP code to convert a number to an Excel column letter
I was looking for a good way to convert a number to the Excel column letter, for example: 1 -> A 26 -> Z 27 -> AA 28 -> AB 800 -> ADT etc. After searching on Google, I could not find any algorithm I want. (The closest one can handle up to two letters, i.e., ZZ. It will crash if the number is too large.). So I ended up creating my own. Basically, you can think of this problem as a 26 based number conversion. Here is the php version. It...
Read More