Sunday, March 25, 2012

phpunit with Netbeans on Ubuntu

As a newbie to PHP I got lots of headache on setting up phpunit. It is a little tricky to setup phpunit on Ubuntu since the documentation about this is not accurate. Make some notes here for the future references.

To install phpunit, the only way is to use PEAR. However I got annoying errors during the process.

1. apt-get does not install latest Pear, it only install the PEAR up to verision 1.9.2 which will be complained then when you are installing phpunit. Use this,
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
2. Then install phpunit
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
3. Setup netbeans for phpunit
The right path of phpunit is /home/xxx/pear/bin/phpunit not /usr/lib/php/PHPUnit as documented on neatbeans official website.

Thursday, March 8, 2012

Remote access MySQL

Recently I come cross MySQL which I have not used much before. To connect it on localhost is without any issue till I want to move the MySQL to my EC2 instance.

To make the magic happen, 2 things need to check.

1. mysql only allows localhost to access by default.
If this step is missing the error below will happen.
ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx'
Fixing:

open mysql config file by    sudo nano /etc/mysql/my.cnf comment out the line    bind-address=127.0.0.1 and
skip-networking if existing
Or we can specify a ip say 10.0.0.2 for bind-address as a result only this ip 10.0.0.2 can access mysql. And only one ip can be bound!


2. Root user can not be used to log in remotely by default.
If this step is missing the error below will happen.
ERROR 1130 (HY000): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
Fixing:

Make sure to modify root user's privileges to allow remote user login mysql as root user. Don't recommend this way for security reasons. A better is to create another user and enable it to access mysql remotely.

Monday, March 5, 2012

Apache Virtual Hosts - permissions

See this article
https://articles.slicehost.com/2007/9/18/apache-virtual-hosts-permissions

HOWTO: Install xdebug for PHP5

Here is a mini-howto in how to install the xdebug extension with PHP5 in Ubuntu 7.04

This will install xdebug 2.0 (or whatever is latest version in PEAR repository when you try this).

It is assumed you have Apache2 + PHP5 working already.

sudo apt-get install php5-dev php-pear

Now install xdebug thru PECL.

sudo pecl install xdebug

Now we need to find where xdebug.so went (the compiled module)

martin@martin-dev:/$ find / -name 'xdebug.so' /dev/null /usr/lib/php5/20060613/xdebug.so

Then edit php.ini:

sudo gedit /etc/php/apache2/php.ini

Add the following line:

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

Then restart apache for changes to take effect

sudo /etc/init.d/apache2 restart

Check phpinfo() to make sure the extension is loaded correctly. The following line should have been appended to the copyright lines:

with Xdebug v2.0.0, Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, by Derick Rethans

For more information about xdebug configuration and usage, please read the official documentation, found here: http://xdebug.org/docs/

check http://ubuntuforums.org/showthread.php?t=525257

Tuesday, December 20, 2011

Prototype of Javascript

Recently I just try to dig my knowledge of JavaScript deeper. Prototype is a very important concept of JavaScript and is the key to program JavaScript in object-oriented way. After reading some articles I did the code snippets for experiment.

Reference articles:
Understand JavaScript Article
OO programming in JavaScript

My experiment code:

<script type="text/javascript">
    function employee(name,jobtitle,born){
       this.name=name;
       this.jobtitle=jobtitle;
       this.born=born;
    }
    var fred=new employee("Fred Flintstone","Caveman",1970);

    employee.prototype.salary=300;

    document.write(fred.name + "'s salary:" + fred.salary);
    document.write('<br/>');

    var jack = new employee("Jack","Developer",1983);
    jack.salary=100;

    document.write("Prototype(defaultsuper class static) salary: " + jack.__proto__.salary);
    document.write('<br/>');
    document.write(jack.name + "'s salary:" + jack.salary);
    document.write('<br/>');

    employee.prototype.aftertax = function(){
        return this.salary * 0.8;
    };

    document.write(jack.name + "'s after tax salary: " + jack.aftertax());
    document.write('<br/>');
</script>

Wednesday, November 9, 2011

Android crash report

There is a great library called "ARCA" for collecting android crashes on the fly.

It is open source. What you need to do is just go to the link below and use it for free and it is super easy!

http://code.google.com/p/acra/