Sunday, February 24, 2013

JavaOne 2012 videos on YouTube

Here's list of videos from the recent JavaOne 2012 symposium:

Have fun!

Wednesday, February 20, 2013

Configuring Apache and DNS to access site without www

When hosting a site, it's convenient to just type the domain name e.g. instead of pre-fixing it with www.  This can be easily configured using Apache and by adding one additional entry to the DNS.  For this article's purpose, we'll be using as the domain.

To start off with, add a new A DNS entry to point to the same IP as the A entry which maps to  You'll have something like below:

Name Type Value A A

Once that's done, we configure Apache.  Inside the VirtualHost directive, add the Alias directive as well as the rewrite condition:

<VirtualHost *:80>

DocumentRoot /home/blah/public_html
        <Directory /home/blah/public_html/>
AllowOverride All
Order allow,deny
allow from all

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]


The rewrite condition redirects all requests beginning with www to the domain without www prefix.

Tuesday, February 19, 2013

Using MySQL General Query Log

MySQL comes with the feature to log all SQL queries which is sent to the server.  This feature can be enabled dynamically without having to restart the server.  However, only MySQL 5.1 and above supports this.

To enable this feature, login to MySQL as root.  At the MySQL prompt, type this:

mysql> SET GLOBAL log_output = 'TABLE';
Query OK, 0 rows affected (0.00 sec)

mysql> SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)

Double check if it's really been turned on:

mysql> select @@global.general_log;
| @@global.general_log |
|                    1 |
1 row in set (0.00 sec)

The value should read '1'.  You can now see all SQL queries logged in the general_log table in the mysql database.  

To turn off the logging, set the general_log to OFF using the same syntax as above.

Tuesday, February 5, 2013

Extracting public key for OpenSSH use from AWS generated keypair

To extract a public key from the AWS generated keypairs for use in OpenSSH, use the following command:

$ ssh-keygen -y -f my-key.pem

That will output the public key in a nice string which can then be inserted into authorized_keys.

APNS and PHP gotcha...

This got me good.  Wondering why your APNS messages aren't delivered?  And there's no error message from your client?  Well now, print out the APS payload after it has been JSON encoded.  A correct message should look like this:

{"aps":{"alert":"Oh really?","badge":1,"sound":"default"},"message_type":"message"}

Compare that to a message which supposedly looks fine but doesn't get sent:


See the difference? :)

Yup, the "badge" value.  PHP cast the "badge" value to a string :(  Blogging this so that I don't crack my head in the future.