Showing posts with label howto. Show all posts
Showing posts with label howto. Show all posts

Tuesday, February 12, 2008

Latex: lstlistings pseudo language

For my thesis I need to display a lot of algorithm to document the actions taken by peers talking a specific protocol. Since the thesis should present a theoretical view of the protocol itself and the algorithms, I do not want to display them in a specific language. I do want to use a pseudo language. Also I want the keyword of the language to be highlighted to ease the reading.

Here's the definition of my pseudo language to be used with lstlistings latex package:

\lstdefinelanguage{pseudo}{
morekeywords={if, else, for, in, remove, from, case, do, forever, to, False, True},
sensitive=true,%
morecomment=[l]\#,%
morestring=[b]',%
}
\lstset{language=pseudo}
\lstset{commentstyle=\textit}
\lstset{literate=
{<=} {$\le$}{2} {!=} {$\neq$}{2} {=} {$\leftarrow$}{2} {==} {=}{2} {&&} {$\cap$}{2} {||} {$\cup$}{2} }

This is an example of what your listing will look like:

Monday, February 11, 2008

Gmail IMAP backup

Today I decided to try out Gmail IMAP. Untill today I downloaded mail via POP from gmail and keep them in my home IMAP server. This way I was able to use thunderbird and have my mail synched on all my computers. Now that gmail offer an integrated imap server I decided to switch to that so I'll able to use also gmail web interface and have all synched (before I used to use OverLook that's quite useful, but really slow... at least on my small home server).

In the end now all my mail reside on gmail and I have no local copy (except for thunderbird local file...). I want to keep a local copy of the gmail account to be able to recover from loss of data by google. Also I want it to be synched daily.

Well, the first solution I thought is imapsync.
Here's how to backup a gmail account with it:

imapsync --host1 imap.gmail.com --ssl1 --user1 user@gmail.com \
--password1 gmailPass --host2 local --user2 user@local \
--password2 localPass --prefix2 INBOX.gmail-backup. \
--authuser1 user@gmail.com --authmech1 LOGIN \
--authmech2 LOGIN --syncinternaldates

A more secure way is to put the passwords in 2 file and use --passfile1 and --passfile2.

Latex: listings side by side

Here's how to display two listings side by side in a figure using the subfig and lstlistings packages.

First, put the code you want to display in 2 files (say a and b). Then do the following:

\begin{figure}
\subfloat[subcaption 1]{\lstinputlisting{a}}
\hspace{20pt}
\subfloat[subcaption 2]{\lstinputlisting{b}}
\caption{Global caption}
\end{figure}


This way you obtain the listing side by side. The only issue is that their vertical align is centered. So if the height of the two listings is not the same, the short one is not vertically aligned to the long one.

One way to solve this issue is to use \raisebox{xxpt}{\subfloat[...]{...}} where xx is how much points you want to raise the listing. Anyway I found the result not good enough.

Googling a little bit I found something on the faq section of subfig'sdocumentation. Here it is:

6.1 "My sub-floats are not aligned along their bottoms. Why?"
Remember! The subfig package aligns sub-floats along their baselines with the sub- caption (if any) sticking out above or below. The above problem is usually due to using a minipage, tabular or array environment that, by default, places the baseline at the center of the box that it generates. If the two sub-floats are different sizes, or if onesub-float is generated in some other way with its baseline not at the expected place (perhaps an \includegraphics), then the sub-float will be misaligned. One solution is to use the environment options `[t]' or `[b]' to move the baseline to the top or bottom rather than the center.

I tried (not that hard to be honest), but I wasn't able to align both figure to the top. After all I think I'll keep the center valign...

Thursday, February 07, 2008

CVS to Mercurial

This week I finally tried out Mercurial.
Having used only CVS before, I found this VCS simply amazing.
It's really simple to use and also to learn. Useless to say I decided
to move all my projects from CVS to mercurial.

After searching a while on the net I found some alternatives:
Mercurial ConvertExtension is shipped with mercurial 0.95 so I decided to
use this but probably Tailor is the most flexible of all. Surely it deserve
a try.

Anyhow, the documentation on the ConvertExtension wiki page is just non
existent and the online help of mercurial does not helped me a lot.

So here's how to convert a CVS module:

First of all checkout the module you want to convert as usual.
Let's say myproject is the checked out module, then do the following in
the directory containing the module:

$ hg convert myproject/
assuming destination myproject-hg
initializing destination myproject-hg repository
connecting to :ext:user@cvs.example.com:/cvsroot
scanning source...
sorting...
converting...


Now mercurial convert CVS commits to changesets and in the end it creates
a .hgtags file containing the mapping between CVS releases and mercurial
changesets.

Here it is. Now your module is ready to be used with mercurial. Just to see
if all is ok:
$ cd myproject-hg
$ hg log
And you should see all you CVS history.