Archive for November, 2008
40 Tips for Optimizing PHP Performance
Reinhold Weber has written 40 Tips for Optimizing PHP performance. Many of them were new to me – e.g. $row['id'] is 7 times faster than $row[id]. I don’t know how he has measured these numbers, but the tips are good overall!
Here are the first 10 tips:
- If a method can be static, declare it static. Speed improvement is by a factor of 4.
- echo is faster than print.
- Use echo’s multiple parameters instead of string concatenation.
- Set the maxvalue for your for-loops before and not in the loop.
- Unset your variables to free memory, especially large arrays.
- Avoid magic like __get, __set, __autoload
- require_once() is expensive
- Use full paths in includes and requires, less time spent on resolving the OS paths.
- If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
- See if you can use strncasecmp, strpbrk and stripos instead of regex
Read the full list of 40 tips here.
Read comments on the post as well, they too contain useful information.
Opening External Links in new window from AS3
You most probably know that there are issues opening links using the navigateToURL() method in Flex. The three most common problems / issues are:
- allowScriptAccess not set to all in the HTML Wrapper
- Window Mode set to transparent in IE
- Popup blockers blocking the new window – specially when target is _blank
Many people have tried solving this issue. My approach is simply a hack over FlexMerge’s code. Which in turn is a hack on “Jason the SAJ”’s approach. Another approach I liked in detecting if popup blockers blocked your window is Andrew Trice’s solution on InsideRIA.
Essentially, use JavaScript window.open method for Firefox, a little tweak on that for IE and use navigateToURL() for other browsers.
Continue reading for the code…
Read the rest of this entry »
Introduction to Screencasting in Linux – recordMyDesktop
Screencasting is a great way to share information. I use it to show bugs to my team, to record training videos of the project management system I am working on, and even to record demos of project deliveries to clients. I use Jing to record videos from my Mac. But wanted to find something useful for Linux.
recordMyDesktop is a great Linux tool to record the entire desktop, a portion or an application. It outputs Ogg format video, which can easily be converted to AVI, QuickTime or FLV. It’s been there for a while, and is pretty solid.
What sold me though, was this video explaining how to use recordMyDesktop – and then to convert saved video into other formats. It’s easy to follow and covers all important aspects.
If you want to record screens from Linux, this is the best tool. Try it out!
(thanks Santosh for pointing me to this!)
How to stop keyboard event propagation – Flex / JavaScript?
In a Flex application we are building, we want to listen to Ctrl+N to create a new file. The browser listens to the keystroke and opens a new window. We do not want it to open a new window.
This has been a problematic thing for many. I did a lot of research, trial & error, but I still don’t have a solution. I can catch all key events, using some JavaScript, I can also prevent Ctrl+W and Ctrl+S. But not Ctrl+N. Do you have something?
References:
- Buzzword guys had a lot of problems in keyboard / clipboard handling – http://www.colettas.org/?p=69
- Global keyboard event handling – http://www.adobe.com/cfusion/communitye … postId=304
- Keyboard handling with Flex app – arrow keys should not scroll browser – http://www.nabble.com/Flex-application- … 37485.html
- Moving a sprite with keyboard in Flex – http://codes.widged.com/?q=node/772
Situations / Test Cases:
- Should work: Ctrl + N (New), Ctrl + O (Open), Ctrl + W (Close), Ctrl + Q (Quit)
- Ctrl + C (Copy), Ctrl + V (Paste), Ctrl + X (Cut) – this works with current Flex app. New code must not break it
- Should work on Windows, Mac, Linux
- Should work on Firefox, IE, Safari, Chrome
- What if focus is not in Flex app?
- What if user goes to another window, comes to our app and presses a keyboard shortcut? (this will lose focus)
- Will cut / copy / paste from Browser’s Edit menu work?
JavaScript does it:
- OpenJS – http://www.openjs.com/scripts/events/ke … shortcuts/ – did not work with Command+N
- QooXDoo – http://news.qooxdoo.org/key-event-nightmare-resolved – Full JS library for AJAX, has keyboard handling
- Rajan S – http://santrajan.blogspot.com/2007/03/c … ndler.html – small JS code to capture keys
Flex documentation says:
When handling a key or key combination that the underlying operating system or browser recognizes, the operating system or browser generally processes the event first. For example, in Microsoft Internet Explorer, pressing Control+w closes the browser window. If you trap that combination in your Flex application, Internet Explorer users never know it, because the browser closes before the ActiveX Flash Player has a chance to react to the event.
Notes:
- KeyboardEvent is non cancelable in Flex.
- stopImmediatePropagation(), preventDefault(), stopPropagation() – don’t stop the propagation
- I can detect the keys very well, problem is suppressing the default browser action
- Don’t want to have a full HTML/JavaScript/ExternalInterface handling like Buzzword. Ideally, want to let Flex handle it’s own events, HTML handle browser events and suppress them.
Any ideas?
TIA!
Removing Word special characters from text / XML in PHP
Microsoft Word converts certain characters into "smart characters". Double quotes, dashes (em dash / en dash), bullets and so on.
These characters break PHP's XML handling. (or at least they broke it for me - using simplexml_load_string!).
How do you clean them?
There is an old post that suggests using ereg_replace on a set of characters - essentially converts them to html entities.
Unfortunately, that did not work with me. Since the text is UTF8, the replace logic replaced alphabets too.
I tried a lot to get a solution, but could not find something that would work. Finally, just stripped out all non printing characters except line breaks and tabs.
-
private function cleanWordSpecialCharacters($body)
-
{
-
return $body;
-
}
This too breaks with non English characters. Any suggestions?

