Thursday, February 18, 2010

Content Negotiation Apache Style

Content Negotiation is a complex sounding term for what is really a simple process.

Imagine calling your doctor's office to make an appointment. You tell them what dates you prefer and they respond with the opening that best fits your preference.

The Wikipedia entry on content negotiation is kind of sparse but has links to the RFC and other information.

Apache can handle content negotiation and if the apache server is configured to allow it, you can turn on per directory Content Negotiation with an htaccess file.

Contents of .htaccess file

Options All +MultiViews


The permissions of the .htaccess file should be readable

-rw----r-- 1 owner group 24 2010-02-08 19:48 .htaccess


Apache instructions for Content Negotiation

Then you can put multiple files in the same directory with the same name.
e.g.
image.png
image.gif
image.jpeg

When a user requests the image like http://example.com/image the browser will negotiate with the server for the preferred image type.

Thursday, February 4, 2010

MySql Shortcut

If you access a MySql database from a linux machine here is a tip that can save you some time. In your home directory create a file named .my.cnf. That is dot-my-dot-cnf.

Then in that file you can create multiple entries like the following:
[client]
user=username
password=%!;*;^123
host=localhost

Now when you ssh in and type mysql, the client will automatically parse and use those credentials. You can specify multiple hosts if you want like this:

[client]
user=username
password=%$**^123
host=hosta.example.com

[client]
user=usernameB
password=%B^123
host=hostb.example.com

Then the MySql client will choose the proper set depending on the host you are connecting to. This feature served me well when using R scripts. In a R script that access a database you can specify the particular client group that you want to use.

In the .my.cnf file.

[Rdata]
user=Ruser
password=password
host=localhost

Then in the R file itself you can create the connection like this:

dbcon <- dbConnect( MySQL(), group="Rdata")

Now you can move the script around or share it without worrying about revealing your password information.