Web Development Tutorials for March 2011

Exclude files from Tar Archive

Tar is a UNIX/Linux utility which is used to compress files for storage in an archive. When we tell tar to compress and create an archive of a directory, it will go ahead and include all the files in that directory.

Sometimes we may want to exclude a particular file from an archive. Tar allows use a convenient option to specify a file or files to exclude when making the archive. The tutorial below shows how we do a tar exclude file operation by using the command line.

Use Javascript to Highlight Text

Javascript can be used as a handy way to highlight some text for a user when they click on it. This nifty little feature is useful as it saves time for the user since they don't have to do any clicking and dragging.

To utilize this feature, we use the javascript onclick event and assign certain actions to it. For example, if we had a textbox with some text in, we would enable automatic highlighting when a user clicked inside of it like so:

<textarea onclick="this.focus(); this.select();">

Check Ubuntu version from the Command Line

To get the version of Ubuntu or the kernel that is running is quite a simple task when using the command line. Especially on an Ubuntu server where you may only interact with the system through a terminal, it may be easy to lose track of which version of the operating system is running. The version of the kernel which is running may also be obscure since you rarely need that sort of information.

Whatever your interest in knowing these versions, you will find out how to check them below.

Remove 'Preview' button in Drupal 6 comment form

By default in Drupal 6, there is a 'Preview' button in addition to a 'Save' button in the form which allows a user to post a comment. For those of us who think it is silly to have a preview before posting, the good news is that you can remove the button quite simply with a bit of code.

Place the following code in the template.php file which exists in the directory for the theme that you are using. If your theme does not use a template.php file, go ahead and create one.

This code goes in template.php:

<?php

Restart MySQL Ubuntu

We may want to restart our MySQL server for a number of reasons. The most likely reason for wanting to restart our MySQL database server is to load new configuration settings. It is a good idea to ensure that no users will be accessing the database server when you are performing the restart just in case the restart fails. Always backup your configuration files before making any changes, as fouled up configuration files are the most likely causes of a failed restart.

PHP md5 String and File Example

A hash function is useful for checking that something has not been changed. The md5 function is a popular hash function that can be used to generate a hash of a string of text or a file. A hash is useful since you cannot easily determine the input from the hash itself.

You may hash a file and send the hash with the file. The receiver can then rehash the file once they receive it to ensure that the file was not modified during transmission, since a modified file would generate a different hash.

Adding rel="nofollow" to Comments in Drupal 6

By default in Drupal 6, only the Homepage link of a commenter has a rel="nofollow" attribute attached to it. The commenter has free reign on all the other anchor tags inside the body of the actual comment. In many cases this is unsuitable especially for SEO purposes.

Spammers like to leave links in comments to transfer Pagerank from your page to theirs. By adding a rel="nofollow" attribute, no Pagerank will be passed to the external page and it will also serve as a deterrent to adding external links in the first place.

Disable Resizable Textarea Drupal 6

Drupal 6 allows textareas to be re-sizable and this may be a useful or annoying feature depending on how you look at it. It may be useful since you are allowed to change the size on the fly to suit your needs and may be helpful when adding a lot of content at one time. It may be a nuisance since an extra image (grippie.png) has to be loaded from the server to provide that functionality.

How soon after crawling do pages appear in Google's index?

Enthusiastic web publishers always want their new content to be found from a Google search as soon as possible. The short answer to the question of how soon can content appear in search results after being published is less than 24 hours.