IE 8 and trailing commas in JavaScript

Feb 27, 2015

How many elements does this JavaScript array object have? (note the comma at the end after which there is no element):

var an_array = [1, 2, 3, ]

This is what the ECMASript Language Specification says about commas in array initialisers:

Whenever a comma in the element list is not preceded by an AssignmentExpression (i.e., a comma at the beginning or after another comma), the missing array element contributes to the length of the Array and increases the index of subsequent elements. Elided array elements are not defined. If an element is elided at the end of an array, that element does not contribute to the length of the Array.

So the answer to our question would be 3 as the trailing comma would be ignored. You can confirm this by bringing up the console in developer tools in Firefox or Chrome entering the array definition and printing out its length:

> var an_array = [1, 2, 3, ]
> an_array.length

< 3


Using and customizing Apache Roller

Feb 20, 2015

One of the reasons I wanted to host a blog on my own server is that I wanted to run it on Java. Searching around for blog applications written in Java, I narrowed down on Pebble and Apache Roller. Pebble doesn’t seem to have been updated in years. While development on Apache Roller seems to have slowed down, at least it is being actively maintained. So I chose it over Pebble.

(A note — running a blog on Java and wanting that blog to have as many features as that other blog you just saw on the Internet requires a fair amount of Java knowledge and effort. So if you are just looking to run a blog with minimal effort, you might want to stick to PHP applications like Wordpress. They have a ton of customization features which don’t require much programming knowledge. They also have a lot of themes to chose from).

Installing and running Apache Roller is a simple enough affair if you follow the documentation. The only issue I ran into was this, during server startup:

 java.lang.NoClassDefFoundError: javax/mail/Session
    at org.apache.roller.weblogger.ui.core.RollerContext.contextInitialized(


roller  |  3

Backing up your data

Feb 14, 2015

Backing up your data is important because it is always possible for you to lose your data. It can be due to you accidentally deleting it, your hard drive crashing or because you lost access to your server. In any case, it is a good idea to set up automated backups both on your server and on another machine that is not in the same physical location as your server.

Here are some resources I used to setup backups on this server which is running Debian Wheezy:

Backing up Postgresql

First create a read only user to perform the back ups as described here. If you don’t want to create a linux user for the read only user, you may need to edit your pg_hba.conf file to change the auth-method to md5 instead of peer which is the default.

Then use this backup script which can make daily, weekly and monthly backups. The script contains the documentation on how to use it.

Backup config and application data files

Next backup any config files that you have modified. Most of your configuration should be in the /etc directory. So you can just backup the whole directory. Then you need to back up your web applications data files as well - files like images, videos etc.. that aren’t stored in your database but are stored on the file system.

To automate the backup of these files, I created a simple shell script with cp commands to copy files to a backup directory. I then dropped this script into /etc/cron.daily so that the script runs daily. If you don’t know how to use cron, this is a good place to start.

Copying your backups to another machine

To automate copying your backups to another machine, you can use rsync. The process is a bit involved. I referred to these guides to setup my rsync backups:

  • A general backup guide that also explains how to use rsync.
  • To automate rsync backups to another machine, we need to use ssh keys and when using those, it is a good idea to create user just to run rsync and prevent that user from running anything else. This explains how to do that.

Using Apache HTTP Server in front of Tomcat 8

Feb 04, 2015

Previously, I wrote about installing Java 8 and Tomcat 8. In this post, we’ll see how to use an Apache HTTP server in front of Tomcat 8. Note that the configuration described in this post is what worked for me. The official documentation (here and here) is heavy on the various configuration options that are available, but doesn’t help much if you are looking for a simple example of how to configure Tomcat with Apache HTTP server, and then tweak that simple configuration as you need. So depending on your goal, the information in this post may not be sufficient. With that caveat, here’s how I got things working:

Install and configure the Tomcat-Apache connector

(The version of Apache HTTP server that I’m using is 2.2, from Debian Wheezy repositories).

Install the Apache-Tomcat connector module:

sudo apt-get install libapache2-mod-jk

That should also enable the jk module in Apache. But just to be sure, enable it explicitly:

sudo a2enmod jk

The Apache-Tomcat connecter uses worker processes to handle requests forwarded by the Apache HTTP server. The configuration of thes processes is in /etc/libapache2-mod-jk/ There, update the paths to tomcat_home and java_home. as I described in my previous post, if you are using separate Tomcat directories - one for Tomcat binaries and one for the config files and webapps, then tomcat_home should point to directory having the webapps.


Installing Java 8 and Tomcat 8 on Debian Wheezy

Feb 01, 2015

Installing Java 8

By default, Debian repositories only have Open JDK and on Wheezy, the Open JDK version is the equivalent of Java 7. To get the latest Java 8, we need to install it manually. First download the Java 8 server JRE which comes with JVM monitoring tools. Or you could just download the Java 8 JDK which includes those monitoring tools and more. I prefer to install only the bare minimum setup that is necessary.

When manually installing software on Linux, it is recommended that it go into /opt directory. So unpack the JRE or JDK into /opt.

Create a symbolic link "java8" pointing to the JRE/JDK directory. This will make it easier when installing updates to the JRE/JDK. All Java dependent applications will refer to the symbolic link and when you do update the JRE/JDK, you don’t need to update the path to Java for all those applications. You just need to update the symbolic link.

cd /opt
sudo ln -s jdk1.8.0_25 java8

Add the Java bin directory to your PATH so that the Java commands are available to you. Edit your .profile file

vi ~/.profile