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: http://quomon.com/question-how-to-check-if-a-javascript-variable-is-defined-891.aspx


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){
keys.push(key);
}
return keys;
}


Or to list them in Firebug:
for(var key in obj){
console.log(key);
}


Solution source: http://stackoverflow.com/questions/208016/how-to-list-the-properties-of-a-javascript-object

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:
$(document).ready(function(){
$("#contactForm").bind('invalid-form.validate',
function(event, validator) {
alert('validation failed!');
}
);
});


Regularly you would add this on initialization:
$(document).ready(function(){
$('#contactForm').validate({
invalidHandler:
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: http://code.google.com/p/android/issues/detail?id=5880

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


or

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?:

If
<?php
$im = new imagick('file.pdf[0]');
?>

breaks your server. Try installing the latest Ghostscript windows binaries: http://pages.cs.wisc.edu/~ghost/

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>
gs_std_e.ps 13 2588248 1246221 1461800 170712 true 1133 5 <12>
gs_il1_e.ps 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>
gs_btokn.ps 67 2652032 1311993 1461800 172336 true 991 4 <63>
gs_dps1.ps 73 2652032 1313338 1461800 172336 true 991 4 <63>
gs_dps2.ps 78 2652032 1315345 1461800 172336 true 991 4 <63>
gs_type1.ps 84 2652032 1316871 1461800 172336 true 991 4 <63>
gs_lev2.ps 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 gs_patrn.ps:
%%[ 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>
gs_std_e.ps 297645 2776784 1434941 1508160 224232 true 993 6 <70>
gs_il1_e.ps 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>
gs_btokn.ps 297689 2840568 1500739 1508160 225856 true 991 6 <121>
gs_dps1.ps 297694 2840568 1502084 1508160 225856 true 991 6 <121>
gs_dps2.ps 297700 2840568 1504091 1508160 225856 true 991 6 <121>
gs_type1.ps 297705 2840568 1505617 1508160 225856 true 991 6 <121>