Categories
Linux

Ubuntu 11.10 Fix: Unplugging Power Cable Suspends Notebook

The scenario is simple. I am using Ubuntu 11.10 64bit on my Compaq Presario CQ42. When power cuts or I unplug the adapter, I get a warning message that battery is critically low and it suspends a few seconds later. After searching for a while I found the solution.

Use this following command on Terminal:

It should solve the problem! 🙂

Categories
PHP

Symfony2: Loading external libraries

I have always wanted to play with Symfony since I heard many cool things about the framework. Finally got some time and started studying the framework. I would save the experience for another blog post. However I am going to share how easy it is to load external libraries.

Libraries supporting PSR-0 standard
If the library was written according to the PSR-0 standard, it is already well structured with the proper implimentation of namespace. For such libraries, just open up “app/autoload.php” and add the namespace to the array which is passed to the $loader->registerNamespaces() method. Your codes should look something similar to:

Libraries supporting PEAR Conventions
Libraries with support for PEAR conventions could be easily loaded as well. Just pass the autoloader prefix (the first part of the class name or the root directory name followed by underscore) to the $loader->registerPrefixes() method.

Something like:


In such scenarios the class MyLib_MyClass should reside inside __DIR__.’/../vendor/mylib/src/MyLib/MyClass.php – as the PEAR standard suggests.

The Old and Incompatible ones
PHP has a very long history of evolution and there are plenty of community maintained codes which haven’t yet been updated to reflect the modern development standards. There are many 3rd party libraries out there which are old (was written before PHP 5.3) but useful. While there is no direct way to load them into Symfony, thanks to the nifty autoloader, we can easily use them with Symfony2.

Say, we have a class like this:


It is a single file library – no namespace, no PEAR naming. What do we do? We make it PEAR compatible 🙂

# First rename the file according to the class name – KillingCurse.php

# Now create a vendor and source directory under the “vendor” directory of the app. Say, we name “voldemort” as the vendor and name the source directory “src”. The file structure would be- “/vendor/voldemort/src”. This is not a requirement, we could just create any directory under the “/vendor” directory but follwing the Symfony naming convention is a good practice.

# We need to create a prefix, so we create a directory named “Spells” (/vendor/voldemort/src/Spells)

# We put the KillingCurse.php under the Spells directory and define a Spells_KillingCurse class in the same file like this:


The full file now looks like:


# Now we register the “Spells_” prefix to the “app/autoload.php”:


# We use the following codes in the controller:


Points to be Noted:

— \Spells_KillingCurse::load(); We are using a static call which does nothing. But this makes the autoloader load the file in which the bare KillingCurse lives. We used a static call instead of having to initiate an object.

— An extra class without any functionality is added just so that entire file is loaded. Any functions, classes or constants will get imported into the global namespace.

— Be sure to use the “\” before the classes, functions etc. You’re inside a namespace and you must refer to the global namespace to use items in the global scope.

— There could be many other ways to do this. Like I mentioned at the top of this post, I am just beginning Symfony2. I would love to hear new ideas or suggestions to improve the codes.

Categories
Linux

Displaying Skype on Notification Area in Ubuntu 11.10

I am using Ubuntu 11.10 64 bit (don’t ask me why! grr!) and I hate Unity. Besides all the inconvenience – the Skype icon doesn’t appear on the notification area. From Google found this solution:

It works! 😀