Mcloide's resources library

All about PHP, Javascript, concepts and development

Samba and Vista

Posted by mcloide on November 20, 2009

I was having this little bit of trouble with Windows Vista accessing my files on the SAMBA server.

After a little research I have found a great post wich gives a great trick to work out the imcopatibility issues between Vista and Samba.

Follow the link: Get Vista and Samba to work

Posted in linux | Tagged: , , , , | Leave a Comment »

Back to old reliable Xubuntu 9.04

Posted by mcloide on November 19, 2009

Yesterday, after spending some hours to get all development eviroment set, I have managed to finish the installation of the good and old Xubuntu 9.04.

It’s a bit faster than the 9.10 and so far, no errors what so ever. Next step, wait for the next stable release for Xubuntu and check out some forums before the upgrade.

Posted in linux | Tagged: , , , | 3 Comments »

Downgrading your Xubuntu Core

Posted by mcloide on November 17, 2009

I’m having problems with my new updated Xubuntu core as I have mentioned at my previous post.

After some good search and reading I have found a possible solution. There is a good way to downgrade your core without major incidents.

Here are the steps (got from Ubuntu Forums)

1. Reboot your machine and when Xubuntu is about to start hit ESC (or the key set to show the menu options at boot). You should see about 3 to 5 entries where one of them should be a older version of your core. Choose the right version and you are done.

Now if you don’t see the right core, then this is what you need to do:

1. Using Synaptic install a linux-image (use linux-image to search in synaptic) that reflect the right core that you want to downgrade. Take note on the information about the core. Ex.: 2.6.31-14-generic

2. Open your menu list at your Grub boot menu and see what options do you have to start your Xubuntu (use terminal).

mousepad /boot/grub/menu.lst

Now add the new menu core installed following the same format as the other ones.

title        Ubuntu 9.10, kernel 2.6.31-14-generic
root         ()/ubuntu/disks
kernel       /boot/vmlinuz-2.6.31-14-generic root=UUID=xxxxxxxxxxxxxx loop=/ubuntu/disks/root.disk ro ROOTFLAGS=syncio quiet splash
initrd       /boot/initrd.img-2.6.31-14-generic

title        Ubuntu 9.10, kernel 2.6.31-14-generic (recovery mode)
root         ()/ubuntu/disks
kernel       /boot/vmlinuz-2.6.31-14-generic root=UUID=xxxxxxxxxxxxxxx loop=/ubuntu/disks/root.disk ro ROOTFLAGS=syncio  single
initrd       /boot/initrd.img-2.6.31-14-generic

Remember to always have your files backup. No matter if you are on Windows, Linux or Mac, a full recovery can always brings unexpected results (even knowing that on Linux is mostly likely to have a smooth transition).

Posted in linux | Tagged: , , , , , | 1 Comment »

Don’t upgrade to Xubuntu 9.10 Karmic

Posted by mcloide on November 16, 2009

I have been working with Xubuntu for a while now and so far it has worked wonders at a point which I haven’t used Windows for months.

About 2 weeks ago I have upgraded my current Xubuntu 9.04 to 9.10 and this has become my biggest mistake ever.

Since the upgrade this is the kind of errors that I have been getting:

  • Skype doesn’t have any more sounds or can’t find mic
  • Applications Bar gone
  • Turning off or rebooting fails drastically making a hardware shutdown and power up necessary
  • And the latest, my XServer is gone (all the user interface that looks like Windows)  and with it the login screen (everything now is terminal)

From all the troubles so far, the Xserver is by far the worst. Since it is gone I haven’t been able to run it using my user and to execute it I have to run everything as root.

After making a short trip to Windows and checking Google to find some solution at least for the XServer, I could manage to make the everything come back, but all using root.

If you are about to upgrade DONT – This can be my best advise for you.

But if you are finding yourself in the same position that I was today then this is what you should do (you should be seeing only terminal at your screen):

  1. execute display – if your x-server have a problem, then it will warn you about
  2. now execute startx – this will start the xserver and all display options for your user. If you can see your Desktop, yeay, nothing more is necessary, otherwise you will need to run it as root (sudo startx)

Now is waiting for a good release of Xubuntu to solve this issues or reinstall everything from scratch.

Posted in PHP | Tagged: , , , , , , , | 6 Comments »

Face detection with PHP

Posted by mcloide on November 10, 2009

digital face @copy bitsys.gr

Today checking my daily Tweets for development I have found a very good tutorial about face detection using the GD library from PHP.

Karthik Tharavaad have developed a class that will allow you, with very little commands, to detect a face in a photo. As shown on the end of the post, it works well.

More at the post: @Karthik Tharavaad – Face detection with PHP

Post source got from Twitter: @planetphp

Posted in PHP, development, resources | Tagged: , , , , , , , | Leave a Comment »

Working with Google Charts and Visualization API

Posted by mcloide on November 9, 2009

Julian has just added a post with a good tutorial of how to use the Google Charts and Visualization API.

Check it out: aHref: Working with Google Charts and Visualization API

Posted in development, google | Tagged: , , , | Leave a Comment »

How to solve the disapearance from the applications bar / menu from Xubuntu 9.10

Posted by mcloide on November 5, 2009

For the first time today I have got a small issue that was painful to solve.

It’s quite hard to walk around on Xubuntu when you just can’t see the application bar and don’t have many shortcuts on Desktop to help you out.

Here is the situation:

- Pidgin Msgr or any other application suddenly stopped and forced the system to a lock.
- Forcing a reboot is necessary
- After successful reboot and logon, all you can see is the desktop icons. No application bar, no applications menu, nothing.

How to solve:

1. Open Terminal – if you don’t have it opened, click with the right click of the mouse on desktop and you will see as one of the options the terminal.

2. Now check if your applications menu, XFCE is running:

pgrep -l xfce4-panel

2.1 If there was something there, then you would see something as:

5535 xfce4-panel

2.2 Only do this next step if you have XFCE running

xfce4-panel --exit

3. Backup the configuration just to be safe:

cp ~/.config/xfce4/panel/panels.xml ~/panels.xml.old

4. Remove the old file

rm ~/.config/xfce4/panel/panels.xml

5. Now you can either do 2 things:

  • Run the applications menu from terminal and whenever you close the terminal so the applications menu will be closed
  • Add a launcher on desktop (recommended)

If you are going to run the applications menu from the terminal, then all you need to do is:

xfce4-panel

Now adding the launcher is a bit easier and whenever this happens again, you can simply click on the launcher on desktop.

Right click on an empty space on desktop and choose launcher. For the name and command you will need to enter:

xfce4-panel

Choose an icon to identify it (if you want to) and your application shortcut is ready. Double click on it and the menu should automatically appear up top.

Note: most of these steps where given by K.Mandla at http://ubuntuforums.org/showthread.php?t=312394

Posted in PHP | Tagged: , , , , , , | 1 Comment »

Instaling Zend Studion on Ubuntu 64

Posted by mcloide on November 3, 2009

Julian just came with a detailed tutorial of how to install Zend Studion on the 64 edition of Ubuntu.

It has both solutions, installing the normal version and the 64 version of Zend Studio.

Check it out: http://www.smooka.com/blog/2009/11/02/installing-zend-studio-on-ubuntu-64-bit/

Posted in PHP | Tagged: , , , , | Leave a Comment »

PHP Basic Series – Playing with XML

Posted by mcloide on November 2, 2009

XML – Extensible Markup Language – is one of the most flexible type of files that you can use at your application. It can easily allow 2 different applications to communicate, it can save data, store configuration information and much more.

PHP has 2 great libraries to work with XML:

  • DOM – Document Object Model: A great library to strongly manipulate XML in all levels
  • SimpleXML: A “simple” xml library that will help you to easily manipulate XML files until a certain level (for instance you can’t delete an item on a XML with the SimpleXML).

Even knowing that SimpleXML does not handle everything it is by far the best library to work with. Is very light, the performance is amazing and you can handle the minimal necessary which is creating, reading, adding and, with a little trick, deleting nodes. The best feature of the SimpleXML library is the XPath. XPath provides you with a small “regex” interpretation to easily let you get the contents and attributes from a given node / parent etc.

[Note:] SimpleXML only supports well-formed XML files / strings. Only by loading it, PHP already gives a great tool to validate XML.

First let’s work with a small XML file:

<?xml version="1.0" encoding="utf-8" ?>
<states>
<!--US States and Territories-->
 <state abbreviation="AL">Alabama</state>
 <state abbreviation="AK">Alaska</state>
 <state abbreviation="AZ">Arizona</state>
 <state abbreviation="AR">Arkansas</state>
 <state abbreviation="FL">Florida</state>
 <state abbreviation=IN>Indiana</state>
 <!-- list continues -->

</states>

Copy this code and paste inside a text file and name it as you please (states-provinces.xml / states-provinces.txt / etc). Since SimpleXML allows to read the XML from a string, we will be seeing both codes here in this post.

First let’s load the created file into the SimpleXML object.

<?php
// reading a xml file with simple xml
$xml = simplexml_load_file('states-provinces.xml');
?>

Or, if you want to load it from a string:

<?php
// reading a xml string with simple xml
$xmlString = '
<states>
<!--US States and Territories-->
 <state abbreviation="AL">Alabama</state>
 <state abbreviation="AK">Alaska</state>
 <state abbreviation="AZ">Arizona</state>
 <state abbreviation="AR">Arkansas</state>
 <state abbreviation="FL">Florida</state>
 <state abbreviation=IN>Indiana</state>
 <!-- list continues -->

</states>';
$xml = simplexml_load_string($xmlString);
?>

After this point, all the remaining procedures for SimpleXML are the same and so it’s the structure.

Once created SimpleXML will load all XML contents to an array of SimpleXML objects.

As any other method, when manipulating is necessary that the focus be at:

  • read
  • write
  • delete

SimpleXML does read and write pretty well, but when it comes to delete is a bit tricky.

Reading:

To read attributes and values from a given item is pretty simple and the library offers you 2 ways to access the element node.

  1. Accessing in an as array style
  2. Accessing using XPATH

To access in an array style all you need to do is use the position of the element in the array (if you know it) or call the children method inside a loop.

<?php
foreach ($xml->children() as $node) {
 // to read the state name value all you need is to convert the node to string
 $name = (string) $node;
 // to read the state abbreviation is even simpler, call the attribute using the array feature
 $abbreviation = $node['abbreviation'];
 // just to print
 echo "name: {$name} abbrv: {$abbreviation}
";
}
?>

Seems simple, but when you are working with XML files that have 3, 4 childnodes levels, it becomes more complicated and more intensive to get to the results. In cases like this we use the XPATH to access the elements of an XML in a fast way.

As mentioned before, the XPATH will work as a small REGEX to get to the element and load its features.

<?php
$node = $xml->xpath('//state[@abbreviation=\'IN\']');
?>

As simple as it looks, with XPATH, you can easily access the Indiana node value without having to loop until it. XPATH will also be very useful when we are considering deleting a given node.

Writing:

SimpleXML is a simple structured xml library so there aren’t many methods to write into the file, therefore, the methods existing are more than enough to perform the operation. The basics are, value and attributes, so, all needed is to add the child and it’s attributes.

Consider the insertion of the Texas State on our small XML file:

<?php
// adding a new state child
$state = $xml->addChild('state', 'Texas');
// adding the abbreviation attribute on the newly created state
$state->addAttribute('abbreviation', 'TX');
// saving the xml file
$xml->asXML();

foreach ($xml->children() as $node) {
// to read the state name value all you need is to convert the node to string
$name = (string) $node;
// to read the state abbreviation is even simpler, call the attribute using the array feature
$abbreviation = $node['abbreviation'];
// just to print
echo "name: {$name} abbrv: {$abbreviation}
";
}
?>

Just like reading, if necessary to add a child inside a given node, all needed is to reach the node and then add the child. Just to exemplify, consider we adding the child city inside the recently created Texas State.

<?php
$state = $xml->addChild('state', 'Texas');
$state->addAttribute('abbreviation', 'TX');

$city = $state->addChild('city', 'Austin');
$city->addAttribute('capital', 'yes');
$xml->asXML();
?>

The fact of the SimpleXML library be a simpler version of XML handling, it does not support direct access to functions such as DELETE and UPDATE, therefore, there is a way around it.

Deleting:

SimpleXML does not support direct deletion of a node, therefore, since it is treated as an array, you can, just like in an array, unset a node to delete it.

<?php
    $counter = -1;
    $itemToUnset = null;
    foreach ($xml->children() as $node) {
        ++$counter;
        $attr = $node->attributes();
        if ($attr['abbreviation'] == 'TX') {
            $itemToUnset = $counter;
            break;
        }
     }

   unset($xml->state[$itemToUnset]);
   $newXmlText = $xml->asXML();
?>

For multiple tier levels of the XML file, you can use the XPATH to get to uppermost parent node and then loop inside it to get the index and “delete” the node.

Updating:

Updating is not one of the easier tasks with SimpleXML and, in a case like this, using the DOM XML object is recommended, therefore just like the delete there is a way to go around it and update a XML file using SimpleXML.

First get all information that is necessary to re-create the node. Update the pieces that need to update, delete the node and then re-insert it with the addChild methods.

Even knowing that SimpleXML does not carry a strong support for delete and update, for it reading, nothing is faster than it. Most of the times XML manipulation will be used to read values from an AJAX request, config file for a bootstrap, simply store a new entry on a XML file, etc.

With the support of the XPATH, SimpleXML becomes a strong library and can handle the basics for XML manipulation with PHP in a structured and easy-to-understand  way.

Have fun.

Posted in PHP | Tagged: , , , , , , , | 1 Comment »

Advanced Photoshop Techniques that you might not be aware of

Posted by mcloide on October 28, 2009

Got this from a Tweet of 99Designs. Good tutorial.

Follow the link: http://inspectelement.com/tutorials/advanced-photoshop-techniques-that-you-may-not-be-aware-of/

Posted in PHP | Tagged: , , , | Leave a Comment »