Wednesday, February 20, 2013

How to get list of available timezones in php

<?php
    print_r( DateTimeZone::listIdentifiers( ) ); 
?>

Saturday, February 16, 2013

Some basic UNIX commands

Today I will write down some basic UNIX commands.
"cd -" will switch you to the previous directory.
testuser@test:~/Downloads$ cd ../Desktop/
testuser@test:~/Desktop$ cd -
/home/testuser/Downloads
testuser@test:~/Downloads$ 

"cd ~" or "cd" will switch you to your home directory.
testuser@test:~/Downloads$ cd ../Desktop/
testuser@test:~/Desktop$ cd -
/home/testuser/Downloads
testuser@test:~/Downloads$ 

"pwd" (print working directory) is used to output the path of the current working directory.
testuser@test:~/Desktop$ pwd
/home/testuser/Desktop

Monday, December 10, 2012

How to found out extra fields in Symfony2 form?


If you encounter this error message while working with Symfony2 forms, follow my advice.
This form should not contain extra fields.
This way to find out the fields that are considered "extra" is very simple. I use the code quite frequently. Here it is:
$data = $request->request->all();

print("REQUEST DATA<br/>");
foreach ($data as $k => $d) {
    print("$k: <pre>"); print_r($d); print("</pre>");
}

$children = $form->all();

print("<br/>FORM CHILDREN<br/>");
foreach ($children as $ch) {
    print($ch->getName() . "<br/>");
}

$data = array_diff_key($data, $children);
//$data contains now extra fields

print("<br/>DIFF DATA<br/>");
foreach ($data as $k => $d) {
    print("$k: <pre>"); print_r($d); print("</pre>");
}
...
$form->bind($data);
Have a nice day!

Saturday, November 24, 2012

How to install Oracle Java 7 in Ubuntu 12.04

First of all remove JDK packages if they were installed:
sudo apt-get purge openjdk* 
After that:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
Thanks for this article. It helped a lot.

Saturday, November 3, 2012

PHP can be inconsistent

PHP can be inconsistent. Good PHP-programmers know its wayward temper. It is the payment for the seeming simplicity at the beginning. A naive beginner can be captivated by the absence of restraints. But experienced programmers know that the absolute liberty can cause a chaos.

In honor of Halloween some blogs published interesting scary examples of the PHP behavior. I liked this one and want to share:

Spooky Scary PHP

Let's read and remember: there is no perfection in our world and so let's use our sense of humor not to conclude bad things about the language. PHP has also the good features that make it one of the most used programming languages.