Thursday, December 30, 2010

New Firebug Autocomplete annoying with jQuery

Firebug is a great tool for web developers to debug webpages.

If you have installed the latest update from Firefox' Add-ons menu and tried to write jQuery commands into the console/command line of firebug you might have run across an annoying problem.

Firebug tries to autocomplete $, $(, $(', etc. adding $ and completing ' after the next character. Basically you have to keep hitting escape or delete to write your jQuery statement.

This problem is luckily fixed in the latest beta release. It is not available through the add-on menu in Firefox, but can be downloaded directly from the Firebug website. So head over to and download it.


Saturday, December 18, 2010

Windows 7 middle click mouse doesn't close tabs

In Firefox on Windows 7, closing tabs by clicking on them with the middle mouse button doesn't work. You only get the Alt+Tab 'window' to switch between programs.

To fix this:
- Go to Control Panel
- Select 'Hardware and Sound'
- Select 'Mouse' under 'Devices and Printers'
- In the drop-down box for 'Wheel button' change it from 'Flip' to 'Middle-click'
- Press OK

This should now enabling closing tabs with clicking the middle mouse button.

Sound cut-off in Deus Ex 1

Playing the old classic on Windows 7 gave me some trouble with speech being cut of about 1 second before it should have finished.

Read a few places about this problem and some suggestions about changing latency to 46 or 60 (in the deusex.ini file in the deusex/system folder), but this didn't work for me.

Changing from using Direct3D Support to OpenGL as the video device did.
Here is how:
- Open 'Deus Ex Safe Mode' from start menu
- Select 'Change your 3D video device'
- Select 'show all devices'
- Select 'OpenGL Support' and press next
- Accept settings suggestion (can be changed in-game later)

If this doesn't work for you, here are some forums with suggestions for how to get it to work with Direct3D: (since DeusEx runs on the Unreal rendering engine)

Saturday, November 13, 2010

Workaround for Ubuntu install hangs on forward button

Have you tried installing Ubuntu using the official guide where you create a Live/Install USB using Universal USB Installer in Windows? Did the install not continue after pressing continue when selecting language or when selecting keyboard layout?

This seems to be because of gparted/parted not being able to start. It affects installing from Ubuntu 10.4-netbook 10.10-netbook, and 10.10-desktop.

A workaround is to create the Live/Install USB in Ubuntu.

You will need two USB drives (including the one you created in windows).

Start the Live session, get a copy of the iso you put on the USB onto the computer (either from a different machine or download it). Open the startup disk creator in you Ubuntu Live session (System->Administration->Startup Disk Creator). Select the iso file and the other USB drive.
Create the startup disk. Shut down, remove the USB created in windows. Start up using the USB created in Ubuntu to boot from. Install from the USB created in Ubuntu. The forward button should now work.

Sources: A Ubuntu bug report that I cannot find again. Please tell me if you have seen it so I can give credit.

Tuesday, October 26, 2010

Check if a Zend_Db_Table_Rowset is empty

When retrieving data from the database using Zend Framework (using find or fetchAll functions) you will be presented with a Zend_Db_Table_Rowset. To check if it is empty it would seem logical to use the empty function like when checking an array. This will not work.

To check if a Zend Rowset (Zend_Db_Table_Rowset) is empty you need to use the count function. e.g.:
if(count($result) > 0) {
//Do something

Or using the Rowsets own count function (which does not iterate through all the elements apparently):
if($result->count() > 0) {
//Do something

See for a discussion on the topic.

Saturday, September 25, 2010

jQuery value and text of selected option in selectbox

You often need the value and text of the selected option of a select box. $("#selectboxid").val() returns the value of the selected option and $("#selectboxid :selected").text() returns the text.

Solution found at:

Monday, August 23, 2010

Hilarious review of Windows 7

A bit late, but I ran across this hilarious review of 'Windows 7'.

Check out what windows he has open in the task bar and also read the comments. Very funny. Enjoy! :)

Saturday, July 24, 2010

Sending images in MMS messages with Froyo on Nexus One

Upgraded to Android 2.2 Froyo and suddenly can't send images in MMS messages? (Mine just said Sending in the message view and never changed to Sent)
The problem could likely be that the images are too large to be sent (carriers usually have a max limit on image size or upload is so slow the it can't finish with a large image) and Froyo dosen't resize the image like 2.1 Eclair did.

To send images you need to crop them first. This will create a new image from a subsection of the original. (Not destroy the image being cropped tho). Do like this:

Open Gallery and open the image you want to send. Press the More button and choose Crop. Select the portion of the image you want and press Save.
You will now have the original plus a new smaller image.

Then, for the new image, do like usual, press Share and Messaging or choose Menu and Attach from inside a message.

Friday, July 16, 2010

Disabling spellchecker in NetBeans

I started using NetBeans and quickly encountered the annoying red underlining of all words in my code. Disabling the spellchecker feature in NetBeans 6.9 is NOT done by deselecting all files in the Options -> Miscellaneous -> 'Spellchecker' tab.

For NetBeans to really understand that you don't want spellchecker, do the following:
Go to Tools -> Plugins -> Installed tab -> select the spellchecker plugin -> press Deactivate -> restart NetBeans

Alternatively try adding the file type you are working on (if NetBeans doesn't recognize it) by following this post:

Filetypes in NetBeans

Working with ex. .tpl files? Getting NetBeans to recognize most of the code (at least the HTML, JS, and CSS), and do code highlighting on it, is as easy as adding 'tpl' as an associated file type:


UPDATE 24.03.2011: NetBeans have had a Smarty (.tpl) plugin for a while, but it hasn't been very good. Now it's getting much better. You can download it from withing NetBeans, go to Tools > Plugins > Available Plugins, search for smarty, check the checkbox beside the plugin and press Install.

(Make sure you have NetBeans Beta Update Center (See Settings tab of Plugins window URL: for NetBeans 6.9))

NetBeans' blog posts about Smarty plugin: and

Alternative to Eclipse IDE

So, getting tired of eclipse's infinite number of program/system halting tasks?

Maybe you should try Netbeans, it's not just for Java development. There are also plugins for PHP, Ruby, C/C++, and Groovy (whatever that is).

Check it out at:

Saturday, July 10, 2010

Opera icon in ubuntu gone

Did you have a shortcut to launching Opera and have it's icon disappear when upgrading your Opera installation? (e.g. to 10.60).

No worries, just open the shortcut properties (use if it is a menu or panel shortcut). The location you want to look for the icon is:
Select the Opera_256x256.png file.

Voila. :)

Friday, June 25, 2010

Accessing elements cross-frame (HTML)

I know it is a hassle, but sometimes you need to maintain legacy code and come across someone using frames. To access elements in other frames you need to go to the top and 'back down into the frame you want':

<name of parent frame>.<name of sibling frame>.element
parent.mainframe.location.href = 'next.html'

Remember javascript variables that should be accessible cross-frame need to be global (not declared with var (var variablename)). Also for jQuery you use the document as a root to get elements from. e.g.:
parent.mainframe.document.myVar = 5;

Check out these pages for more information:,

Sunday, May 23, 2010

How to get Flash on Froyo on the Nexus One

First of all you need to upgrade to Android 2.2 Froyo. Follow the guide at’s-how/.

Next, you would think Flash was installed out of the box. It is not. To install it go to the Market, search for flash and select "Flash Player 10.1 BETA" (with an Adobe 'f' icon). Install this. Now you should be able to view flash content in your browser.

Solution found at:

Wednesday, May 5, 2010

Preventing web vulnerabilities

Two nice sites to check out when working with public web pages are:

Both are useful for learning about how your webpage can be exploited and how to prevent it.

Postscript delegate failed for ImageMagick PHP library

For ImageMagick in PHP through the library Imagick the following error may occur for versions ImageMagick-6.3.5 to ImageMagick-6.4.2:
Postscript delegate failed `': No such file or directory

This is a bug and the error appears when one is trying to use the readimageblob function to read a PDF file.

The fix has been posted and the bug is no longer present. See So to fix it get the latest release from

Some installations (like server environments), haven't got the latest version and cannot install it. For these, it is possible to work around this bug, by using a temp file.

So instead of:
$im = new Imagick();

$im = new Imagick();
$temp = tmpfile();
fwrite($temp, $data);
fseek($temp, 0);

(This would typically be followed by for example:
$data = $im->getimageblob();


If this doesn't fix it for you, also check out:

Saturday, May 1, 2010

Setting Ubuntu menu item icon

Every tried setting the icon for a menu item on the Ubuntu start menu and discover that ubuntu can't find your icon files?

First of all, to get to the place where you change the icon:
Right click 'Applications' menu on the taskbar -> select 'Edit Menus' -> find your menu item in the list -> click 'Properties' -> click the current icon

When you select Browse... and go to the directory where your icons are located it doesn't show any files there. The key is to press Open when you are in the directory where the files should be. A new window will open showing the files that can be used as icons.

"The image files must be one of the types: PNG, XPM, or SVG, and the extension must be ".png", ".xpm", or ".svg" (lower case)." Source:

Thursday, April 29, 2010

Undefined properties and showing all properties for Javascript/jQuery objects

To check if a Javascript/jQuery variable has been set use the following code:

if(typeof(myVar) !== 'undefined');

Solution source:

To get all properties of a Javascript/jQuery object (to find what methods and values can be set for example) use the following function:

var getKeys = function(obj){
var keys = [];
for(var key in obj){
return keys;

Or to list them in Firebug:
for(var key in obj){

Solution source:

Wednesday, April 21, 2010

Add InvalidHandler after jQuery validator initialization

If you have a problem where you need to add the option 'invalidHandler' to your jqueryValidate (jQuery Validation Plugin) after it has been initialized, this is how it can be done:
function(event, validator) {
alert('validation failed!');

Regularly you would add this on initialization:
function(event, validator) {
alert('validation failed!');
rules: {}

Note: invalidHandler will be called when validation of form fails on submit (e.g. values for a field is missing or such).

This might work for other options of the jqueryValidate plugin, but I'm not sure which property to use. I found the property to bind to in the jquery.validate.js file, you might want to look there.

Thursday, April 8, 2010

Mount Nexus One SD card on PC with Ubuntu Linux

If you are trying to connect the Nexus One to Ubuntu via USB and it keeps disconnecting and you get the following messages when you run dmesg in a terminal:

[14082.844359] sd 23:0:0:0: [sdb] Sense Key : Not Ready [current]
[14082.844371] sd 23:0:0:0: [sdb] Add. Sense: Medium not present
[14082.844386] end_request: I/O error, dev sdb, sector 24
[14082.854502] sd 23:0:0:0: [sdb] Device not ready
[14082.854512] sd 23:0:0:0: [sdb] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE

The fix is turn on USB debugging for the Nexus One:

On the Nexus One, go to Settings -> Applications -> Development and check USB debugging and say OK to the warning. Connect the Nexus One via USB to the Ubuntu machine and it should connect fine.

Solution source:

Wednesday, April 7, 2010

IE javascript error "Invalid argument"

If you get one of the following errors in IE when running jQuery and/or jqGrid:

Message: Invalid argument.
Line: 112
Char: 247
Code: 0
URI: http://.../jquery-1.4.min.js


Message: 'p.cellLayout' is null or not an object
Line: 10
Char: 56008
Code: 0
URI: http://.../jquery.jqGrid.min.js

It is quite possibly that you are trying to set something to null. Check if any of the javascript variables in the page are null and being used as parameter to call a jqGrid or jQuery function.

NOTE: IE often doesn't specify the correct line number. So even though it may say line 10, the error could be somewhere else, this is why it is so hard to debug IE. The reason is dynamic pages where javascript libraries and content is added on the fly, IE can't keep up with this.

Tuesday, April 6, 2010

Imagemagick reading pdfs under Apache and Windows

Getting "Apache HTTP Server has stopped working" when trying to read a pdf file using the PHP imagick class when running Apache?:

$im = new imagick('file.pdf[0]');

breaks your server. Try installing the latest Ghostscript windows binaries:

You should also have gotten an error if you tried to convert the pdf in commandline:
Unrecoverable error: undefinedresource in setcolorspace
Operand stack:
--nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- DefaultGray ColorSpace
START 0 2568152 1228867 1461800 167944 true 1134 5 <9>
END PROCS 6 2568152 1240166 1461800 169328 true 1133 5 <9> 13 2588248 1246221 1461800 170712 true 1133 5 <12> 20 2588248 1248404 1461800 170712 true 1133 5 <15>
END FONTDIR/ENCS 25 2588248 1248582 1461800 170712 true 1133 5 <21>
END DEVS 31 2591744 1255606 1461800 170712 true 1133 5 <21>
END STATD 37 2591744 1262786 1461800 172336 true 1133 5 <45>
END GS_FONTS 44 2631936 1293632 1461800 172336 true 1134 5 <51>
END BASIC COLOR 50 2631936 1300193 1461800 172336 true 1132 5 <54>
END LEVEL 1 COLOR 55 2631936 1301921 1461800 172336 true 1132 5 <57>
END IMAGE 61 2652032 1308551 1461800 172336 true 1132 5 <60> 67 2652032 1311993 1461800 172336 true 991 4 <63> 73 2652032 1313338 1461800 172336 true 991 4 <63> 78 2652032 1315345 1461800 172336 true 991 4 <63> 84 2652032 1316871 1461800 172336 true 991 4 <63> 93 2672128 1334882 1508160 219096 true 991 4 <63>
BEGIN RESOURCES 96 2672128 1337010 1508160 219096 true 991 5 <64>
END CATEGORY 100 2672128 1338270 1508160 219256 true 991 6 <64>
While reading
%%[ Error: typecheck; OffendingCommand: get ]%%
START 297633 2756688 1417603 1508160 221464 true 995 6 <67>
END PROCS 297638 2756688 1428886 1508160 222848 true 993 6 <67> 297645 2776784 1434941 1508160 224232 true 993 6 <70> 297649 2776784 1437124 1508160 224232 true 993 6 <73>
END FONTDIR/ENCS 297653 2776784 1437302 1508160 224232 true 993 6 <79>
END DEVS 297657 2780280 1444326 1508160 224232 true 993 6 <79>
END STATD 297662 2800376 1454858 1508160 225856 true 993 6 <103>
END GS_FONTS 297667 2820472 1482354 1508160 225856 true 993 6 <109>
END BASIC COLOR 297672 2820472 1488915 1508160 225856 true 991 6 <112>
END LEVEL 1 COLOR 297677 2840568 1493995 1508160 225856 true 991 6 <115>
END IMAGE 297683 2840568 1497297 1508160 225856 true 991 6 <118> 297689 2840568 1500739 1508160 225856 true 991 6 <121> 297694 2840568 1502084 1508160 225856 true 991 6 <121> 297700 2840568 1504091 1508160 225856 true 991 6 <121> 297705 2840568 1505617 1508160 225856 true 991 6 <121>

Friday, March 26, 2010

Custom message for Zend CSRF token

Ever see the following message when using Zends CSRF token?:

The token 'cea65eff4f464dsl57729a21fbd56aea' does not match the given token 'd2479b415baafe5791ase68f85122828a'

Wouldn't it be more useful to have an intelligible message? To set custom messages for the Zend_Form_Element_Hash do the following:

$this->addElement('hash', 'csrf_token', array(
'salt' => get_class($this) . '',
'timeout' => ,
'errorMessages' => array('Identical' => 'Form has timed out (probably), or you are attempting a cross-site request forgery. Please submit form again.'),

'Identical' is the validator that Zend_Form_Element_Hash uses. So adding the errorMessages line when creating the hash should do the trick.

There is probably a setErrorMessages() method also, but I haven't tried this.

Thursday, February 11, 2010

Zend PHPUnit check elements set by controller

When testing output from controllers in Zend using the Zend PHPUnit one might want to check the elements set by the controller, if they have the right values or exist at all.

Anything below top level form ($this->view->form = $form; in controller) one needs to use the getElement() function like one would in the controller. getSubForm() is also valid if there are subforms:

public function testRegisterViewObjectContainsProperties() {
$controller = new RegistrationController(


$username = $controller->view->form->getSubForm('userpass')->getElement('username'); seems to be useful.

Zend PHPUnit posting to controller

Sending data to the controller to check what you get back can be tricky. Especially if you have subforms or file uploads.

Here is how if you have subforms (in this case a select and a multiselect in separate subforms):
public function testPostMissingFilledFields() {
$this ->request ->setMethod('POST')
//Selected element with value '2'
'firstLayerSubform1' =>
array('secondLayerSubform1' =>
array('thirdLayerSubform1' =>
array('select' => array('2')))),
//Selected elements with values 1159 and 1161
'firstLayerSubform2' =>
array('secondLayerSubform2' =>
array('thirdLayerSubform2' =>
array('multiselect' => array('1159', '1161')))),

Useful functions to see what you submit look like are:
In Test file:
In controller:

If you find a way to check for uploaded files please tell me. :)

PHPUnit with Zend View

When you want to check if important objects in Zend Views show up using PHPUnit testing can be used. In my case I have a registration form which repopulated the fields if one was missing or if anything was incorrectly filled in.

There seem to be multiple ways to select elements in the DOM:
- assertQuery - CSS selector
- assertXpath - Xpath selector
- strpos (!) - search through the html as a string

I first tried CSS selector:
$this->assertQuery('input[id="username"][value="test1"]'); //username
$this->assertQuery('input#username[value="test1"]'); //username
$this->assertQuery("input[value='']"); //emailaddress

All should work, but there are different problems. The two first selections don't work, event though they work in firebug. The last line doesnt work either because of the period '.' which gives a "DOMXPath::query(): Invalid predicate" error.
Seems Zend PHPUnit converts from CSS to Xpath selectors and doesnt manage to do it right.

Therefore using Xpath directly is better. (Download the FireXpath extension to Firebug for Firefox and play around to learn it (also is good)). So here's Xpath:
$this->assertXpath("//input[@id='username'][@value='test1']"); //username
$this->assertXpath("//input[@id='emailaddress'][@value='']"); //emailaddress

Works out of the box.

Alternatively you can search through the html code linearly:
$this->assertTrue(strpos($this->_response->getBody(), '') !== false); //emailaddress
However, if anything changes in the html code, the test might fail.

Solution sources:,, others I cant remember.

Friday, February 5, 2010

Atomic transactions in Zend

If you have many database changes where all need to succeed or none at all do the following:

//Get a hold of the database adapter:
$model = new Model_DbTable_();
$adapter = $model->getAdapter();
try {
//Do inserts, updates, deletes etc.
//Commit the changes and do rollback if it fails:
catch (Exception $e) {
//Print errors
$echo $e->getMessage();

or similarly:

try {
$db->insert('server', array('key' => 'foo', 'value' => 'bar'));
$db->insert('server', array('key' => 'bar', 'value' => 'baz'));
$db->insert('server', array('key' => 'baz', 'value' => 'foo'));

catch (Exception $e) {

Solution found:

'not found in haystack' error in Zend

If you get a '%value%' was not found in the haystack' error when using select boxes in Zend, add the following to the form element:


or directly when creating form:

$form->addElement('multiselect', 'elementname', array('RegisterInArrayValidator' => false));

Solution found at: