Adi Drumea

Tuesday, November 27, 2007

[Javascript] typeof

Today i needed a way to check the real type of an object in javascript. Since typeof always returns 'object' for Date and Array objects, i needed a typeof routine that would return 'array' or 'date' (needed for json encoding). Here is a simple method to detect if an object is an Array instance or a Date instance:

function objectIsArray(o) {
if (o === null)
return false;
return o.constructor == (new Array).constructor;
}

The constructor function is always defined for arrays. Two functions return equal if and only if they're the same function.

Friday, November 23, 2007

[MySQL] Query optimizer bug

Today I posted my first bug report to the MySQL project.

Here is the link:

http://bugs.mysql.com/bug.php?id=32665

It has to do with slow query when dependent subqueries and IN operator is used and the dependent subquery result can be cached (but it is not).

Update: They said it will be fixed in MySQL 6. I'm not too glad about the timeframe.

Monday, November 05, 2007

[Web] Content-Disposition: inline; filename=bla.pdf

For some reason, the adobe pdf reader plugin doesn't care about the filename argument of the Content-Disposition directive when you save the pdf file. The fix is to use friendly URLs, and to build your url with the pdf filename as the last part of the url. For example, consider the following url: view.php?op=pdf&id=100. Before the fix, the plugin would suggest the filename view.pdf, no matter what filename= would be given in the http headers. After the fix, using the url view.php/op/pdf/id/100/myname.pdf, the plugin would suggest myname.pdf, which is exactly what we wanted. Note that friendly urls typically exclude .php extension from the script name, but i didn't bother to make the proper apache config changes to support it. Also note that the script arguments should be separated by /, and no funny characters should appear in between unless properly encoded.