Downloading or mirroring a website with wget

The easiest way to download/mirror a complete website is using WGET and use the mirror option. If you want to see your website with the correct layout and all images, make sure you also supply the --page-requisites flag.

The full command:

wget -p -m -k -K -E http://your.website.com/

See wget --help for an explanation of all command-line options, but these should give you a good start.

Linux breaking lines to fixed length

Break line in fixed width with the linux fold command.

I keep forgetting this command, so here goes.

The Linux 'fold' command, can be used to wrap each input line to fit in specified width.

If width is not specified using -w option, by default, 'fold' breaks lines wider than 80 columns. The output is split into as many lines as necessary.

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}