Perhaps the only person who makes more extravagant claims about Git than I do

"Git is the next Unix":

Git was originally not a version control system; it was designed to be the infrastructure so that someone else could build one on top. And they did; nowadays there are more than 100 git-* commands installed along with git. It's scary and confusing and weird, but what that means is git is a platform. It's a new set of nouns and verbs that we never had before. Having new nouns and verbs means we can invent entirely new things that we previously couldn't do.

With git, we've invented a new world where revision history, checksums, and branches don't make your filesystem slower: they make it faster. They don't make your data bigger: they make it smaller. They don't risk your data integrity; they guarantee integrity. They don't centralize your data in a big database; they distribute it peer to peer.

Much like Unix itself, git's actual software doesn't matter; it's the file format, the concepts, that change everything.

The author describes a whole bunch of projects he worked on or heard about where Git would basically have satisfied all the needs of the project while being faster, smaller, and more secure.

Essentially, Git could serve as the base for many more version control system-type tools than just the ones that are called Git today. Myself, I'm looking forward to version control that's suitable for entire disks (perhaps with automatic history pruning) and better ways to be able to easily deal with large projects that contain smaller modules. But there are undoubtedly better ways of doing things than our untrained minds are capable of even imagining right now.

Interview with Eben Moglen

Eben Moglen, in an interview:

The primary desire that businesses have is for control over their own destinies, for avoidance of autonomy bottlenecks which put the fate of their business into the hands of someone else. The difficulty that they experience — that they call vendor lock-in, or noninteroperability — is a difficulty which is really a businessman's equivalent of Stallman's frustration at unfreedom. They are essentially the same recognition: In a world of complex, interdependent technology, if I don't control my technology, it will control me. Stallman's understanding of that proposition and Goldman Sachs' understanding [for example] needn't be as far apart as one might think. The desire to maintain autonomy — the desire to avoid control of destiny by outside parties — is as fierce in both cases as it can get.

Indeed, I still find it difficult to argue that unfree software is immoral (except using very theoretical arguments), but it is certainly bad business sense. Using proprietary software is like handing the reins of your company's infrastructure to an outsider.

What is interesting about free software is that it is a commons which does not suffer from the tragedy of the commons. It is valuable because of its freedom, not despite its freedom.

A wonderful abuse of regular expressions

As it turns out, you can use regular expressions to test primality.

You'll need a regular expression engine that supports backreferences to do this. (Intuitively, a more restricted matcher that can be implemented as a finite state machine cannot count up to arbitrarily large numbers.)

I tried this in GNU egrep. I made this input file, which contains a number on each line followed by that number of stars:

$ cat numbers.txt
 2 **
 3 ***
 4 ****
 5 *****
 6 ******
 7 *******
 8 ********
 9 *********
10 **********
11 ***********
12 ************
13 *************
14 **************
15 ***************
16 ****************
17 *****************
18 ******************
19 *******************
20 ********************

Then, to find only those lines corresponding to prime numbers:

$ egrep -v " (\*{2,})\1+$" numbers.txt
 2 **
 3 ***
 5 *****
 7 *******
11 ***********
13 *************
17 *****************
19 *******************

Intuitively, the regular expression identifies composite numbers by seeing whether they can be written as a group of two or more stars, followed by one or more repetitions of that group. Writing the line in such a way corresponds of finding a factorization of the corresponding number into two other integers, both of which are greater than 1. The implementation basically carries out trial division by letting the first group be equal to **, then to ***, ****, etc. The -v option to egrep only prints those lines which do not match the regular expression, that is, the prime numbers.

Here's the catch:

Back-references are very slow, and may require exponential time.

(man page for GNU egrep)

Thank you, HP and Intel

I recently set up an HP all-in-one printer/scanner/fax (an Officejet 5610) on my house network.

Thanks, HP, for providing free drivers for the printer and the scanner. I set up the device directly through my OS and I don't have to use a crappy vendor-specific frontend to scan and print. I've had a bad experience with a Brother scanner (which didn't provide an open source driver, only a really flaky binary), so this is quite refreshing.

In Ubuntu, the printer drivers (PPDs) are in the package hpijs-ppds and the scanner drivers (SANE backends) are in the package hplip, I think. Our Officejet now happily scans and prints over the network with SANE and CUPS. Standards, I love you.

Which reminds me, I'm also thanking my lucky stars for the free drivers for components on my Thinkpad X61s. The Intel integrated graphics (965GM) and the Intel wireless chipset (4965AGN) just work out of the box on Ubuntu. Thanks, Intel!

Setting up reverse SSH

With SSH, you can use local forwarding to access a service that's available from a well-known host. For example:

localhost$ ssh -L 8080:remotehost:80 corporate

asks localhost to take requests to http://localhost:8080/ and relay them through corporate to http://remotehost:80/. This is handy if the host remotehost is accessible from corporate but not from localhost. Note that the client, localhost, can be anywhere (e.g. behind a NAT or a firewall) because it is the one initiating the SSH connection.

You can also do the reverse (also known as reverse SSH), forwarding in the other direction to allow a service behind a NAT/firewall to be accessible from a well-known host. For example:

localhost$ ssh -R 8080:localserver:80 corporate

asks corporate to take requests to http://corporate:8080/ and relay them through localhost to http://localserver:80/. This is handy if localserver is a host which is accessible from localhost but not from corporate. Note that the proxy and server, localhost and localserver, can be anywhere (e.g. behind a NAT or a firewall) because localhost is the one initiating the SSH connection. This setup can be used by trusted users inside a firewall to circumvent the firewall.

I frequently connect from my laptop to a desktop machine to do work. I've configured reverse SSH to allow SSHing from my desktop to my laptop so that I can, for example, save files to my laptop using a program on my desktop. Again, this works whenever I connect, even if my laptop connects from behind a NAT/firewall, or if I'm just on some network where I haven't bothered to look up my IP address.

To do this manually, add a remote port-forward and use that port to connect from the remote end:

laptop$ ssh -R 8889:localhost:22 desktop
desktop$ ssh -p 8889 localhost
laptop$

Now, this is sort of unwieldy, so I've configured my .ssh/config to fill in all the boring parts automatically. On laptop:

Host desktop
  RemoteForward 8889 localhost:22

Then, on desktop:

Host laptop
  HostName localhost
  HostKeyAlias laptop
  Port 8889

Now the login sequence is much more streamlined:

laptop$ ssh desktop
desktop$ ssh laptop
laptop$

Notice the HostKeyAlias field. Old versions of OpenSSH would barf if, on desktop, you SSH'd to both localhost:22 and to localhost:8889, because it would see two different host keys associated with the same host and think that there was a man-in-the-middle attack going on. This is a common problem whenever port-forwarding is used. The HostKeyAlias is your way of telling SSH, "no, this connection I've set up has its own host key which you should remember, but that host key is different from that of localhost". (I think newer versions of OpenSSH are smart enough to remember the host key on a per host/port basis, so they aren't subject to this problem.)

2007 in Review

What did I do and learn last year?

Emacs

Emacs is a Lisp-based operating system which I occasionally use for editing text files. When you type in a text box in a normal application, you are just typing in a little box. When you work in Emacs, the thing you are editing an extension of your mind. After becoming acclimated to this, using a regular editor is incredibly frustrating in that you can feel the lag between what you are thinking and what you are actually capable of doing with your hands.

I taught a class on Emacs last IAP and have been ramping up my Emacs usage since then. Using Emacs leads to a virtuous cycle of productivity: you do your work in Emacs, discover patterns in the things you do, then automate those patterns using macros and code. In Emacs, it's trivial to find out how the keys you press translate into function calls, so unlike most automation languages, you never have to look up some crazy API in order to code an equivalent for what you were already doing.

For coding, some people swear by Eclipse (for Java and C++ work, at least). What I think they don't realize is that time spent refactoring and remembering symbol names is a drop in the bucket compared to the time spent typing and moving text around, and no IDE comes close to Emacs as an editor.

I'd characterize Emacs as having a text UI for input combined with a graphical UI for output, taking advantage of the high-bandwidth link in both directions. Unlike typical GUI programs, Emacs isn't used to whitewash the underlying OS and programs; rather, it augments them. Emacs gives you the full power of command-line tools without the limitations of shell interaction. The biggest of these limitations is what I call "linearity". Once you run a command, you can look at its output, but the output is dead: you can't edit it (unless it occurred to you to save it to a file first), and you can't act on it directly except in very restricted ways. In Emacs, every significant piece of text you see appears in a buffer, where you can bring to bear all your editing skills and execute context-specific commands in the buffer. Read the Emacs guided tour for more of my thoughts on this (with examples).

Git

Git is a versatile content tracker which I've started using mostly as a local VCS and as file synchronization software. It is astonishingly easy to set up and use locally (at least after trying to use CVS and SVN), so I've started using it for managing almost all of my projects.

Git has changed the way I write software. When version control is fast, no change is too small to commit by itself. Smaller and logically coherent changes make it easier to isolate bugs. In addition, always having a nearby baseline version makes it easier to think about what I am trying to do at any particular time. When branching is fast enough to use regularly, taking a detour to try something new and ambitious doesn't interfere with the rest of your work.

Having really easy replication is quite reassuring. I actually trust Git to synchronize my files correctly, regardless of when I modified my files on which hosts since the last synchronization, something which is not true of, say, rsync.

Free software

I came for the power, but I stayed for the freedom.

I think at some point in 2006 I switched over completely to using GNU/Linux. In 2007 I stopped using nonfree software entirely on my primary work computer (now a Thinkpad X61s I got this fall, which works great, by the way).

I love the ethos associated with free software. Astonishingly, some people have software that doesn't allow them to (1) use it in any way they wish (2) share a good thing with their friends (3) learn from it by taking it apart (4) tweak it to suit their needs (or pay someone else to do so). How backwards is that?

What bothers me the most about proprietary software is its use in education. Many proprietary software makers "subsidize" students by offering their software cheaply. In reality, by teaching proprietary software in schools, the education system is subsidizing the software makers: if all I've used in school is Microsoft Word, then I am beholden to Microsoft when I graduate. It goes against the very idea that education is supposed to make people self-reliant, but for public money to be spent this way is particularly horrifying.

Computers are tools of empowerment. That's why free software is important: as we've seen in recent years, if you are running proprietary software on your computer, it is in a sense no longer "your computer". That's why the OLPC project excites me: it's an attempt to empower children rather than to give them a cheap handout (not to mention, it created a market segment where none existed two years ago, but that's another story).

I realize that some people do not respond to arguments like the above in favor of free software, which is why I think it is also important for those among us with the knowhow to make free software as good as it can be. It's not just hackers who benefit from free software, but hackers will have to lead the way.

Comparison of regexp syntax

To help myself learn Emacs regular expressions, I've put together this cheat sheet comparing regular expression syntax in Emacs, Python, and egrep.

Note that in Emacs, the syntax described below is for regular expressions that are entered directly (e.g. in isearch-forward-regexp and occur). When you provide a regexp in a string (e.g. in Lisp code or in re-builder) you need to double all backslashes.

Emacs Python egrep
Any character . . .
Beginning of line ^ ^ ^
End of line $ $ $
0 or more repetitions * * *
1 or more repetitions + + +
3-5 repetitions \{3,5\} {3,5} {3,5}
Optional ? ? ?
Character set [...] [...] [...]
Alternatives \| | |
Group \(...\) (...) (...)
Named group (?P<name>...)
Non-capturing group1\(?:...\)(?:...)
Word boundary \b \b \b
Digit [[:digit:]]\d [[:digit:]]
Whitespace char \s- \s
Alphanumeric char \w \w \w
Back reference \1 \1
Named back reference (?P=name)

1 Also referred to as "shy groups".