Howto change a default Eclipse project to an Eclipse Java project

To change a default Eclipse project to an Eclipse Java project you can follow the steps below.

  1. First close the project in Eclipse (right-click project folder > close project)
  2. Open the .project file in a text-editor outside Eclipse
  3. Add the Java builder and nature to the .project file
  4. Save and close file
  5. Open project in Eclipse and it now is a Java project

Example:
Original .project file

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>A project</name>

Replacing text in a directory tree

Sometimes you want to replace one piece of text with another in all files in a whole directory tree.

*nix and sed to the rescue.


find ./ -type f -exec sed -i ’s/queryString/replaceString/g’ {} \;

Java memory usage

We all know that Java is a memory hog. This page aims to give you an idea how much it actually hogs without using a profiler.
Primitive types
A reference to an object is in this listing also considered to be a primitive type.

  • boolean: 1 byte
  • byte: 1 byte
  • char: 2 bytes
  • short: 2 bytes
  • int: 4 bytes
  • long: 8 bytes
  • float: 4 bytes
  • double: 8 bytes
  • reference: 4 bytes

Objects
Each Java object uses the following:

  • 8 byte Object overhead

Command line printing with Firefox

To print from the command line with Firefox, you need to install an extension. One such extension is
Command Line Print by torisugari.

This extension allows you to print URLs immediately, without user interaction. This can be useful to convert html pages to PDF for example.

You first have to install the extension from http://torisugari.googlepages.com/commandlineprint2

After you've properly installed the extension, you can start using Firefox as command line printer.

Usage:

$>firefox -print http://www.example.com/index.html

Tar selected files based on file name

To include only a set of files with tar, you can use the following one liner. This example will tar all files with the java extension in the archive with the name test.


find . -name '*.java' | tar czvf test.tar.gz --files-from -

Restore sessions at Firefox start-up

This tutorials shows how to restore all tabs that were open when you closed Firefox.

Go to about:config, this should be typed in the address bar.
Go to the section with that starts with browser.sessionstore and set the values to the whatever you like.

Determine uncompressed size of GZIP file

For some applications it is useful to determine the uncompressed size of a file that has been compressed by the gzip algorithm. From the command line this can be done by using the -l option of the gzip program. But this is less straightforward using the Java API's. The GZIPInputStream class does not provide a method to query the original file size. However the information is present in the GZIP file for files that were originally smaller than 4 Gb and can be extracted.

Create a bold or italic column in a latex table or tabular environment

To create a table in latex one can use the tabular environment and surround it with a table block to add a caption and make it floating.

The table below starts with a column that is left-aligned, then there is a a column that will be in bold and is centered and finally there is an italic column that is right-aligned.


\begin{table}
\begin{tabular}{l>{\bfseries}c>{\italic}r}
apple & red & round\\
melon & green & round\\
cookie & brown & square\\
\end{tabular}
\caption{Some objects, their color and their shape.}
\end{table}

Timing runtime in Linux

When writing new software or implementing new algorithms it is always nice to know how long it takes to process a certain data set. Alternatively it is just good to know how much time a program consumed when you let it run overnight. Did it take till 7 am in the morning or was it finished five minutes after you left your desk.

Linux has a very straighforward way to time your applications. The command is simply called time.

Simply put time in front of your program or script when calling in and you well get some information regarding the runtime it took.

Recursively renaming files in Linux

This tutorial explains how to rename all files in a directory and its subdirectories. Or just how to rename multiple files at once in Linux.

This can be done with one very simple command:

rename some other `find . -name '.*'`

This will replaces all occurences of 'some' in file names with 'other'.

A simple example: rename all htm files to html.

rename htm html `find . -name '*.html'`

The rename command takes 3 arguments:

  1. thing to replace
  2. thing to replace it with
  3. a list of files to apply it to