Archive for February, 2008

Play iTunes m4a Files on Linux Ubuntu

Recently I transfered some of the iTunes .m4a music files to my Linux Ubuntu 7.10 Gutsy , the pre-installed music player Rythmbox can’t recongnize music files in .m4a format. So in order to play .m4a file, we must choose an alternative music player. I have done intensive research and come to the conclusion that the best music player to use would be Amarok. If your Linux OS is like a vergin touched by the first time (in layman’s word, you are a newbie using Linux system, read this article to make sure you can install.

To Install Amarok Open Terminal . Main Menu -> Accessories -> Terminal .Now type this in Terminal:
sudo apt-get install amarok

The player only solved part of the problem, Now since you have installed the Audio Player Amarok, now we should head forward and install codecs so that these players work without any problem. The one we are going to install is called Gstreamer.

Please note there are many tutorials teaches you the wrong or outdated way to install Gstramer. To avoid confusion and trouble expalining, I will just show you the easiest quick and dirty way to get the codecs installed:
sudo apt-get install gstreamer*

The above command tells the computer to install every plugin of Gstreamer, the good, the bad and the ugly.

After you have installed Gstreamer, our Amarok Player will work like charm while playing Media files..

10 Comments

YUI Slide Show Hide

This YUI application I coded was based on one of my previous article JavaScript – Unobtrusive Slideshow. The slideshow is completely written using YUI yahoo-dom-event and animation components. Below is the link to the demo page, enjoy!

http://www.lab.highub.com/yui/slideshow/list.html

1 Comment

Ubuntu 7.10 Gutsy – Add Universe Multiverse Repositories

Ubuntu is based on the Debian Linux distribution but contains only a subset of Debian’s software due to the amount of testing required to support each package. universe is a subcategory that contains software that the community has packaged and supports for Ubuntu. If you are looking for a particular piece of software and can’t seem to find it, there’s a good chance that it is in universe or the next subcategory, multiverse. Note that since these packages are not officially supported by Ubuntu, there’s a chance that you risk some instability by installing software from this category.

Like universe, the multiverse category contains software that is not officially supported but is maintained by the Ubuntu community. multiverse is to universe as restricted is to main. Here you will find contributed or nonfree packages that are not officially supported by Ubuntu.

To add Universe Multiverse Repositories, go to System -> Administration -> Software Sources. Check all the unchecked options under Ubuntu Software , Third Party Software, Updates. After that it will ask you to relode the package stats so that latest repositories can be added in the database for installation of the necessary software.
After the relode done you will be prompted to update your system . It is necessary to update your whole system before installing any software.. So I think you are done till now.

1 Comment

Unix Shell Command Line Tips

There are two major time-savers when dealing with long files on the command line (Unix Shell) : file globs and tab completion. File globs are symbols you can use as wildcards in the place of a filename. You can substitute the ? symbol for any single character in a filename, and * for any number of characters in a filename. For instance, say you had three files: car, bus, and cab. If you wanted to delete both car and cab, you would type:
rm ca?

The ? matches both r and the b at the end of the filename. If you wanted to remove all files that started with the letter b, you would type:
rm b*

Tab completion is another time-saver on the command line. If you start to type a command and then hit the Tab key, the shell will automatically attempt to complete the name of the command for you. In the case that more than one command matches what you have typed so far, hit Tab an extra time, and you will be shown all of the options that match:

apt-get followed by hitting the tab key twice.

Tab completion also works for files and directory names. Just type the first part of the filename and hit Tab, and the shell will fill out the rest for you.Once you are finished with a terminal, you can close the window like any other window, or, alternatively, you can type exit on the command line.

No Comments

Manipulate Files Directories using Unix Shell

This article continues from the previous article about using Unix Shell (command line) to operate Unix-like operating systems like Linux Ubuntu. We will see how to use Unix Shell to create, rename, move and delete files and directories.

To create a directory from the command line, type the mkdir command followed by the name of the directory, let’s create a directory called bollocks
mkdir bollocks

Use the mv command to move a file or directory to a different directory, or to rename it in its current directory. To rename the bollocks directory you created to sex_pistols you can use:
mv bollocks sex_pistols

If you wanted to move the sex_pistols directory inside the Desktop directory, you would just specify the Desktop directory as the second argument:
mv sex_pistols Desktop/

The rm command removes files, and rmdir removes directories. Just use the commands followed by the files or directories to remove, respectively:
rm Desktop/sex_pistols/
bodies.mp3
rmdir Desktop/sex_pistols/

You can also remove a directory and all files and directories inside of it by running rm -r followed by the name of the directory.

Notice: Be careful when you recursively delete a directory with this command that you do in fact want to remove all of the files within. Once removed via the command line, there’s no trash bin to retrieve them from.

1 Comment

Navigate the Filesystem using Unix shell

Due to the popularity of mainstream operating systems, desktops like Windows or Mac, the command line might seem like a foreign thing to many people. Typing commands into a window might seem, well, arcane. But even though Linux has really progressed on the desktop, there is still a lot of power you can wield at the command line. So if you are a former Windows or Mac user and recently joined the ‘free and open source revolution’ but suddenly feel lost in this utopia (can’t get used to the command line), I think you should take a deep breathe and take a bit of time to learn this powerful technology. Knowledge is power, once you get this power, you will find that you have so much freedom to think and act independently, no longer rely on soul-sucking evil cult companies like Microsoft or Macintosh.

The most popular Unix-like computer operating system would be Linux, there are many well-known Linux distributions like Fedora, openSUSE, Ubuntu etc. The most well-known among all these is Ubuntu. So now let’s see how we can navigate the filesystem on Ubuntu using Shell script.

The first step is to launch a terminal. Click Applications > Accessories > Termial to start default GNOME (GNOME is one of the three most popular uer interfaces on desktop machines, the other two are KDE and Xfce) Terminal program.

Now that the terminal program is open, you can navigate the filesystem. By default, terminals will open your home directory, so one thing you might want to do is see what files are currently in your home directory. The ls command displays all the files in the directory you specify (or in the current directory if you don’t list a drectory):
ls

The command above will display all the files in the home directory

To get the list of contents on the Desktop directory, type the following command:
ls Desktop/

Notice: please take note that in the Unix world, all directory and file names are case-sensitive. So if you change the above command to: ls desktop/, you will end up getting a response like: No such file or directory.

If you want to navigate to a certain directory, use the cd commond followed by the directory to change to:
cd Desktop/

You can use the pwd command to see where you currently are, to use it simply type: pwd

Tip: The ~ symbol is shorthand in Linux for your user’s home directory. If you type cd ~ you will automatically change back to your home directory. It saves you from having to type out cd /home/ username.

Hope this helps!

No Comments

Remove Mootools From Joomla Header

Joomla 1.5 is definitely a better CMS if you compare it to Joomla 1.0. One of few complaints I have heard and personally experienced with Joomla 1.5 is the inclusion of Mootools (and caption.js) by default if you use Joomla template method to display header information in your template. What’s the problem, one may ask? Well, the problem is that the Mootools file that comes with Joomla 1.5 is whopping 74k in size. From developer’s point of view, I may never need to use mootools in my application. And from end user point of view, this really slows down initial page load times especially for users who have slower connections, and you never get a second chance to make a first impression.Mootools is definitely a very useful JavaScript framework. (And since the perfectionist founder can even FIRE his developer, that also shows it has certain standard.) But loading it without using it really irritates some people.So why the hell on earth would Joomla 1.5 includes Mootools? The reason is because Joomla 1.5 Admin section uses Mootools. It’s the C (Controller) in the MVC (Model-View-Controller) that needs it. If you have installed the latest version and seen the AJAX effects from the admin area, you may probably know what I am talking about.Now the question is how to remove the Mootools and other JavaScript files from the header when the end users see it, and keep it exists when a administrator sees it? Don’t worry, here is the solution, below is the code I use to remove the mootools.js and caption.js

<?php
$user =& JFactory::getUser();
if ($user->get('guest') == 1) {
$headerstuff = $this->getHeadData();
$headerstuff['scripts'] = array();
$this->setHeadData($headerstuff); }
?>
<jdoc:include type="head" />

In case you want to keep the caption.js, (some Joomla! components, modules or plugins uses caption.js, for example:Acajoom), you can choose to remove mootools only. Below is the PHP code i use to do so:

<?php
// Remove auto generated mootool from header
$headerstuff = $this->getHeadData();
reset($headerstuff['scripts']);
$moo = key($headerstuff['scripts']);
unset($headerstuff['scripts'][$moo]);
$this->setHeadData($headerstuff);
?>
<jdoc:include type="head">

Hope these tips help!

75 Comments

Way to use Joomla loadAssoc

mysql_fetch_assoc is the native PHP MySQL function to fetch a result row as an associative array. Joomla! has it’s own database abstraction class that does this job — loadAssoc.

Below is an example of the using loadAssoc to fetch a result row from content table and show the individual selected field results:

$db = JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE
title='Overview'";
$db->setQuery($query);
$article_row = $db->loadAssoc();
echo $article_row['introtext']."—".$article_row['publish_up'];

The output will the the intro text of the article with the title Overview and followed by published date and time.

2 Comments

Joomla – Use loadObjectList and foreach to get list

Joomla is build to be able to use many different kinds of SQL-database-systems and to run in a variety of environments with different table-prefixes. In addition to these functions, the class automatically creates the database connection. Besides instantiating the object, you only need 2 lines of code to get a result from the database and that in a variety of formats. Using the Joomla database layer ensures a maximum of compatibility and flexibility for your extension.

The database class contains many methods for working with a query’s result set. One of the most useful one would be loadObjectList. The syntax of loadObjectList is: loadObjectList ( $key ), this returns an array of database objects using the current SQL query. Returns false if the query fails. If the $key parameter is set, the array is indexed using the values of the field specified by key. Otherwise, the array is indexed sequentially.

The reason I say this is a really handy function is because we always retrieves a list of results belongs to a certain category. For example, if we want to get all category titles from database jos_categories where section equals to 1, and list them out. This can be done by using the following method:

// Get a database object
$db = JFactory::getDBO();
$query = "SELECT * FROM #__categories
WHERE section = 1";
// Executes the current SQL query string.
$db->setQuery($query);
// returns the array of database objects
$list = $db->loadObjectList();
// create the list of titles
foreach ($list as $item) {
$item_title = $item->title;
echo $item_title.'<br />';
}

3 Comments

Proper Way to Use Joomla getNumRows

Joomla provides a sopisticated database abstraction layer to simplify the usage for 3PD. Joomla database class contains many methods for working with a query’s result set. Many people have encountered one problem when using getNumRows which is part of Joomla database class. The following chunk of code is the most common senario:

$db = JFactory::getDBO();
$query = "SELECT * FROM #__example2";
$db->setQuery($query);
$rows = $db->getNumRows();

When you try to execute the above chuck of code, you will get an error message similar to the one below:
Warning: mysql_num_rows(): 108 is not a valid MySQL result resource in root:\mywebsite\libraries\joomla\database\database\mysql.php on line 123

The reason that this happens is because although we called setQuery, but we’ve forgotten to call $db->query(). Add $db->query() just after $db->setQuery($query); will solve the problem. So the following chunk of code should not return any error and works fine:

$db = JFactory::getDBO();
$query = "SELECT * FROM #__example2";
$db->setQuery($query);
$db->query();
$rows = $db->getNumRows();

2 Comments