Wednesday, January 27, 2010

How to add more swap space on Linux

An easy method if you don't want to repartition the whole disk.

dd if=/dev/zero of=/tmp/swap.img bs=1M count=256

Set up a loop device and connect the dummy file with that device:

losetup /dev/loop3 /tmp/swap.img

Then, it's just formatting the loop device:

mkswap /dev/loop3

It also needs activation:

swapon /dev/loop3

Voilá, there is a new swap partition.

To remove it:

swapoff /dev/loop3
losetup -d /dev/loop3
rm /tmp/swap.img

Enable LAN access for Oracle XE admin web on Ubuntu

Edit your .bashrc file to include the lines:

export PATH

Log out. Log in again.

Then start up sqlplus:

sqlplus sys as sysdba

And then just execute:

SQL> exec dbms_xdb.setListenerLocalAccess (l_access => FALSE);

Wednesday, January 20, 2010

Generating unique file names with SimpleDateFormat and Random

Sometimes it is necessary use an unique file name when writing a voice recording with Cisco IP IVR or Cisco Unified Contact Center Express (UCCX). The CCX Editor does support Java, so we can easily do this: let's just create a timestamp with the date and time including milliseconds, then just append a random number between 0 and 9999. Yes, I know there is still some chance this will generate the same string, but this isn't something I cannot live with.

First, create the timeStamp string using this code block:

String DATE_FORMAT="yyyyMMdd_HHmmss-SSS";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
return sdf.format(new Date());

Then generate a random number with this code:

java.util.Random nahcis = new java.util.Random();
return nahcis.nextInt(9999).toString();

And in the end just concatenate:

"recording_" + timeStamp + "_" + randomNumber

This will create a string like:


And this is something you can use as the file name.

Sunday, January 3, 2010

Servlets cannot look into their own install directory? Solution.

This applies to a Tomcat 5.5 installation running on a Ubuntu 8.04 server (and, all Ubuntu versions I know).

If you write a servlet that needs to read a file which is in the servlet's WEB-INF directory, for instance, a config.xml, Tomcat, or more precisely, the Java Security Manager will not let you.

(Interestingly, Tomcat that comes with CentOS, will do. Hmm.)

What I did is turning off the security manager in the /etc/init.d/tomcat5.5 file.

Task for the rest of the week: find out how to enable the required thing without turning off the Security Manager.

Saturday, January 2, 2010

Using apt behind a proxy in Ubuntu

It's really easy. All you have to do is:

$export http_proxy

and voila, you can apt-get update, apt-get install, whatever.