Sunday, April 02, 2006

Accents in latex

I use kile to compile my latex code but I was not able to get accents on the dvi. Why, because I did not use the good packages.

What have I to write in the header? It is easy:

%Use the latin1 encoding
%yes, I am french

Sort a byte array in Java

The default algorithm used to sort a byte array is Arrays.sort(byte [] array). The algorithm used is a quicksort (complexity about =(nlog(n))). It is good for objects, but we have seen it is far better to use a countingsort algorithm.

Here is the code used:

public static void sort(byte toSort[], int offset, int length) {

//If we have less than this number of elements, we do the
//default sort else we use the countingsort algorithm
if (length < 45) {
Arrays.sort(toSort, offset, length);
//It can go faster if we keep in memory an other array,
// but the class has to be synchronized.
//We initialize a new array
int temp [] = new int[256];
Arrays.fill(temp, 0);

//Count the number of elements
for (int i = offset; i < offset + length; i++) {
temp[toSort[i] + 128]++;
byte value = -128;
int ind = 0;
//Insert the bytes in the good order
for (int i = offset; i < offset + length;) {
while (temp[ind] == 0) {
for (int j = 0; j < temp[ind]; j++) {
toSort[i++] = value;


If there is less than 45 elements we have found that creating new arrays takes to much time and that the countingsort algorithm is not good enough.

The factor (sun sort)/countingsort has been calculated for some size of arrays. With 80 elements, the couting sort is about 50% faster. At 1280 elements, the couting sort algorithm is 4 times faster.

Sound with totem

By default, you cannot hear mp3 in totem. That is annoying because you will not have sound on most of the videos.

To get the sound in totem, you have to install gstreamer0.8-mad. It is in universe.

sudo apt-get install gstreamer0.8-mad

Yopu should have the sound now.

Ubuntu package not available

On a lot of forums, you can see:

sudo apt-get <package>

But sometimes this package is not available. What to do?

It is certainly that you did not add all the repositories available. Ubuntu comes with a preconfigured system that allows only to download ubuntu selected packages.

If your package is not present, you will have to add the repository...

The file containing repositories is /etc/apt/sources.list

By default, most of the repositories are commented (# symbol). Uncomment Universe (lines terminated by universe...) repositories and you should be able to download the package (most of the time).

Install iptables as a service

To add iptables as a service, you have to:

  1. Generate a iptable script in /etc/init.d/iptables

  2. Configure it as a service

Iptable script

Here is an example. This script only allows ssh, http, and https, and established connexions. It rejects everything else.


case "$1" in
echo -n "Starting IPTABLES... "

# Clear old rules

$IPTABLES -A INPUT -p tcp --dport ssh -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 80 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 443 -j ACCEPT

echo "done."
echo -n "Stopping IPTABLES... "

echo "done."

echo -n "Restarting IPTABLES... "
$0 stop > /dev/null
sleep 1
$0 start > /dev/null

echo "done."

echo "Usage: $0 {start|stop|restart}"

Configuring the service

I think we can put iptables in each init level. But I have decided to start this service after network service, it is the level 1. To do that, simply write.

sudo update-rc.d iptables start 99 1 .

Okay, how does it work:

  • iptables is the name of the script

  • start : We want to start the service

  • 99: is the id of the service, each service is started from the init level, and for each level the order depends on the id. We just run iptables as the last service.

  • 1: is the init level

You should get the message:

Adding system startup for /etc/init.d/iptables ...
/etc/rc1.d/S99iptables -> ../init.d/iptables

Install gcc on Ubuntu

If you only install gcc, you will get an error saying that standard libraries are lacking.

You have to install an other package: build-essential.

To install gcc:

sudo apt-get install gcc build-essential

Install and configure webalizer on Ubuntu

  1. install webalizer

    sudo apt-get install webalizer

    If webalizer is not found, you have to add sources in /etc/apt/sources.list: can comment the universe sources.

  2. Enable the apache2 hostname resolution: go into /etc/apache2/apache2.conf: Change

    HostnameLookups Off


    HostnameLookups On

  3. By default webalizer is not well configured: it does not check in the good log. In /etc/webalizer.conf: Change

    LogFile /var/log/apache2/access.log.1


    LogFile /var/log/apache2/access.log

  4. Test webalizer:

    sudo webalizer

    If you get a warning like warning: Truncating ...
    It is because you did not put the hostnameLookup. If afterward, you get this message, it can be because you are attacked by a virus...

  5. Run webalizer as a cronjob. This has to be run as root: Edit the root cronjobs by running the command:

    sudo crontab -e

    and add the line:

    0 * * * * webalizer

    With that line, every hour webalizer is run

Use the static xerces library on linux

  1. Download the source code
  2. Compile and install it following the instructions.
  3. Go into $xerces/objs
  4. Make an archive:

    ar cru libxerces-c.a `find . -name "*.o"`

  5. Congratulations, you have now a static xerces library

Create a new module with CVS

If you want to create a new module, let's say newdir:
  1. go into the directory newdir.
  2. Run the command:
    cvs import newdir vendor version 

    vendor and version are not important, you can write what you want.
  3. Write a comment.
  4. Now you have a new module, you just have to checkout, to be sure that the file is ok.
I did not write -d ... because in my environment variables: CVSROOT and CVS_RSH are defined.

Using C++ and fortran using visual studio and visual fortran

To avoid declaring always __stdcall for each external C procedure, the default Calling convention has to be set in Properties/Fortran/External Procedures

PHP4 with Apache2 on Gentoo

  1. edit /etc/make.conf and add "apache2" in your use flags
  2. emerge mod_php apache2
  3. Edit the file /etc/apache2/conf/apache2.conf and add these lines
    LoadModule php4_module extramodules/
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps
    ServerName "localhost"
    alias /@mydir@/ "@path@"
    Order deny,allow
    Allow from all
    where @mydir@ is the name you want to access from the internet and @path@ is the path to your the directory containing sources.
  4. restart apache
     /etc/init.d/apache2 restart 
  5. You should be able to access your page at: http://localhost/@mydir@/...

Xerces static library

To use the xerces C++ parser with a static library, we suppose you already have used xerces with dynamic library and that the project is correctly configured:

  1. download the source code at:
  2. Open the $xerces_src\Projects\Win32\VC7\xerces-all\xerces-all.sln
  3. Right-click on the XercesLib
  4. Change configuration Type: Static library (.lib)
  5. Compile Xerceslib
Open your project:
  1. Put the library in the "resource files" directory.


We had to use the GSL (Gnuwin32) library but we had some problems: an access violation when trying to call the

function. The exact error was:

(LIBGSL.DLL): 0xC0000005: Access Violation

To avoid this error, the macro GSL_DLL has to be declared.

Xerces dynamic library

To use xerces C++ with visual studio 6:

  1. Download the xerces zip file at: and unzip it.
  2. Go in Project->Settings->C/C++.
  3. Insert into the "additional include directories", the path to the xerces include directory.
  4. right-click on resource files and select: add files to folder... Select the needed librarires in the xerces lib directory.
  5. In the execution directory (or in system32), you have to put the xerces dlls.
Now it should work properly