Sunday, October 3, 2010

jQuery webcam plugin


Because of finds like this jQuery plugin is worth `wasting` so much time on reddit.


With jQuery Webcam plugin, a global object window.webcam is available, which provides the following methods:



  • capture()

  • save([file])

  • getCameraList()

  • setCamera([index])



Cant wait to test it with red5 stream capture stuff.

Wednesday, February 24, 2010

PHP: __get && isset


Encountered strange behaviour with php today. If __get is implemented in a class (to provide some properties that are calculated on the fly for example), isset returns false for mentioned calculated properties.



Check out this simple example


class exampleA
{
    __get($property)
    {
        return ($property == 'calculatedProperty')
            ? 42 //do some resource heavy calculation, like meaning of life
            : false;
    }
}
isset($exampleA->calculatedProperty) === false


This is not a bug but a feature according to PHP staff. Btw there is rationality behind it, as there is a __isset in place.

This should work


class exampleB extends exampleA
{
    __isset($property)
    {
        return ($property == 'calculatedProperty') ? true : false;
    }
}
isset($exampleB->calculatedProperty) === true


Maybe this is obvious to everybody, it surprised me at first run, but its correct behavior.

Tuesday, February 2, 2010

Debugging PHP with NetBeans & Xdebug & Ubuntu

It was almost impossible with my config to get working Zend Studio debugging, I think I achieved it once over the years, but it crashed my apache often, so wasnt that good solution neither. For development environment I use ubuntu/debian, vhosts with mod_rewrite, therefore need remote debugging.

Useful links info :

* Configure Xdebug in NetBeans
* Netbeans debugger in general


I had Xdebug set up and NetBeans fully supports it so gave it a try.

in Project Properties->Run Configuration, advanced button

- added Server path/Local path mappings for project ,
- debug Url set to "Ask every time", because I was about to debug remote mod_rewrite urls

For some odd reason, it wasnt working out of the box, Xdebug and NetBeans wasnt communicating well (it probably will work for you out of the box, my machine is cursed :), nothing "easier" that debug the debugger... needed some info

Edited /etc/netbeans.conf and changed php dbgp debug level:

netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true -J-Dorg.netbeans.modules.php.dbgp.level=400"

IDE debug log is accessible at (with output from dbgp): View->IDE log,

Xdebug logs location is at xdebug.remote_log defined in your php.ini

It turned out that it had something to do with my xdebug settings in php.ini. My final settings are:

zend_extension="/usr/lib/php5/20060613+lfs/xdebug.so"

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_log=/var/log/xdebug.log
xdebug.extended_info=1

And it finally found my break point, on custom remote url, hurray :) Long live NetBeans & Xdebug

PHP IDE: NetBeans 6.8 vs Zend Studio 7.1

Little bit of background: I use Zend Studio since version 5.5 and it was released long time ago, I dont even remember the year :). Main point of sticking with Zend was that I am used to eclipse, how it works & its shortcuts/shortcomings. Its a good IDE although it has its dark sides.

It was "interesting" from Zend that with every new major release you got a worse product, until the first minor releases fixed up the bugs (do they even have QA?). Same was with version 7. I got to the point that even autocompletition wasnt working, indexing was still slow as hell, not to mention "luxury" of debugging ... Was thinking is this really that much better than vi :)

Looked around and installed NetBeans 6.8, because read good things about it. Will try to cover my impressions in order of appearance.

  • Marks svn changeset in editor : it has a green bar beside line numbers that shows changes done to working copy, usefull little feat
  • Fast : indexing is remarkably fast (have I mentioned that I come with Zend Studio background :)
  • Code completition working: shouldnt be that big of a feat, if it was working correctly in Zend Studio 7.1, this is what differs an IDE from a really complicated text editor.
  • Eclipse keymapping as option. pleasant surprise, obviously they have encountered similar people as me :)
  • Search & Replace: more convenient on multiple replace runs on same selection (no direction problems like in Zend Studio), was minor but annoying, who encountered it will know what I talk about :)
  • Syntax checks in HTML/JavaScript are better in Netbeans (spotted quite a few errors made in Zend Studio), especially with non standard markup (like Flexy templates)
  • Double clicking selection of strings sometimes selecting slowly/rarely not selecting/sometimes need multiple double clicks in Netbeans, minor but this is better in Zend Studio
  • PHP source formatting is more customizable in Zend Studio, HTML/JS formatting was better in NetBeans
  • Working debugger in NetBeans (details of setup)

Summary


I am using Netbeans 6.8 as my PHP IDE, have I mentioned that it is free?