GParted and my laptop

OK, yesterday I bought a laptop (my first ever), and I am so excited about it! It’s specs:

Fujitsu-Siemes Amilo PI1536
CPU: Intel Core 2 Duo T7200 2×2.0GHz
RAM: 2x1Gb
HD: 120Gb SATA
Display: 15.4 WXGA
Graphics: ATI Mobility Radeon X1400 (128Mb dedicated/512Mb shared)

I chose it for its high quality CPU, and half-decent graphics card. It turns out most sellers have a large Core Duo stock, but a pitifully short list of Core 2 Duo models. Hence, they want to sell their already outdated Core models, and offer little choice in Core 2s (and a bit higher prices, although Intel sells them both at similar prices). The little choice in Core 2 Duos made it difficult to me to find what I was looking for, but I finally did.

However, this post is not only dedicated to spread my happiness. I also wanted to praise the Free Software program GParted, which I just used.

As any laptop+Linux user has experienced, usually Windows is pre-installed and shipped with the computer. In my case, I wanted to have it, so no problem with that. The bad part is that, of course, the whole hard disk is usually a single partition, with Windows being in it. Since I wanted to install Linux also, I had to make partitions. Although the laptop came with CDs for all the software that comes pre-installed (Windows included), I wanted to try to resize the Windows partition, and make room for the other partitions, without destroying the Windows installation.

I downloaded an Ubuntu ISO, burned it, then restarted the laptop with it. Good thing of Ubuntu is that its CD is a Live CD, which means that can be run without installing anything in the hard disk. Ubuntu started flawlessly, and I was presented with a GNOME desktop. There, I started GParted, and a simple, yet visually pleasing, GUI opened, and I point-and-clicked all the settings, which took me from:

1x 111Gb partition under NTFS

to:

1x 15Gb (NTFS)
1x 512Mb (swap) probably wasted disk, but oh well…
3x 10Gb (ReiserFS)
1x 50Gb (ReiserFS)
1x 18Gb (NTFS)

This way, the second NTFS partition can be used to store files Windows can access (I have to try if Linux can access that. If not, I’ll reformat with FAT32), and I still have room for three Linux distro installs (10 Gb Reiserfs), and a big home/ that all Linux-es can share.

Now, the delicate part… rebooting into Windows. I held my breath while the computer rebooted, but it did so fine. Windows started without problem, it just performed a disk integrity check at startup (which finished OK), and then said it had found new hardware, which turned out to be the second NTFS partition (the E: drive now). As we are used to with the stupid Windows, I was told to reboot to have the system recognize the recently-discovered hardware. So I did, and it worked!

Now Windows is installed in the 15Gb NTFS partition (and recall I didn’t reinstall anything. What was there, is still there), and sees a second 18Gb partition. As for Linux, I am looking forward to installing Debian, Ubuntu or something…

Comments (3)

Do one thing, do it well. Part II

This post is the continuation of a previous one. In that first part I mentioned the “bells and whistles” of most Windows programs being even counterproductive, and getting in the way of the user. Here I will elaborate on that.

Most GNU and Free Software applications for GNU/Linux and other Unix-like systems have the possibility of being called from the command line, appart from any GUI they may have.

One would think that no-one in his right mind would use an ugly CLI, where a visual point-and-click GUI exists. However, CLIs give a substantial flexibility, and I will illustrate this with an example.

Suppose you want your computer to remind you of the upcoming birthdays of your friends. Suppose you use Windows. Then, you have to find a program like Birthday Reminder Plus 2006, or whatever, which does it. Maybe you want to be reminded by e-mail… but you will have to make do with what the options in the BRP2006 GUI give you. If BRP2006 has a menu with: “Remind with a beep” and “Remind with a pop-up”, you will have to choose one, and that’s it. Windows programs don’t expect you to think or develop. They expect you to use Google, eMule and so on to download a pirated copy of a monolithic program that fits your needs. If BRP2006 has not an option for reminding you via e-mail, then you have to drop it alltogether, and keep searching for Birthday MegaReminder for PowerUsers 2007, which has such an option.

With GNU/Linux, maybe there is such a program, and you are free to use it. However, there are far better solutions, which you can tailor to your needs. The following is what I actually do to be reminded of birthdays:

First, I need a kind of “database” of birthdays, and a program that, reading this database, can extract the upcoming ones (the ones for which a given amount of days or less, are left). There are probably many of them, but I use one called simply Birthday. I haven’t found the Home Page of this program (to give it here), but I use the Debian package, mantained by Alexander Neumann. The “database” consists in a file called .birthdays that we have to place in our home/ directory. This file will contain lines like:

Bill Gates=30/09/666

Then, when called from the command line, it will output:

Bart[~]: birthday
Bill Gates is 1340 years old in 4 days' time.

If no option is given, birthdays in the following 21 days will be printed out. If you want to see birthdays in the following X days, just issue birthday -W X.

Second, this output is ugly. For example, the use of “is” is wrong, and “days’ time” could be shortened to “days”. To do so, we can pipe it through sed (another GNU utility):

Bart[~]: birthday | sed -e "s/ is / will be /;s/'.*//g"
Bill Gates will be 1340 years old in 4 days

Thus, sed substitutes ‘ is ‘ with ‘ will be ‘, and a literal ‘ and anything behind it ('.*) with nothing (effectively deleting it).

Third, we have to send this “Bill Gates will be…” to our e-mail address. For that, we will use the mail GNU command, like this:

Bart[~/]: birthday | sed -e "s/ is / will be /;s/'.*//g" | mail -s '[BIRTHDAY]' myaddress@myisp.org

This will send an e-mail to myaddress@myisp.org, with the subject [BIRTHDAY], and the body being the Bill Gates will be 1340 years old in 4 days text above.

Fourth, we need to automate this. For that, we can make a little Perl script:

#!/usr/bin/perl -w

#
# This scripts e-mails me to remind me of
# upcoming birthdays. It needs the ‘birthday’
# package.
#

use strict;

# Test if birthday package is installed:
die “No birthday package!\n” if (`which birthday` =~ /not found/);

# Read the list of upcoming birthdays, formated with sed:
my @bulk = `birthday | sed -e “s/ is / will be /;s/’.*//g”`;

# The e-mail address:
my $u = ‘a@b.c’;

# Send e-mail, if there is any upcoming birthday:
system “echo ‘ @bulk’ | mail -s ‘[BIRTHDAY]’ $u” if @bulk;

Next, we have to set this script to run periodically. We can do it with the GNU cron utility. This is a daemon, constantly running in the background (if its service has been activated), wasting negligible resources, and executing the task the users schedule, via the crontab command, or even a GUI like Kcron.

So, I use kcron to schedule the Perl script above to run everyday, at 7:01 am, et voilà! I receive an e-mail from my system every morning, reminding me of the upcoming birthdays.

Uf, all THAT has to be done?

OK, it sounds like a lot of work, for something our Birthday MegaReminder 2007 could do with half a dozen clicks.

Now, consider. The procedure outlined here is fully modular. Any time you want to modify something, you can act on the relevant step: e.g.: if you want to add a birth date to your list, you can just add it editing the ~/.birthday file. If you want to be reminded just once a week, the crontab should be modified. If you want to be reminded 73 days in advance, just add -W 73 to the birthday command in the Perl script. If you want the reminder to be sent to a list of e-mails, instead of only to yourself, you can modify the script accordingly.

The good part is that now you have learned how to use different tools, for different tasks: You have used cron here, but you can use elsewere to schedule ANY job. You have used mail here, but you can use it elsewere to send any text by e-mail, including the contents of a file, the output of a command, or a fixed text.

Maybe the Birthday MegaReminder has scheduling capabilities (like cron), running in the background and activating itself when appropriate. That’s fine but… can its scheduling capabilities be used for other programs? Sorry, no. If you want a periodic scheduler for program X, you have to buy, or pirate, a copy of a program which not only makes X, but also has scheduling capabilities. Maybe Birthday MegaReminder has e-mailing capabilities (like mail), but… can they be used to e-mail other things? Sorry, no.

With the GNU tools (like cron, sed and mail), when I want a program to connect to the Web, retrieve my horoscope, and send a copy to my e-mail, I don’t need a program that is good at sending e-mails or scheduling actions. I need a program that is good at retrieving horoscopes from the Internet. Then, I have tools to e-mail me with the output of such a program, and/or schedule its execution periodically.

Comments

Do one thing, do it well. Part I

If one reviews the Unix philosophy, it is readily seen a huge different from Windows-land. With Windows, every single task has huge programs, with a colorful graphical interface, menues galore, icons, flashing lights and all functionality incorporated into point-and-click buttons, scrolling bars etc.

All this is advocated in the name of “user friendliness”, that is, making it easy for the user. However, there are two major drawbacks I can see (there can be others). First, in a technical aspect, each and every program is a mammoth. Second, the flexibility and usefulness of these programs actually gets degraded with this policy. I’ll address the first question in this post, the second one in another one.

The “mammoth-ness” of proprietary programs happens because, since they forbid sharing code and information among their developers, they tend (have) to be mostly self-contained. This is highly counterproductive, because instead of sharing resources, they have to be replicated.

Think of the following (silly) example: I have programs A, B and C, all of which can produce red circles. Since their source code is closed, each one of them has to implement a piece of code (library) to make “red circles”. Each time one of the three programs is installed, it carries its own redcircles library, with its bugs and problems (and hard disk and memory resource waste). See Figure 1.

bad

Figure 1: Each program has incorporated a redcircles module.

If these programs were Free, they could all share a common redcircles package, which could be developed by other people. See Figure 2. This would let the developer of each program concentrate on the particular things their program does. And also disk space would not be wasted installing that library for each new program that uses it. A new A, B or C instalation would only need the installer to know that the extra package redcircles has to be also installed (a “required” package), if it already isn’t.

good

Figure 2: All programs share an external redcircles library.

The development of the redcircles package would also be much more efficient, because developing and debugging a single package would be much easier than doing so for each program that uses it.

Comments (1)

LaTeX: PowerDot

Tired of hearing that GNU/Linux is good for “technical things”, but not for visually appealing matters, such as presentations? Tired of hearing that LaTeX is good for 200-page books full of cross-references, tables and bibliograpy, but not for “other” documents?

Well, next time you can point your ignorant fellow to some LaTeX solutions for making fancy presentations.

You can find some overviews here:

Among the different programs and methods, I’d like to mention the Seminar and Prosper packages for LaTeX. Prosper was written by Timothy van Zandt, and is available as a package for Debian. However, the Prosper package had its capabilities extended by Hendri Adriaens, to create the HA-prosper LaTeX package. Later on, HA-prosper was dropped, and Adriaens and Christopher Ellison commited themselves to the development of PowerDot, a LaTeX class that would supercede both Prosper and HA-Prosper. The PowerDot class (and many others) can be found in the Debian package texlive-latex-recommended.

What Prosper, HA-Prosper and PowerDot do is (since you are using LaTeX) create a DVI, PS or PDF. Usually, your aim will be to create a PDF, since it even allows for fancy slide transitions (an infamous hability of you know who).

Examples of PowerDot presentations (taken from Adriaens’ site), can be accessed here: Example 1, Example 2, Example 3.

Actually, I am considering to use PowerDot to make the presentation of my PhD defense… I hope I don’t give up and end up using the GUI (and, thus, evil) programs KPresenter or (God forbid) OpenOffice.org.

Comments

LaTeX: footnotes in tables

Although an apparently widely known LaTeX issue, I came across it just today. Fact is if you use \footnote inside a \tabular environment, the footnote will be “trapped” inside the table, and actually never get displayed at all in the output.

You can find some possible solutions for that at the UK TeX FAQ on the Web.

The trick I’ll comment here is to use \tabularx, which is covered in the link above, and also at J.L. Diaz’s LaTeX blog[es].

The “problem” is that \tabularx requires a fixed table width value to be input by the user, so the following will fail misserably:

\usepackage{tabularx} % required in the preamble
\begin{tabularx}{100mm}{|c|c|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

Why? Because the {c} especification (to center the text inside the cell) makes the affected column as wide as necessary, not more (so will {r} or {l}). The output can be seen below:

The effect of the whole table being actually wider than the sum of the integrating colums could be partially “concealed” if the \hlines were eliminated, but the table would still be actually incorrectly wide, which would make things like aligning the whole table “fail” (to the eye).

Fortunately, the tabularx package provides a way to tell LaTeX that a column must be of the necessary width, so that the sum of colum widths equals the total column width. This is the {X} keyword (notice the capitalization of the “X”). E.g.:

\begin{tabularx}{100mm}{|c|X|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

This makes the first column just as wide as needed, not more (the {c}), and then, the second column will be as wide as needed to reach the 100mm. The output:

If multiple columns are given the {X} keyword, they will all have the same width, precisely the one required to meet the total table width.

Comments (3)

Sudaku released

I previously posted about the sudoku fever that had attacked my family. I have found amusing solving some sudokus, but what I really thought was interesting was making a computer program to solve them automatically. Not that it would be more “challenging” (some sudokus are quite difficult), just more fun for me.

OK, so that I did, and today I have released a Perl program that (hopefully) solves any sudoku we feed to it. The program is called Sudaku (well, one sweats when solves a sudoku, doesn’t one?), and can be freely downloaded from my home page. I have licensed it under the GPLv2.

Yes, I know there are other sudoku solvers around, probably better than mine, on top of that. However, I just wanted to make it, and releasing it may help someone, or (more probably) even me, if some better programers than me out there e-mail me proposing changes/corrections.

What the heck, I just felt like releasing it! :^)

Comments

Why use LaTeX

Somehow (don’t remember exactly) I came across this LaTeX advocacy page, in which some reasons are given as to why use the typesetting software the reader must already know I use and love: LaTeX.

Comments

Some numbers on FLOSS

Looking at the Free Software page in the Wikipedia (to which I have contributed with the “However, direct economic benefit is hardly the main reason[…]” paragraph), I found the following link.

Although it’s about 9 months old, it is still meaningfull, and makes for a good reading. Also check this Groklaw article.

Go ahead and “get the facts”.

Comments

Convert PS to PDF

I make extensive use of ps2pdf to convert PostScript files to PDF. As most GNU/Linux tools, this is a simple and incredibly useful one.

However, sometimes it might give problems. For example, I have sometime converted a PS to a PDF that Evince would open fine, but Acrobat Reader would not. I fixed this problem making use of the superb alternatives system present in Debian.

The first thing to know is that most of PS and PDF manipulation (including PS-to-PDF conversion) is done by calling a backend application called Ghostscript (GS). A quick search within the Debian packages shows that most (if not all) of the GS versions mentioned in the wikipedia page are available:

Bart[~/]: aptitude search ^gs-
i   gs-afpl                     - The AFPL Ghostscript PostScript interpreter
p   gs-aladdin                  - Transitional package
p   gs-cjk-resource             - Resource files for gs-cjk, ghostscript CJK-TrueType extension
i A gs-common                   - Common files for different Ghostscript releases
i A gs-esp                      - The Ghostscript PostScript interpreter - ESP version
p   gs-gpl                      - The GPL Ghostscript PostScript interpreter
v   gs-pdfencrypt               -

It turns out I was using gs-esp:

Bart[~/]: which gs
/usr/bin/gs
Bart[~/]: ls -l /usr/bin/gs
lrwxrwxrwx 1 root root 20 Jul  4 09:00 /usr/bin/gs -> /etc/alternatives/gs*
Bart[~/]: ls -l /etc/alternatives/gs
lrwxrwxrwx 1 root root 16 Jul 27 11:26 /etc/alternatives/gs -> /usr/bin/gs-esp

I remember having used different GS versions, and AFPL being the “best”, so I installed it and made the default gs point to it, with the Debian alternatives system (as root):

Bart:~# aptitude install gs-afpl
[...]
Bart:~# update-alternatives --config gs

There are 2 alternatives which provide `gs'.

  Selection    Alternative
  -----------------------------------------------
  * +   1        /usr/bin/gs-esp
        2        /usr/bin/gs-afpl

Press enter to keep the default[*], or type selection number:

There, I just pressed “2”, et voilà! Now my default GS is gs-afpl, and ps2pdf makes use of it. Any other GS version one could want to use, the procedure to change it would be the same.

Comments

Line breaking in LaTeX

I guess every LaTeX user has found herself in a situation when LaTeX would refuse to split a word in a way the user knows correct (but LaTeX doesn’t), and it has caused some kind of trouble in the formatting of the paragraph (or not). It is worth mentioning that LaTeX has a very good knowledge of how to hyphenate English words, and anyway will almost never split a word incorrectly. When in doubt, it won’t split it at all.

When such a situation arises, the user has (as usual with LaTeX) more than one way to fix it. We can tell LaTeX explicitly where it can hyphenate the word. Using an example from Leslie Lamport’s 1985 “LaTeX: User’s Guide & Reference Manual”:

LaTeX does not know how to hyphenate gnomonly. We can write the word like this: gno\-mon\-ly, and then it will know that the word can be splitted at the places where \- appears (the backslash is not an error, it is required).

However, it is an ad hoc solution. We might find ourselves writing gnomonly quite often (well, not really that often), and having to write gno\-mon\-ly all the times gets old after a while (for me, the second time). To avoid this MS Word-ish solution, we can add the following statement in our preamble: \hyphenation{gno-mon-ly gno-mon}. From that moment on, LaTeX will know how to hyphenate gnomon and gnomonly. However, it will still be unable to hyphenate gnomonic (for that, you would have to add that word to a \hyphenation statement, too).

A related problem can happen when long words or expressions appear at the end of a line. It might be impossible to split the word in such a way that the line containing it is not longer than all the other lines in the same paragraph. In such a situation, LaTeX issues a warning of overfull \hbox. To understand the problem, let’s see how LaTeX manages the linebreaks.

The user (through the page settings and style, and all the stuff in the preamble etc.) tells LaTeX six things about lines in paragraphs: desired line width (page width less margins, if it’s a one-column text), desired inter-word space, and minimum and maximum acceptable values for both. When LaTeX writes a text, it does the following:

  1. Choose an interger number of words, so that they are equally spaced by the desired inter-word space, and make the line have the desired line width.
  2. If it is not possible, it tries the least obstrusive fix that gives the best result, from the following:
    • Increase/decrese the inter-word space (within the acceptable limits) untill an integer number of words makes a line of desired width.
    • Split the last word in the line, so that the non-integer number of words makes a line of desired width.
  3. If none of the above yields a perfect line-width, test if it is within the acceptable limits.
  4. If the width of the line is not acceptable, print it anyway, and cast a warning (overfull \hline if it was too wide, underfull \hline if it was too thin, whatever is less incorrect).

Usually ill-sized lines are very ugly on the eye, even for small deviations, and so it would be interesting to fix these errors. It is important to understand that LaTeX’s standards on what inter-word space range is acceptable (and what line width range), are quite strict, and it prefers to stick to them and produce a line that is too wide, giving a warning in the output. Usually this is sensible, but often times we would rather override its standards, and make the freaking line fit in the fixed-width paragraph.

To do so, we can enclose the paragraph between \begin{sloppypar} and \end{sloppypar}. For example:

\begin{sloppypar}
This text that I am writing is in fact astonishingly and utterly incommensurably acojonantemente chungo to fit correctly in a line.
\end{sloppypar}

The sloppypar environment is such that the text within it has a much wider acceptable inter-word space range. This gives it a bigger flexibility in the point 2 above, so that we’ll hardly ever fall to point 3.

Comments

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »