Tuesday, January 28, 2014

PHP development on mac OS X (Apache, Mysql, MongoDB)

There are several ways how to do PHP development on mac OS X. I used MAMP before, which is really simple to use, basic features are free and no special configuration is needed.  Also virtual hosts are easy to manage.  But I had problem to make mongoDB working.

 After several hours of fight with console and trying about 5 different tutorials  I gave up. Finally I  found great tool  from company softaculous. AMPPS -  http://www.ampps.com is stack of Apache, MySQL, MongoDB, PHP, Perl & Python. All of this tools are ready to use out of the box.

It contains also plenty of web application, which is very simple to install (Joomla, WordPress, Magento, etc)

Default localhost folder is basically /Applications/AMPPS/www/

You can access it via your favourite browser by typing http://localhost

Default MySql credentials are root: mysql and default mongo credentials are admin:admin. I recommend to change it.




Enjoy!

Monday, February 25, 2013

Create desktop icon for PhpStorm in Ubuntu

It's very simple to create desktop icon, or unity launcher.  Run PhpStorm, click to "Tools", then "Create Desktop Entry ...".

If you want to create it for all users, just check the checkbox and click to "OK" button.  To create Unity launcher just drag and drop the icon into launcher bar.

Thursday, November 15, 2012

Disabling translator for Zend_Form_Element


If you use Zend_Form and also Zend_Translate, core Zend functionality tries to translate options of Zend_Form_Element_Select or any other options of elemenet inherited from Zend_Form_Element_Multi. This is not needed in all cases. To disable translator on the element just call function setDisableTranslator like this:


$element = new Zend_Form_Element_Select('my_element');
$element
            ->setDisableTranslator(true)

Wednesday, November 7, 2012

Recursively walk through directory tree

If you need to get all files (or also folders) from some folder and it's subfolders recursively, use following simple construction:

    $folder = '/path/to/folder';

    $objects = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($folder),
        RecursiveIteratorIterator::SELF_FIRST);

    foreach ($objects as $object)
    {
        /**
         * $object is instance of SplFileInfo
         */

        if ($object->isFile())
        {
            echo $object->getExtension();
            echo $object->getRealPath();
        }
    }
Check also PHP manual
     http://php.net/manual/en/class.recursiveiteratoriterator.php
     http://php.net/manual/en/class.recursivedirectoryiterator.php
     http://php.net/manual/en/class.splfileinfo.php







Tuesday, November 6, 2012

How to install PhpStorm on Ubuntu 12.10


If you want to try or use great php IDE PhpStorm follow these steps:


  1. download PhpStorm from http://www.jetbrains.com/phpstorm/download/

  2. unpack downloaded file with following command tar xfz PhpStorm-*.tar.gz (or right click in nautilus and choose "Extract Here")

  3. open folder "PhpStorm/bin/", right click to "phpstorm.sh", choose "properties. In permissions tab mark checkbox "Allow executing file as program"

  4.  install Oracle JDK by following commands:

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer



  5.  double click on file  "phpstorm.sh", click to "run"



Tuesday, November 10, 2009

timestamp from javascript date

Hi everybody, here's simple extension for javascript Date object. It returns timestamp in seconds in local time. Locale is taken from users browser.

Date.prototype.getTimestamp = function () 
{
var date = this;
var timestamp = Math.round(date.getTime()/1000);
timestamp = timestamp - (date.getTimezoneOffset () * 60);

return timestamp;
}


usage is simple:

var new_Date = Date();
alert(date.getTimestamp());

Thursday, June 25, 2009

Foreach equivalent in javascript

foreach function in PHP is very nice and easy to use. I was searching for equivalent in javascritp and there are two possibilities.

1. without jquery:


var new_array = new Array();
new_array[0] = 'foo';
new_array[1] = 'bar';

for (var key in new_array)
{
alert(new_array[key]);
}


2. using jquery


var new_array = new Array();
new_array[0] = 'foo';
new_array[1] = 'bar';

$.each(new_array, function(key, value)
{
alert(key + '=>' + value);
});


if you now another option using some other framework, please add it to discussion, thanks