MySQL World Cities database installation

MaxMind offers a free cities database, the database contains more than 2.7 mil. locations, you can download it at MaxMind’s website.

Once you have downloaded the compressed database, extract the file worldcitiespop.txt and invoke the MySQL client (preferably from the same directory where the worldcitiespop.txt file resides).

Create the world database and the cities table

Here is the structure for the world database (remove the first two lines if you already have a database):

-- Database: `world`
USE `world`;

-- Table: `cities`
  `Country` char(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `City` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `AccentCity` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `Region` char(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `Population` int(10) unsigned NOT NULL,
  `Latitude` float NOT NULL,
  `Longitude` float NOT NULL,
  KEY `AccentCity` (`AccentCity`(5)),
  KEY `City` (`City`(5))

Import cities from worldcitiespop.txt into database

  INTO TABLE `cities`

_path_the_file_ can be either an absolute path or relative path (relative to the folder from where you invoked the MySQL client), so in case you followed my instructions and invoked the MySQL client from the directory that contains the file worldcitiespop.txt, _path_to_file_ will be worldcitiespop.txt.

The file worldcitiespop.txt is as big as 130 MB so the process may take very much longer than a few seconds

What’s next? up to you…

Now that the database is installed you can use it for your application, I use it on one of my websites where users can choose one or more cities on their profiles, then they get a daily weather forecast for those cities.

Add or Remove a word from Firefox dictionary

Lappy, touchpad, plugin, WordPress, vlog… and many other words are not (yet) recognized by Firefox, each time you use any of them Firefox will underline them in red, it would be better not to be bothered by these lines every time you write a “common” word which is not listed in the dictionary.

Add a Word to Firefox dictionary:

Right click on the word and click “Add to Dictionary” or press “o”.

Remove a Word from Firefox dictionary:

Firefox profile directory

It happens sometimes -specially when using a lappy touchpad, that you add by mistake  misspelled word to your Firefox personal dictionary, this how to remove them:

  1. Locate the file persdict.dat (this manipulation is OS independent):
    • At the top of a Firefox window, on the menu bar, click Help> Troubleshooting Information, if the menu bar is hidden press the alt key once to reveal it.
    • A new page will open, click on the button that says Open Containing Folder, this opens the Profile Directory, the button is located under Application Basics
    • Find the file persdict.dat
  2. Close Firefox, otherwise your changes in step 3 will be lost
  3. Open the file persdict.dat on a text editor, you will see that each word you added to the dictionary  constitutes a line in persdict.dat, remove unwanted lines and save… that’s it

WordPress page navigation without using a plugin

wp page navigation
Here is a small… yes, a small function for displaying a paged navigation in your WordPress powered blog without using any plugin.

The function is self-explaining, it accepts one optional parameter, the number of links to show without counting the previous and next buttons.

It accepts your language

The first, previous, next and last buttons text can be set to anything you want from within the function, you probably don’t want to change the presets, the arrows work just fine and don’t need any translation, but it you want to put something else and if you are making a template that is meant for distribution, I advise that you use the __() function, example:

$first_txt = __('First', 'theme_textdomain');
$previous_txt = __('Previous', 'theme_textdomain');
$last_txt = __('Last', 'theme_textdomain');
$next_txt = __('Next', 'theme_textdomain');

The function

This is the function:

 * get_paged_navigation displays a paged navigation
 * @param int $number_of_pages_to_show
 * @author Nabil Kadimi
 * @link
function get_paged_navigation($number_of_pages_to_show = 10){
	$current_page_number = (int) $GLOBALS['paged'];
	$number_of_pages = (int) $GLOBALS['wp_query']->max_num_pages;
	$first_txt = '«';
	$previous_txt = '‹';
	$next_txt = '›';
	$last_txt = '»';
	if($number_of_pages < 2)
		return true;
		$current_page_number = 1;

	$last_head_page_number = ceil($number_of_pages_to_show/2);
	$firt_tail_page_number = $number_of_pages - floor($number_of_pages_to_show/2);

	if($current_page_number = $firt_tail_page_number)
		$page_first_shown = $number_of_pages - $number_of_pages_to_show + 1;
		$page_first_shown = $current_page_number - ceil($number_of_pages_to_show/2) + 1;

	// First arrows
	if($page_first_shown != 1){
		echo '', $first_txt, ' ';
		echo get_previous_posts_link($previous_txt), ' ';
	// Linked page numbers
	for($i=0; $i < $number_of_pages_to_show && $i<$number_of_pages; $i++)
		echo '', $page_first_shown + $i, ' ';
	// Last arrows
	if($page_first_shown + $number_of_pages_to_show < $number_of_pages + 1){
		echo get_next_posts_link($next_txt), ' ';
		echo '', $last_txt, ' ';



With formatting

One more thing, if the pagination will have any formatting surrounding it, you can have a conditional statement so that the formatting doesn’t appear if the pagination is not needed (there is only 1 page), here is an example:

if($GLOBALS['wp_query']->max_num_pages > 1){
	echo '';

HowTo: Connect to Hostmonster’s SSH with a private key

Note: I use Hostmonster, I can’t test elsewhere, but I think these steps will work for Bluehost too.

I don’t understand why most tutorials on hostmonster and bluehost are incomplete, they have one of the best shared hosting service, one of the best support teams… but there knowledge base is not that shiny. Well, this detailed tutorial from hostmonster helpdesk didn’t work for me, there is one step missing, so here it is again, how to connect to hostmonster SSH with a private ssh key using PuTTy… euh PuTty… euh… sorry… it’s PuTTY

Generate Keys

  1. Go to your CPanel -> SSH/Shell Access -> Manage SSH Keys
  2. Go to Generate a new key and fill in the fields,
    • leave the password empty (I couldn’t make it work with a password)
    • for added security set the Key Type to RSA and Key Size to 4096
    • Click Generate Key, then Go Back
  3. On the table Public Keys, Click Manage Authorizations near the key you added a few moment ago, Authorize on the next page and then Go back
  4. On the table Private Keys click View/Download
  5. On the bottom of the page click Convert then Download Key on the next page, save it somewhere on your computer.


From Hostmonster helpdesk:

Configuring PuTTY:

  1. In PuTTY, under Session, enter your Host Name
  2. Under SSH, choose 2 from Preferred SSH Protocol Version
  3. Under SSH -> Auth in PuTTY, you will need to specify where your private key can be found. Remember this is where you saved the private key on your local computer. Click Browse to locate the file on your computer.
  4. If you wish to have your username automatically sent to the server when connecting, under Connection -> Data in PuTTY, you will see a field for “Auto-login username”. Type your account username there.
  5. Save your settings to be used in future sessions – Under Sessions, type a name (such as “my site”) in the Saved Sessions box and click Save.

WordPress LTR/RTL


I found your website on a WordPress forum. Currently I am rebuilding a website in wordpress that is in English and Farsi. I am using the Qtranslate and a theme called suffusion which supports RTL. The theme does come a rtl.css which moves everything to the right which is great. The problem I am having is switching from my LTR Style Sheet to RTL stylesheet when the language is switched. If you could be of any assistance on this it would be greatly appreciated.

Thank You – Chris

Continue reading “WordPress LTR/RTL”

PHP with IMAP on CentOS

I was playing with Drupal 6 and some UberCart ticket module when I came across an error message where Drupal told me that it needed the IMAP PHP extension to be installed.

Because I’m a nice guy I will share this command with you:

[me@it ~]# yum install php-imap

Now it’s installed, proof:

[me@it ~]# php --ri imap


IMAP c-Client Version => 2004
SSL Support => enabled
Kerberos Support => enabled
[me@it ~]#

If it wasn’t installed it would have shown you:

[me@it ~]# php --ri imap
Extension 'imap' not present.

But of course it isn’t working… yet, untill you restart the Apache server daemon

[me@it ~]# service httpd restart

And because I’m a nice guy I will tell you where I found the first command before even you ask:

The PHP manual is always a good place to start, oh… and don’t underestimate comments.

Error writing the value’s new contents (Windows Registry Editor)

I got this error when trying to change some configuration settings for my anti-virus (TrendMicro WFBS on Windows Server 2003)

'Cannot edit LocalServerPort:
Error writing the value's new contents'

As usual, when something I don’t like happens on my computer or on other parts of my life, I ask my friend Google about it, the suggested solutions were :

  • Open the Registry Editor using the command “Regedt32.exe”
  • Set or review permissions (Edit->Permissions…)

Of course none of these worked for me, all I had to do is to close the anti-virus program, or to be more specific unload server/client security agent (lol).

I’m not much on Windows, so I can’t explain that behavior, if you know something about it, please share it on the comments section, I will be very pleased to add it here on this very same post.

Get current URL in PHP

Here is a function for getting the URL of the page being processed in PHP, the function accepts one optional parameter $ignore_port_80 (boolean) to tell it whether it should ignore the port part of the url if the port used is 80:

# Function
function get_current_url($ignore_port_80 = true) {
  $is_https = $_SERVER['HTTPS'] === 'on';
  $show_port = $_SERVER['SERVER_PORT'] !== '80' || !$ignore_port_80;

  $url = ''
    . 'http'
    . ($is_https ? 's' : '')
    . '://'
    . ($show_port ? (':'.$_SERVER['SERVER_PORT']) : '')
  return $url;

# Examples
echo get_current_url();       #
echo get_current_url(true);   # same as above
echo get_current_url(false);  #

vsftpd: 500 OOPS: unrecognised variable in config file


When I start vsftpd on my CentOs machine I get this error:

Starting vsftpd for vsftpd: 500 OOPS: unrecognised variable in config file:  anonymous_enable

How can I fix it?


The option “anonymous_enable” is a valid vsftpd option, but as you can see on the error message, there is an extra white space before the variable definition, I suspect that the line was there, commented, and that when you uncommented it you forgot to remove the white space after the “#”, check your vsftpd.conf file make sure that “anonymous_enable=YES” or “anonymous_enable=NO” stands on a single line without any preceding spaces then start vsftpd:

service vsftpd start

MySQL statement terminators

There is the semicolon “;” that every one knows, and “g” which is just the same:

mysql > SELECT * FROM wp_links;
mysql > SELECT * FROM wp_links\g

Those are exactly the same, and will produce the same result, here is an example:

mysql> select * from wp_links \g
| link_id | link_url              | link_name    | link_image | link_target | link_category | link_description | link_visible | link_owner | link_rating | link_updated        | link_rel | link_notes | link_rss              |
|       1 | | WP arabic    |            |             |             0 |                  | Y            |          1 |           0 | 0000-00-00 00:00:00 |          |            | |
1 row in set (0.01 sec)

\G is another valid statement terminator, it tells MySQL to produce vertical output, this comes in handy when the result has too much columns, here is the same statement again but with the \G terminator:

mysql> select * from wp_links\G
*************************** 1. row ***************************
link_id: 1
link_name: WP arabic
link_category: 0
link_visible: Y
link_owner: 1
link_rating: 0
link_updated: 0000-00-00 00:00:00
1 row in set (0.00 sec)

As you can see this is a more user friendly fashion for displaying data.

Install Symfony Without PEAR

A lot of web hosts have limited or nonexistent support for PEAR, the pear command will throw errors on most commands or not work at all, in order to install Symfony on such hosts you will need to download the Symfony package, copy Symfony files to your home directory and make them easily accessible from PHP scripts by modifying the include_path directive setting.

In order to complete these steps faster, we will prefer using SSH to download or edit files and to create folder instead of using FTP, FTP will take a lot of time compared to SSH… Let’s start.

1 – Download and Install Symfony

Login to your account using SSH, if you are already logged in make sure your current working directory is your home directory (~), then create a “php” folder where you will download the symfony package, we will use the same directory structure used on the Symfony documentation, this will allow you to follow the documentation examples without changing directory names etc.

Before issuing the following commands, grab the link of the latest symfony version from Symfony website, for the purposes of this tutorial you will have to download the  source .tgz file, the text  written in red font will be different depending on the Symfony version: [/tmp]# cd [~]# mkdir php [~]# mkdir php/lib [~]# mkdir php/lib/vendor [~]# cd php/lib/vendor [~/vendor]# wget
=> `symfony-1.4.1.tgz.2'
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3,210,838 (3.1M) [application/x-gzip]100%[===================================================================>] 3,210,838 1.34M/s
06:15:48 (1.34 MB/s) - `symfony-1.4.1.tgz.2' saved [3210838/3210838] [~/vendor]# tar zxpf symfony-1.4.1.tgz [~/vendor]# mv symfony-1.4.1 symfony [~/vendor]# rm -fr symfony-*

2 – Test your Symfony installation

You can test your installation and display the symfony version: [~]# php -q  php/lib/vendor/symfony/data/bin/symfony -V
symfony version 1.4.1 (/home/you/php/lib/vendor/symfony/lib)

3 – Tell PHP where to find Symfony files

Symfony files are now available in your server, but you still need to tell php where to find them easily. For that you need to modify your PHP include_path and add the “php” folder.

We need to know the php folder absolute path, for this we will “cd” to the “php” directory and issue the “pwd” command: [~]# cd ~/php [~]# pwd

-or- [~]# find ~/php -name php

There are different solutions for altering your PHP include_path, you will choose the one that meets your needs.
[See: How to modify PHP include_path]

In this tutorial, I will assume that you are relying on a global php.ini file .

Open you php.ini file for edit [~]# nano /x/y/z/php.ini

Look for the include_path directive setting, something like this:

include_path = ".:/usr/lib/php:/usr/local/lib/php"

you can find it easily by using nano’s search featrure:

  • Press CTRL+W
  • Type the search string and press RETURN, we are interested in the string include_path
  • Press CTRL+W then RETURN until you find something that resembles the code above.

Add the php absolute path to your php include_path like this

include_path = ".:/usr/lib/php:/usr/local/lib/php:/home3/you/php"


At this point you can use symphony almost as if you installed it using the PEAR pear command. You can use the same method to install other PEAR packages. One more thing you can do is to alter your shell PATH to add the symfony command:

Open .bash_profile add the following line AT THE END OF THE FILE:

export PATH

Firefox crashes: How to detect bogus extensions

Today, whenever I used the built in Firefox search function and as soon as I typed the first letter of my phrase, Firefox suddenly crashed and displayed the well known Mozilla Crash Reporter window (image below).

Mozilla Crash Reporter

Sending a crash report to complain about my issue won’t help me (specially), and won’t help Mozilla people too much, unless they know more about my system (OS, FF version, installed extensions, latest visited websites), so I’d better try to solve this issue by myself.

1st try

I restarted Firefox, it still crashes when i type the first letter of my search string…

2nd try

I rebooted my computer… I wasted 2 minutes for nothing.

3rd try

I scanned my computer using Avira Antivir Personal, nothing found as usual.

4th try, what I should have done from the beginning

I started firefox in safe mode and disabled all installed extensions (more than 15).
By the way, the command for starting Firefox in safe mode is:

firefox -safe-mode

Guess what, it worked now, I can use the search function again, but all my extensions are disabled, I enabled them 3 or 4 at a time, restarted Firefox, and tested the search function at each time until I spotted the bogus extensions which was nothing but YSlow 2.0.5.

So what?

Now I can send a descent report to Mozilla and be helpful, I will have to wait until YSlow is updated again or I will install the extension Google Speed which is very similar and even better than YSlow IMO.

Detect WordPress version

How can I detect the current WordPress version?

Log in to your admin Dashboard and scroll to the bottom of the page, you’ll find your version number on the rightmost spot of the footer.

WordPress version

Or you can view the source of one of the pages of your blog and look for the meta generator tag:

<meta name="generator" content="WordPress 2.9.1" />

WordPress upgrade error (Allowed memory size of 33554432 bytes exhausted)

The problem

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2516315 bytes) in /home/mydomain/public_html/blog/wp-includes/http.php on line 1370

This can happen at any line and with any file, not only http.php at line 1370!


Don’t worry if you get this error, there is nothing wrong with your server or hosting plan etc. Whenever a new version of WordPress is released, new features are added, thus more calculations, so logically more memory is needed.
In older versions of WordPress (before 2.7… I think), the memory limit was set to 32M, if you are upgrading WordPress, you will probably get that error, you will have to edit the wp-settings.php file and set (I should say change) the constant WP_MEMORY_LIMIT value to 64M, giving PHP more memory to play with.

The solution

  • Open the remote file wp-settings.php file located on the base directory where you installed your WP blog
  • find this code (probably at line 13)

    define('WP_MEMORY_LIMIT', '32M');

  • Replace with

    define('WP_MEMORY_LIMIT', '64M');

  • Run the upgrade process again
  • Enjoy your updated WP blog

Opera: CSS rotation and other transformations

After the release of Opera 10.5 Alpha, it’s now be possible to rotate elements, this new release includes support for CSS3 rotation and other transitions and transforms, we may not longer need JavaScript for some basic transformations, have a taste:

The demonstration doesn’t show rotation, so the CSS for rotation under Opera is:



When you install Opera 10.5 Alpha, your previous installation of Opera (Stable) is not removed, giving you the chance to test and compare…


Find more about Crossbrowser CSS rotation at hakoniemi’s blog.