Archive for the ‘Webmaster’ Category

Search with operators

Looking for a mail from your friend John? Use the Gmail search box and type from:john. Gmail will find all mails from John. If you can’t remember if the mail you are looking for was sent by John or Paul, type from:john OR paul.

If you have more than one friend called John, the search phrase looks like this: from:john-smith.

There are several operators of this kind:

  • from:
  • to:
  • cc:
  • bcc:
  • subject:
  • label:
  • filename:
  • has:attachment
  • in:anywhere
  • in:inbox
  • in:trash
  • in:spam
  • is:starred
  • is:unread
  • is:read
  • after:
  • before:

The two last operators relate to dates. If you want to find emails from a April 2007, the form is: after:2007/03/31 before:2004/05/01.

If you want to search for a label consisting of more than one word, use hyphens, like in the example with John Smith above: label:holiday-france.

To find mail from email addresses within a certain domain, you just enter the domain in the “From:” field.

You can also use standard Boolean operators (AND, OR, +, -, quotes and parentheses). For an introduction to Boolean search, see the Pandia Goalgetter search tutorial.

Use the Google Toolbar

If you have the Google Toolbar installed (and many Page Rank junkies do), recent editions have a Gmail button you can use to search your mail.

Referential integrity is an important concept in database design. The term refers to a state when all the references in a database are valid and no invalid links exist between the various tables that make up the system. When referential integrity exists, any attempt to link to a record which does not already exist will fail; this helps prevent user errors, producing a more accurate (and useful) database.

Referential integrity is usually implemented through the use of foreign keys. For a long time, the popular open-source RDBMS MySQL did not support foreign keys, citing concerns that such support would erode RDBMS speed and performance. However, given the high volume of user interest in this feature, recent versions of MySQL have implemented support for foreign keys through the new InnoDB table engine. Consequently, maintaining referential integrity within the tables that make up a database has become significantly simpler.

In order to set up a foreign key relationship between two MySQL tables, three conditions must be met:

  1. Both tables must be of the InnoDB table type.
  2. The fields used in the foreign key relationship must be indexed.
  3. The fields used in the foreign key relationship must be similar in data type.

The best way to understand how this works is with an example. Begin by creating two tables (Listing A), one listing animal species and their corresponding codes (table name: species) and the other listing animals in a zoo (table name: zoo). The idea here is to link the two tables by the species code, so that only those entries in the zoo table which have a valid species code in the species table are accepted and saved to the database.

Listing A

mysql> CREATE TABLE species (id TINYINT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) ENGINE=INNODB;
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO species VALUES (1, ‘orangutan’), (2, ‘elephant’), (3, ‘hippopotamus’), (4, ‘yak’);
Query OK, 4 rows affected (0.06 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> CREATE TABLE zoo (id INT(4) NOT NULL, name VARCHAR(50) NOT NULL, FK_species TINYINT(4) NOT NULL, INDEX (FK_species), FOREIGN KEY (FK_species) REFERENCES species (id), PRIMARY KEY(id)) ENGINE=INNODB;

Important: For non-InnoDB tables, the FOREIGN KEY clause is ignored.

As the above illustrates, a foreign key relationship now exists between the fieldszoo.species and species.id. An entry in the zoo table will be permitted only if the corresponding zoo.species field matches a value in the species.idfield. This is clearly visible in the following output, which demonstrates what happens when you attempt to enter a record for Harry Hippopotamus with an invalid species code:

mysql> INSERT INTO zoo VALUES (1, ‘Harry’, 5);
ERROR 1216 (23000): Cannot add or update a child row: a foreign key constraint fails

Here, MySQL checks the speciestable to see if the species code exists and, finding that it does not, rejects the record. Contrast this with what happens when you enter the same record with a valid species code (one that already exists in the species table):

mysql> INSERT INTO zoo VALUES (1, ‘Harry’, 3);
Query OK, 1 row affected (0.06 sec)

Here, MySQL checks the species table to see if the species code exists and, finding that it does, permits the record to be saved to the zoo table.

To delete a foreign key relationship, first use the SHOW CREATE TABLE command to find out InnoDB’s internal label for the field (Listing B).

Listing B

+——-+—————————————————+
| Table | Create Table                                      |
+——-+—————————————————+
| zoo   | CREATE TABLE `zoo` (
  `id` int(4) NOT NULL default ‘0′,
  `name` varchar(50) NOT NULL default ”,
  `FK_species` tinyint(4) NOT NULL default ‘0′,
  KEY `FK_species` (`FK_species`),
  CONSTRAINT `zoo_ibfk_1` FOREIGN KEY (`FK_species`)
  REFERENCES `species` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+——-+—————————————————-+

And then use the ALTER TABLE command with the DROP FOREIGN KEY clause, as below:

mysql> ALTER TABLE zoo DROP FOREIGN KEY zoo_ibfk_1;
Query OK, 1 row affected (0.11 sec)
Records: 1  Duplicates: 0  Warnings: 0

To add a foreign key to an existing table, use the ALTER TABLE command with an ADD FOREIGN KEY clause to define the appropriate field as a foreign key:

mysql> ALTER TABLE zoo ADD FOREIGN KEY (FK_species) REFERENCES species (id);
Query OK, 1 rows affected (0.11 sec)
Records: 1  Duplicates: 0  Warnings: 0

As the examples above illustrate, foreign key relationships can play an important role in catching data entry errors, and implementing them usually results in a stronger, better-integrated database. On the other hand, it’s worthwhile noting that performing foreign key checks is a resource-intensive process and defining complicated inter-relationships between tables can result in a significant performance drop. Therefore, it’s important to always balance referential integrity considerations with performance considerations, and use foreign keys judiciously to ensure an optimal mix of speed and strength.

Reduce number of files in Gallery

Posted by Ivan Guan under Webmaster

Gallery is a fantastic program to organise your photos. However, it generates a large number of files. This application alone is using 16,102 inodes in my server. As most server limits the number of inodes to be 50,000. Some of the tips to reduce the number of files would be handy.

Be sure to back up first.

  1. Removing the modules/*/locale/* and themes/*/locale/*/ folders is fine. you’ll still see g2’s American English default output.
  2. You can delete the g2data/cache (or just the g2data/cache/derivative) directory periodically (yours may be under a different path) at the expense of performance, as each page visit will have to rebuild those cached files from the original.
  3. Delete any modules in ./gallery2/modules that you don’t use, make sure they are deactivated / uninstalled first. You can also ”delete” from site admin, plugins
  4. Delete any themes you don’t use in ./gallery2/themes, of course making sure they aren’t activated (uninstall them!). Might be able to delete from the same place as above
  5. In each module, there are lots of .po and .mo files in each module/po directory (ie: ./gallery2/modules/uploadapplet/po). You should be safe to delete any languages you *don’t* use, but you can see this could quickly be time consuming. If you have shell access, you could do something like `find . -name ‘es.*’` to see all the “es” language files (is that spanish?). You could expand the find request until you are happy with the results (say, using regex) then add a “-delete” or “-exec rm ‘{}’ ‘;’” (depending on which it supports) to nuke all those language files. You might have to repeat it a few times with different file names specified so you can get them all w/o removing the languages you want to keep. This should save a lot of files too.
  6. You might consider de-activating all your modules, downloading the latest “minimal” release and blowing away your ./gallery2/ dir (after making a backup of course), copying the “config.php” from your backup and then making sure everything is going. Now, using the downloadable plugins, you can get modules with *only* the languages you want.

htaccess resources

Posted by Ivan Guan under Webmaster

This is on the List of resource list threads, along with other kinds of useful stuff

5 htaccess Tricks Every Webmaster Should Know

Comprehensive guide to . htaccess – intro

Ultimate htaccess Examples | evolt.org

the jackol’s den » htaccess Cheatsheet – Mikhail Esteves

Stupid htaccess Tricks – Perishable Press

htaccess Magic

Wise-Women: Tutorial: Using the . htaccess File

Fun with . htaccess

Apache Tutorial: . htaccess files

Clockwatchers – . htaccess Tutorial – Introduction

Daring Fireball: Using . htaccess Redirection to Standardize Web …

Hardening HTAccess , Part One

Vortexmind: free your mind » Apache . htaccess tweaking tutorial

Preventing Image Bandwidth Theft With . htaccess (thesitewizard.com)

. htaccess Tutorial – Part 1

Tools

The first link is a really spiffy web-based .htaccess generator. Using it is a great way to learn more–if you make a subdirectory in your public_html directory, you can use it with a .htaccess file to see what happens with the generator’s assorted options.

Reminder: each .htacess file works governs only its own directory and subdirectories below that, until superseded by another, and, like any file with a specific name, only one can exist per directory/subdirectory.

htaccess Generator

. htaccess Tools