Wednesday, December 16, 2009

Unfortunate cutoff

If you are writing a piece of text that may be cut off, pay some extra attention to your first sentence…

Sunday, December 6, 2009

Reinstalling GRUB with LVM from the Ubuntu cd

This post is mostly a reminder to myself. Every time I reinstall Windows, it overwrites my boot sector, and I need to reinstall it from the Ubuntu live CD to get my dual-boot system back. However, since my Ubuntu install is inside an LVM partition, this is not very straightforward. Here are the instructions. I kept them general so that they may be of use to someone else as well.

  • Start from the Ubuntu CD and open a terminal.
  • Install LVM:
    sudo apt-get install lvm2
  • Find the name of the volume group:
    sudo vgdisplay
  • Make the volume group available:
    sudo vgchange -ay name-of-vg
  • Mount the root and boot file systems, and bind the dev file system:
    sudo mkdir foo
    sudo mount /dev/name-of-vg/name-of-root-lv foo
    sudo mount /dev/name-of-boot-partition foo/boot
    sudo mount -obind /dev foo/dev
  • Change to the root of your system:
    sudo chroot foo
  • Drop into the GRUB prompt:
    sudo grub
  • Install the GRUB MBR (assuming that (hd0) is your boot drive and (hd0,0) your boot partition):
    root (hd0,0)
    setup (hd0)
  • Reboot and have your boot menu back!

Saturday, October 17, 2009

Disabled for your protection

My Firefox, on Windows, just reported that it had disabled the Microsoft .NET Framework Assistant 1.1 extension and the Windows Presentation Foundation plugin. Supposedly, these were security issues. If I'd be so kind as to restart the browser for the changes to take effect.

Well, whatever, go ahead. After the restart, the Extensions window pops up, showing .NET Framework Assistant as “Disabled for your protection.” Phew, thank you.

But now I'm curious. What's so evil about these Microsoft plugins that Mozilla feels the need to block them automatically? Luckily, there is a “More Information” link right there in the dialogue! So I click it:

It's great to see that Mozilla really cares about my security.

Friday, September 25, 2009

Digital signatures made easy

Some time ago, a friend of mine discovered that somebody was plagiarizing the content of this blog. I'm not going to provide this guy with link juice, but you can find it through Google easily. The post is an exact duplicate of my Visual C++/Studio: Application configuration incorrect?, except for the title. Even my remark at the end, which clearly suggests that the author of the post is also a developer on Taekwindow, has been copied with the link intact.

Now imitation is the sincerest form of flattery and all that, but stealing my content without even mentioning my name goes too far. I posted as much on this guy's blog, but have received no response. So in the end I overcame my aversion and filed a DMCA infringement notification to Blogger.

Have a look at that form. Scroll all the way down. What will you see? Look at that! Isn't it beautiful? I'm supposed to sign a digital form… by typing my “signature” in a text box! Also, this is legally binding!

That cracked me up. It cracked me up so completely that I typed a beautiful capital X in that box and hit Submit.

Today, I received an e-mail from Blogger. It said:

We have received your DMCA complaint regarding dated 09/20/09. Our policy requires that DMCA complaints be signed by the copyright owner or an agent of such. As your DMCA complaint was unsigned, we cordially request that you re-send us a signed copy of your notice by fax to (650) 618-2680. Once we receive your complaint, we will investigate the issue and process your request accordingly.

I still wonder what would have happened if I'd just typed my name into that box.


Monday, September 14, 2009

Centering a figure on the page in LaTeX

With those wide margins of LaTeX, it sometimes happens that you have a figure or table that is too wide, and just sticks out to the right. Chances are that you want it centered, sticking out equally to the right and to the left, but tough luck: the standard center environment still aligns it with the left margin, and so does the \centering command.

I was about to write a package to provide an environment that centers its content on the page instead of inside the text. This is not too difficult, but preventing the overfull \hbox errors is tricky (they are so bad that even \hbadness=10000 has no effect). But then I stumbled into a standard LaTeX command that does exactly what I want.

So here's how to center your figure whilst ignoring the text margins:
It also works inside float environments such as figure. That was easy!

Friday, July 3, 2009

Speeding up Kile

Even though I'm mostly a Gnome user, my LaTeX editor of choice is Kile. Unfortunately, it can become a bit sluggish, especially when dealing with long lines. (I hate artificial line breaks, so I just type one line per paragraph and turn on dynamic word wrapping.)

This seems to have something to do with rendering. To make Kile considerably faster, start it like this:
kile --graphicssystem raster
Instead of raster, you can also try opengl, which is supposed to be even faster, but not considered stable yet. YMMV.

Monday, June 15, 2009

Creating a multi-page PDF from images

It is often convenient to pour a series of JPEG (or PNG, or GIF) files into a PDF, for example for printing or for e-mailing. Given the power of the Linux command line, this is surprisingly difficult, but I found a fairly straightforward way to do it. Skip to the bottom if you just want the oneliner.

Many websites will tell you the following:
convert *.jpg output.pdf
Easy, no? Don't do this. Why? Look at this:

-rw-r--r--  1 thomas thomas 129826204 2009-06-15 15:29 output.pdf
-rw-r--r--  1 thomas thomas    947022 2009-06-15 15:04 page1.jpg
-rw-r--r--  1 thomas thomas    962956 2009-06-15 15:05 page2.jpg
-rw-r--r--  1 thomas thomas    925291 2009-06-15 12:54 page3.jpg
-rw-r--r--  1 thomas thomas    952717 2009-06-15 12:54 page4.jpg
-rw-r--r--  1 thomas thomas    642471 2009-06-15 15:08 page5.jpg

The original JPG files are less than 5 MB altogether, but the resulting PDF is a whopping 124 MB! Clearly, convert (from the otherwise excellent ImageMagick bundle) re-encodes the images somehow, instead of embedding them straight into the PDF file.

Enter the little-known utility sam2p. It comes in an Ubuntu package of the same name. In its simplest form, it converts a single image file into a PDF by embedding the image file into the PDF file. For example:
sam2p page1.jpg page1.pdf
One of the shortcomings of sam2p is that it does not allow you to set the page size directly, so you'll end up with PDFs that exactly fit the original images.

Now we can generate all the pages as separate PDFs, but sam2p cannot create a PDF with multiple pages. Enter pdfjoin from the pdfjam package (available in Ubuntu under that name). It is simple to use:
pdfjoin page*.pdf --outfile output.pdf
This will use a consistent page size, so it is no problem that sam2p spit out pages of arbitrary size. It defaults to A4 paper; specify --paper letterpaper to use the Letter format.

Because I'm lazy, I wrote a little bash oneliner to do the trick, then let my readers improve upon it (thanks Mark, thanks Eamon!). It is now a twoliner, but who cares:
find . -maxdepth 1 -iname 'page*.jpg' -exec sam2p '{}' '{}'.pdf \;
pdfjoin page*.pdf --outfile output.pdf
This assumes that your input images are named page1.jpg, page2.jpg etcetera, and that there are no files named like page*.pdf in the current directory. If you have more than 9 pages, remember to prefix a zero to keep them in order. If you want to do this for PNG or other images, remember to change the extension in both places.

Tuesday, May 19, 2009

Wednesday, May 13, 2009

Accepted for Google Summer of Code!

I have been accepted for Google Summer of Code 2009! The title of my project is “Extend EclipseFP functionality for Haskell.” I have just set up a blog where I can keep all posts together that are related to this project. (This blog will also allow me to test-drive Wordpress, because as we all know Blogger sucks.) You can find more information at my new blog: EclipseFP GSoC '09.

Wednesday, February 25, 2009

Sumatra PDF Viewer for LaTeX users on Windows

If you use LaTeX on Windows, or in particular pdflatex, you must have noticed that viewing the resulting PDF file is not as easy as you would think.

Sure, Adobe Reader displays it fine. But apart from being bloatware and slow as hell, it also locks the PDF file it is displaying. Thus you cannot rerun pdflatex until you close the file in Reader, because the output file cannot be overwritten. This is a pain in the arse.

Foxit Reader seems like a decent alternative; it is much faster and less bloated than Adobe Reader (even though the installer tries to get you hooked on several other pieces of software that you probably don't want). Foxit does not lock the currently viewed file; however, it offers no reload option, and if you overwrite the output file, it will only display blank pages for what's not currently cached.

Enter Sumatra PDF. A very lightweight and very simple program, contained in a single executable file, written by a single developer, but it has the one killer feature that LaTeX authors need. It automatically reloads the PDF file whenever it changes. And it stays on the same place in the document while it does this.

There is currently a bug that causes the window to demaximize when it reloads, but you can work around that simply by not maximizing the window in the first place. This little viewer will definitely make my life easier.

Tuesday, February 3, 2009

Sunday, February 1, 2009

USB: the right direction

USB plugs are annoying, because it's hard to see how to plug them in, and you have only a 50% chance of getting it right on the first try. But I recently noticed what seems to be a little-known feature that increases your odds. There is a little USB logo on one side of nearly all plugs. It seems that manufacturers mount their ports in such a way that the logo should face upwards.

I haven't figured out the case of side-facing ports yet, but maybe there is a pattern there as well. If your computer has such ports, let me know in the comments which way the logo should face on those!

Thursday, January 22, 2009

Sequential page numbering in LaTeX

Did you ever notice that the page number that your PDF reader gave you was not the same as the page number printed at the bottom of the page? By default, some LaTeX commands, such as \tableofcontents, reset the page number to 1.

I don't like this behaviour. I just want my cover page to be numbered 1, the next to be numbered 2, etcetera. This way, the ‘physical’ and ‘virtual’ page numbers line up nicely. It also prevents some problems with hyperref, which will otherwise create duplicate page labels.

You can get sequential page numbering by putting the following snippet in your document preamble:


This simply overrides \setcounter, such that it ignores any attempt to set the page counter, which holds the current page number. Ugly, but it works.

Thursday, January 15, 2009

Verified by Visa – verily?

Today I ran into an excellent example of false security – with horrible usability to boot. I was helping my landlady to purchase a laptop online using a Visa card. At the checkout step, a screen appeared that we did not understand. It came from Visa itself and asked for the password associated with the credit card.

The password form was in an IFRAME, so the address bar did not light up green. I did not bother to check the security certificate by hand, or else I might not have dared to continue at all.

But we did read the FAQ that was linked to. As it turned out, this “optional” ‘Verified by Visa’ system makes online purchases more secure. It did not seem at all optional. Well, only more secure then. Right?

Wrong. How exactly does one get a Verified by Visa password? Let's click the “forgot your password” button and find out. To reset the password, you need to specify:

  • the 3-digit card validation code
  • your name, as written on the card
  • the card expiry date
  • the year and month of your birth

The first three of these four pieces of information are written on your credit card, and also submitted in any web form that involves a credit card purchase. By assumption, an attacker already has this information, or else the extra password protection wouldn't serve any purpose. So the only extra piece of information that is asked for is your birth year and month. Not exactly information that is hard to find, or even to brute-force if you put your mind to it. They might as well have skipped the password and asked for your birth date instead.

But well, it doesn't make you any less secure, so we continued to set up a password. First attempt failed: “use letters and numbers only”. Because, you know, secure passwords do not involve special characters at all. Second attempt: “please use both letters and numbers”. If you're going to use stupid limitations, at least tell me beforehand. Third attempt: “please use between 8 and 12 characters”. By now it seemed more like a CAPTCHA to me.

Then, finally, the password was accepted and we could proceed… to the next error message. Turns out that NoScript blocked the transaction, even with Javascript turned on. If NoScript does that to you, it probably means that you're doing something very, very wrong. But finally, after convincing NoScript that it was okay, the payment got through.

Stupidity can, in rare cases, be forgiven. But not if you're the largest credit card issuer in the world.