Conditional compilation in Latex

The ifthen package allows conditional blocks on Latex documents. This is very useful if you want to include or exclude some parts of the text. To use the package add the following to the document preamble:

\usepackage{ifthen}
\newboolean{DEBUG}
\setboolean{DEBUG}{false}

Then you can use \ifthenelse commands within the document to include/exclude parts of text. In this example, as the DEBUG variable is set to false, the debug text won’t appear in the final document. If we switch its value to true, the debug text will appear again.

\ifthenelse {\boolean{DEBUG}}
{This is some debug text} {This is the other text}

How does Opera Unite’s File Sharing Service work?

Opera has introduced a new feature called Opera Unite in its browser. Opera Unite allows service sharing from the web browser. These services include File Sharing, Fridge, Media Player, Photo Sharing, The Lounge and Web Server.

operaunite How does Opera Unites File Sharing Service work?

Since it looked promising, I decided to try it out. Setting up the File Sharing service just took a few minutes and everything worked fine. Which made me think … how does it really work? I’m behind a NAT connection and haven’t configured my router which, by the way, doesn’t support UPnP. Perhaps magic? … don’t think so.

To test how it worked I started a file download and fired up Wireshark to examine the packets. They were coming from an Opera server. This happened on the client’s side. On the server’s side Opera had opened a connection to another Opera’s server. So it seems that the service works the same way as a Reverse SSH Tunnel:

  1. The browser establishes a connection to an Opera server (tunnel A).
  2. When the clients access the service they’re really establishing a connection to an Opera Server (tunnel B).
  3. Tunnel A and Tunnel B get connected and the data flows.

The question that comes up is … Does the service always operate this way? Is the connection direct when the user is not behind a NAT or supports automatic port forwarding?

In general the service looks good to me, being its main advantage the ease of use. On the other hand, the information exchange is not strictly between the server and the client (shared files go through the Opera’s network), which can be a deterrent for some users.

Schedule commands to run later on Linux and Mac

For scheduling periodical tasks you have Cron. But if you just want to schedule a command to run later you can use at.

# at 12:00
# at> echo “Scheduled phrase”|mail addr@provider.com
# at> (type control+d)
job 6 scheduled at 2009-06-16 12:00

You can see the scheduled tasks with atq and remove them with atrm

# atq
6 2009-06-16 12:00 a root
# atrm 6 (where 6 is the task id)

Mac4lin brings the beauty of the Mac to the Linux desktop

Seen on Lifehacker. Two years ago I bought a Macbook and from that moment on, I’m pretty much in love with the Mac look & feel. Its ease of use and integration are impressive. Mac4lin brings these fancy features to the Linux Desktop. It includes skins, wallpapers and interface refinements that resemble the Mac experience. It definitely worths a try!

mac4lin Mac4lin brings the beauty of the Mac to the Linux desktop

Christian, Muslim and Satanic Ubuntu Editions

Yes, you read it right. There are Christian, Muslim and Satanic Ubuntu editions.

Recover the root password on Linux

There are many different ways to recover a lost root password on Linux systems. These are two of them:

When the Grub screen appears, press ‘e’ and append ’1′ to the line. The system will boot in single user mode. When you are presented the root prompt type the password command to change the password.

Another option is to mount the root filesystem and do a chroot:

# mkdir /mnt/system
# mount /dev/sda1 /mnt/system
# chroot /mnt/system
# passwd

In the first case you can prevent password recovery assigning a password to Grub.

# /sbin/grub-md5-crypt

This command returns a MD5 hash of the entered password.

Next, edit the Grub configuration file /boot/grub/grub.conf and add the following line (replace ‘password-hash’ with the grub-md5-crypt command output):

password --md5 password-hash

Now Grub doesn’t allow direct access to the edit or command menus. You have to press ‘p’ and enter the password.

Latex brush for Syntax Highlighter Plus WordPress plugin

I post source code snippets quite often and I use this plugin for syntax highlighting. It works great but it doesn’t support every programming language. For example it lacks Latex support. On the other hand you can define coloring rules for unsupported languages by creating new “brushes”.

Taking advantage of this feature, I’ve defined an extremely simple Latex brush which highlights:

  • Latex comments beginning with a percent symbol ‘%’.
  • Latex commands beginning with a backslash “\”.
  • Some keywords such as ‘if’, ‘else’, etc.

You can download the brush from here.

If you want to see Latex coloring in action, you can take a look at the Latex section of my blog.

Note: I also had to add this line:

'Latex'     => array('latex', 'tex'),

…to the SetVariables() function in syntaxhighlighter.php for the new brush to work.

Setting up a Public Key Infrastructure (PKI) on Linux: Theory and Practice

This article highlights the most important concepts regarding Public Key Infrastructure (PKI). It also includes a practical step-by-step guide explaining how to set up a PKI on Linux using the OpenSSL package.

Wrap text around float figures in Latex

The wrapfig package enables text wrapping around figures.

\usepackage{wrapfig}

To include a wrapped figure we can use the \begin{wrapfigure} command. You have to specify the alignment (l, r) and the figure’s width. Here is an example:

\begin{wrapfigure}{r}{60mm}
\begin{center}
\includegraphics[scale=0.5]{images/nature_photography.jpg}
\end{center}
\caption{Wrapped image.}
\end{wrapfigure}

And the final result.

picture 11 Wrap text around float figures in Latex

Placing subfigures in Latex documents

Sometimes you need to place two or more figures side by side or you just need to include a figure composed of many subfigures. To place the images in your Latex document this way, you can use the subfig package.

\usepackage{subfig}

The command subfloat is used to specify the subfigures.

\begin{figure}[!h]
\centering
\subfloat[NP Server's certificate]{label{fig:gull} \includegraphics[width=0.4\textwidth] {images/npservercert.png}} \qquad
\subfloat[SP Server's certificate]{label{fig:gull} \includegraphics[width=0.4\textwidth] {images/spservercert.png}}
\caption{}
\label{fig:}
\end{figure}

And this is the final result.

subfig Placing subfigures in Latex documents