Monday, August 29, 2011

The Linux Programming Interface: a beautifully written technical book

I have been reading, "The Linux Programming Interface" recently. It covers everything about the Linux programming environment: the layout of process space in memory, threads, signals, sockets. Nearly everything you can think of while programming Linux is covered here. Go get it. Now.

It is a beautifully written book. The author, Michael Kerrisk, combines technical knowledge about Linux internals with a clear, precise writing style. This book is fun to read. I have used Linux for many years now, and I found the chapters both illuminating and delightful. At first, I picked it up to learn about memory layout in Linux. I found the writing style so good that I read on, finishing not just that chapter, but many others. I have been reading a chapter at a time at random since. Each chapter deals with a single topic (e.g. Threads) and consists of roughly 25 pages. This is an excellent organisation: it lets you completely understand one area at a time in manageable chunks. Its 64 chapters are spread across 1500 pages, giving it unprecedented breadth and depth.

Technical books are difficult to write. The subject matter can be dry and the terminology makes sentences verbose and difficult to parse. In addition, there is a problem of target audience. You can assume the reader knows too much, making the book inaccessible. Or you could assume too little, and require the reader to go through trivial material that they already know. In addition, technical books are often read with a purpose in mind. They need to answer the question, "How do I do X in Linux" in minimum time. Remarkably, this book does well along all these dimensions. It is a case study in pleasant, lucid writing.


If you do anything with Linux, and have ever programmed in Linux, get a copy now. Keep it on your shelf, and leaf through it when you are bored. You will enjoy the book, and learn more about Linux while doing so.

Tuesday, August 16, 2011

1 Watt webserver

I recently bought a Zipit 2 from an online store. It is a tiny device with an ARM CPU (XScale-PXA270) with 32MB of RAM, an SD card slot, and 802.11 networking. The device cost me $30 including shipping, which is a cheap price for the computing potential. My goal was to run Linux on it, and learn the ARM instruction set. There are many Linux distributions for the Z2, and I found Debian on the Z2 to be perfect. The device is small, light and fits in the pocket of my jeans. Its battery lasts four hours when the screen is on.

Installing Linux on it was trivial: you flash a custom bootloader using FlashStock. This loads a new kernel on the small flash partition on the device, and it gives you the ability to boot from an SD card. Then, you download a Linux distribution for the z2 (I chose z2sid), copy the image to the SD card (using a raw copy tool like dd) and boot from it. I have an 8GB SD card in the Zipit. This Z2 is better than my first Pentium computer along every single dimension except screen size.


Once Debian is installed on the Zipit, you have access to the 'apt-get' package management tool. After installing vim, gcc, make, it turned into a fully functioning ARM development system. I did not want to type using the tiny keyboard, which is uncomfortable and lacks important keys. So I installed an ssh server called dropbear. Now I can remotely log in to the device, copy files back and forth, and use it for development.

Once it was set up, I wondered if I can serve web pages from it. After installing a webserver called nginx, the zipit holds up very well. I'm serving three virtual hosts externally from it, and two hosts internally. For a small amount of traffic, this is the perfect device.

Power consumption

With the screen turned on, the Zipit consumes less than 2 watts of power. When the lid is shut, the screen turns off and power consumption drops to 1 watt. By comparison, a typical laptop consumes 30 Watts and a typical desktop consumes 100 watts. The device is dead silent and cold to the touch. Due to the low power consumption, it generates no perceptible heat. You can leave it in the corner of a cramped closet, and it will chug away. Silently.

There is a lot of potential in these low-power devices called plug computers. Plug computers and mobile devices have caused a resurgence of ARM processors due to their low power consumption. With improvements in processor technology, an entry-level ARM CPU can handle tasks reserved for a "real" computer. Web serving, file serving and ssh-login don't require a beefy processor.  Rather than maintain a full computer, you can purchase a small, silent, and low-footprint computer to handle these tasks for you. Once it is set up, you can store it in a closet somewhere, completely out of sight. Low power consumption allows the device to run exclusively on solar power.

You could use it as an entry point to a home network. Once the SD card is copied to a desktop, you can recover from a malicious attack by copying a known-good image back onto the card.

Low-power computing holds a lot of promise. In the developed world, it can be used instead of power-hungry computers for routine tasks. In the developing world, it can be the first computer for a family.

Sunday, August 07, 2011

Beautiful, professional resumes with LaTeX

I love LaTeX, but when it comes to resume writing, my skills at LaTeX fall short. This means that I have to load up OpenOffice, and spend hours tuning every single spacing and pagination problem.

Enter Moderncv, a class file for professional looking resumes. If you use LaTeX, it is the perfect document class for writing a resume.

This is what my resume looks like:


You can download the resume in PDF. This resume was generated from this LaTeX source file.

The moderncv class is straightforward: you fill in the details and it generates a beautiful, professional resume for you. Once you fill in the critical details, the page layout is handled for you. So if one section is too big it is automatically shifted to the next page. You fill in the contents, LaTeX handles the rest.

Itching to give it a try? To get started, download the moderncv class from CTAN. Either use my resume as an example, or look through the examples directory for a file called 'template.tex'. On Ubuntu, you need the texlive and texlive-latex-extra packages.

On Ubuntu or Debian machines, you can download all the packages with:
$ sudo apt-get install texlive texlive-latex-extra 
 

Lego NXT Mindstorm with Linux

There is a lot of documentation on the NXT and Linux on the Internet. A lot of it is very good, like this page showing Linux setup with NXT. Unfortunately it is scattered all over the place, making it difficult for a complete newbie to make headway with the Lego Mindstorms on Linux. This page links to the major steps and will enable you to set up Linux-Mindstorms communication and the programming environment.

Why Linux?

Linux is better suited for Lego programming. It is essential if you have a Linux machine, and don't want to install Windows (or MacOS) just for using the Mindstorm. But the advantages of Linux go beyond that. Linux is a great programming environment, and interfacing it with Mindstorms allows you to connect it to other devices. Linux machines have a good programming interface for Bluetooth, GPS, networking through the Internet, sound, display, and large-scale processing.  Connecting the NXT to a Linux device opens up a lot of possibilities.

Also, many netbook computers are ideal robot building blocks: they are small, light and lack fragile spinning disks. Linux is space efficient, and runs well on these devices.


Journey

These are the steps you need to be completely up and running with Linux and the NXT. These pages are listed in order, and each page builds upon the previous work.
  1. Setting up the Linux-NXT Bluetooth connection
  2. Setting up the Linux-NXT NXC programming environment
  3. Writing a program that demonstrates NXT Robot-Linux communication over Bluetooth 
With a little bit of setup, you can combine the flexibility and design of the Mindstorms with the power of Linux.