Tuesday, February 19, 2008

Macosx resize partition

A great feature of macosx 10.5 (leopard) that I discover only yesterday (just after having done damages!) is the ability to resize a hfs+ journaled partition on the fly. This means you don't have to boot from the install cd. All you need to do is open DiskUtility. Select the disk you want to modify, go to the Partition tab and simply adjust the partitions size. Awesome!

I found out this features becouse my System volume was almost full but I had a lot of free space on my user volume (BTW: partitions are evil! Long live to ZFS).

So the next time I'll have to modify the space allocation on my disk I'll just backup important data and let DiskUtility do the job.

Friday, February 15, 2008

Mercurial repository @ SourceForge

Today I set up 2 mercurial repositories on sourceforge.net for my project jMmsLib.
It's been quite easy... I basically followed this simple howto and all went straight once I solved one little problem.

Thought the howto state that you have to put you hg distribution inside your project directory, I decided to put it in my user home directory and make a symbolic link in the project home. So at the moment of trying the cgi page I get a python error. It was telling me that it couldn't find a module that was inside the hg distribution.
At first I thought I had messed up the path in the cgi script, so I checked, but all seemed right to me. So I tried to set the path to the hg distribution in the mutt prject home. This time it worked.

Mmm... So thinking the problem was in my hg distribution (maybe a corrupted one!) I substitute it with the one from mutt (always putting it in my user home directory). But still it didn't work...
To make a long story short, the problem was apache (or at least I think it was apache) refuses to include a python module outside the file system portion devoted to projects. So I had to move the hg distribution from my user home to my project home and after all worked like a charm.

Thinking about it now, it is a normal security policy. I wonder why I didn't thought it from the first moment. Besides that, I hope SF will support mercurial soon or later!

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:

morekeywords={if, else, for, in, remove, from, case, do, forever, to, False, True},
{<=} {$\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:

\subfloat[subcaption 1]{\lstinputlisting{a}}
\subfloat[subcaption 2]{\lstinputlisting{b}}
\caption{Global caption}

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...

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

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.

Tuesday, February 05, 2008

Send MMS

Some months ago I've had to write a simple software for sending MMS. Before that moment, my knowledge of MMS or WAP was very limited. Indeed my mobile phone do not even supports MMS... (or color to be honest).

So I've start to search the internet for some documentation regarding MMS and how to send them through a GPRS connection. Unfortunately there's not so much documentation on these matters. In the end I figured out that I could use jWAP to send the binary MMS message to the MMSC of the provider. The last problem was how to build a binary MMS. The only Java library I found capable of encoding a binary MMS was "MMS Java Library" from Nokia. The first problem with this libarry was the download (for some reason, it's not downloadable from the Nokia web site anymore and I had to search for it a lot to find a copy). The second problem was the license that wasn't so clear (the only thing I found it's a post on the Nokia forum where it's said you cand modify if freely).

So after all I decided it was a better idea to write a simple library to encode MMS messages. Fortunately the specification avaiable at Open Mobile Alliance are quite detailed. The only problematic thing is to find the informations you need in all those pdf files.

In the end the results of this work are avaiable here. You'll find the library for encoding and decoding MMS and a simple client to send them trough a WAP gateway. At the moment the library is quite simple, it supports encoding of send_req messages and decoding of send_conf ones only. Also it does supports only image and text parts. In the future it's possible that new features will be added.

Anyway if someone is searching information on how to send MMS take a look at the sources of SendMMS (a total of 3 classes with one being an Exception and one a container).
If you want details on how to encode a MMS message take a look at the sources of jMmsLib, they are quite simple to read and understand.