blog’s amazing Rotating Header Image

“Micro” Optimizations That Matter

Brandon Savage compiled a good summary of application performance tips. Definitely not the difference between using single and double quotes in your code: these are easy to implement and effective (=”micro”) methods to improve responsiveness of your code, like:

  • Caching
  • Eliminate Any Sort Of Logged Errors
  • Enable Output Buffering For Everything
  • Make Use Of A Content-Delivery Network
  • Determine What Data Doesn’t Need To Be Real-Time
  • Consider Using An Autoloader

Read more about “Micro” Optimizations That Matter at BrandonSavage.net.

Bookmark and Share

Watch out for your CRON jobs

Running CRON jobs is not an easy task if you want to do it perfectly: fortunately we’re doing it similarly as it’s recommended by the Percona guys:

- prevent running multiple copies using file locks
- watch for errors
- store historical run times (use logging)

Further details and code sample in Watch out for your CRON jobs at MySQL Performance Blog.

Bookmark and Share

PHP memory_limit calculator for image resizing

Do you have some image resizing PHP code out in the wild? You’d better prepare yourself: your code may break anytime if you don’t pay attention to the memory limit settings of PHP. (God, it could already did!)

Take care of the plenty megapixel images and avoid trouble now!

How many memory do you really need? Find it out for yourself! The dotsamazing.com labs proudly presents the hot’n’sexy PHP memory limit calculator for image resizing! Check it and process images like a pro.

Should you have any questions regarding image resizing and memory allocation, feel free to ask in the comments!

Bookmark and Share

Opera and iGoogle: do you want your Tab key back?

In case you’re using Google Search with your Google account logged in you may have already seen the iGoogle features like Promote, Remove or Comment.

They may be cool in some cases, however, these icons break the keyboard navigation on a Google result page: they just steal your Tab key, which is the fastest way of quickly changing keyboard focus back to the query field. The feature used hundreds times a day.

Fortunately to tame the beast only a few lines of user JS is enough, like this:

// site: google.com
// user javascript use the tab key to focus to search field
// created by: dotsamazing.com (blog.dotsamazing.com)

if ( location.hostname.indexOf('google.com') != -1 ) {

  if( location.href.match(/search/) )

    document.onkeypress = function(e) {

      keynum  = e.which;

      if ( keynum == 9 ) {

        if (
             ( e.srcElement.name == 'q' ) &&
             ( e.srcElement.tagName == 'INPUT' )
           )
          // may still press tab key to move
          // on to Search submit button
          return true;
        else {
          // in any other case focus to search field
          document.forms[0].q.focus();
          return false;
        }

      }

    }

}

Just place these lines in a file named googletabkey.js under user_javascripts in your Opera profile directory (something like Documents and Settings/youruser/Application Data/Opera/Opera/profile/user_javascripts, YMMV), and now you’re ready to go!

From now on when you’re opening the search pages at google.com, your Tab key will only move between the top search field and its submit button.

Bookmark and Share

Are there problems with floating point in JavaScript?

JavaScript is a mature language (holding mature issues), though tomorrow I’ve ran into something that’s out of this world:

<script type="text/javascript">
document.write( 0.1 + 0.2 );
document.write( '<br />' );
document.write( 0.1 + 0.2 === 0.3 );
</script>

Guess what?

0.30000000000000004
false

Well, not exactly the result I’ve expected.

However, the issue is absolutely not unknown neither new: many languages (including C) have similar issues due to the approximate representation of floating point numbers in memory (leaving the deep explanation to others).

For the impatient: you’ve got two options here.

First: use the .toFixed() method, for example:

( 0.1 + 0.2 ).toFixed( 2 )

It works fine when you don’t really need the floating point calculations, which is absolutely fine for money calculations for example.

The second option? Well, I should offer a nice GPL JS library which does the trick. The bad news is that I’m not aware of one, so should you find a solution, feel free to post it in the comments!

Bookmark and Share

Cufón – a cool alternative to sIFR

On one of our sites, fokk.hu we’ve implemented the sIFR technology to introduce an easily translateable interface with True Type Fonts other than the browser-safe ones.

Honestly, sIFR is a hard-to-tame kind of beast. Only sIFR 3 nightly builds gave the so-so compatibility we’ve needed on this site, and even these builds did produce strange bugs. To name a few: setting up sIFR was quirky when the sIFRed text was also a link (the .sIFR-root class didn’t work in such cases); sIFR text was clipped sometimes; under some circumstances, you needed to click twice on sIFRed links; in Opera sIFR menu items were unclickable when the mouse cursor was below about half of the screen (what the…?).

That’s why we became quite delighted when read first about Cufón, the lib with the strange name (CUstom FONts, FYI). If you’re looking for really easy-to-use font replacement library, go no further. Using Cufón is quite easy, and it works absolutely flawlessly compared to sIFR in every browser that counts for us. Cufón technology is based not on Flash but Canvas and VML (IE).

Setting up Cufón is very easy: you only need to convert your fonts to a JS representation using an online font converter, and insert several instructions to do the actual replacement. Cufón even recognizes JS frameworks/libraries if they’re available, this way you can use CSS selectors too. If interested, go and give a try, I’m sure you’ll be pleased!

Bookmark and Share

Smarty support in NetBeans || die()?

It seems that Sun is serious about providing PHP support in the NetBeans, a 10-years-old Java IDE.

However, besides many of the cool features already included there’s a showstopping shortage for many PHP devheads: NetBeans does not support the all-time favourite Smarty template library, which provides the foundations for zillions of web sites out in the cloud.

Though NetBeans does cool source highlighting and much more even when there’s PHP and HTML mixed together in a single file, Smarty support is entirely missing – I’m sure it will make many developers turn away from NetBeans in the first round, unless the support arrives soon.

As a comment says in the NetBeans issue tracker, “Officially there will not be any framework supported in NB 6.5“.

I agree that adding a framework means much more work than adding a syntax highlighter from the NB viewpoint (that’s why a separate plugin project has been established for Drupal), though even such a support could help a lot in the first round.

Fortunately we’re not entirely lost – there are two things you can do:

  • first, you can add your Smarty extension (eg. tpl) under
    Tools > Options > Miscellaneous > Files
    and set the MIME type to
    PHP files (text/x-php5)
    .
    This step adds at least basic HTML and PHP formatting – it seems to be the most you can achieve right now.
  • and vote to the appropriate issue in the bug tracker of NetBeans right now! You’ll need to do a short one-minute registration for that, but if you’re devoted to using both Smarty and NetBeans that’s not that much.
Bookmark and Share

Opera 10a messes up Vista associations – the solution

Being an Opera lover (though not a blind enthusiast) I was happy to read about the alpha release of Opera 10.

During the installation I’ve unchecked the option to set Opera 10a as the default browser, since Opera 9.63 is already installed on my notebook. That’s exactly where something went wrong: Opera 10a was set as the default browser. As I was only about to test the latest alpha, it was really annoying here, I wanted 9.63 back!

To make the situation even worse:

  • the Vista association dialogs (screens) do not differentiate between versions of a single software! I was truly disappointed here. As the registry had 5+ entries with Opera 10 in the path, I’ve decided to look for some official solution.
  • tried to find an Opera setting. No luck, Opera doesn’t have a built-in “restore association” option

After trying every possible combination of the offical tools, here’s the solution: after making a backup of your profile, you have to uninstall Opera 10a, uninstall Opera 9.63, and reinstall Opera 9.63.

Though it’s not really a kind of bug John Resig meant in his post, a bug report has been filed for Opera. I guess early adopters on Vista should say goodbye to O10a yet, if they need a stable browser installed too.

Bookmark and Share