Reverting All Buffers

I have two machines on which I do most of my writing and development: a 27″ iMac and a 5 year old MacBook Pro. I use both of these computers everyday so I need to keep them in sync. I do that with Git repositories that live on a separate Linux server. One of those repositories contains all my org files. That includes blog posts, todo and task lists from my org agenda, and various other files that I maintain with org-mode. Those, along with all the other archived files means that I have a lot of files to keep up to date.

The first thing I do when I begin a session is a git pull to make sure I have the latest files from the other machine. Of course that means I have to be religious about pushing any changes to Git but that’s pretty much second nature now. The other thing you need to know is that when I’m finished with a session, I just put the machine in sleep mode. That means my Emacs still has all the open files from the last session when I get back to it. I also have desktop-save-mode on so this happens even if I turn the computer off or reboot it.

Here’s the problem. After the Git pull, those buffers and their underlying files are no longer in sync. I could set Emacs to automatically sync them but I don’t want to deal with the overhead. Thus I have to run revert-buffer by hand for each of the updated files. That’s a pain, of course, and cries out for automation so I wrote a quick bit of Elisp to do it for me. Here’s the code

(defun revert-all-buffers ()
  "Revert all non-modified buffers associated with a file.
This is to update existing buffers after a Git pull of their underlying files."
  (interactive)
  (save-current-buffer
    (mapc (lambda (b)
            (set-buffer b)
            (unless (or (null (buffer-file-name)) (buffer-modified-p))
              (revert-buffer t t)
              (message "Reverted %s\n" (buffer-file-name))))
          (buffer-list))))

The code is pretty simple. It goes through the buffer list looking for buffers with an underlying file. If the buffer is not dirty, I call revert-buffer to get the changes from the Git pull into the buffer. If I’ve made changes to the buffer, then I have to fix things up by hand so I don’t want to do the revert.

It seems to me that there’s nothing special about my work flow so others may have the same problem and find revert-all-buffers useful.

Posted in Programming | Tagged , | 9 Comments

RSA Explained

Barry Steyn over at I’m Still Learning has a nice post on RSA and how it works. Steyn explains the needed mathematical background in small pieces that should be accessible to everyone. At each step he works through a small example so that the reader can follow the process.

If you’ve ever wondered what’s behind RSA, how it works, and what its weaknesses are, this post is an excellent introduction. Steyn even explains modular arithmetic so if the statement 11 divided by 4 equals 2 remainder 3 makes sense to you, you will have no problem following his exposition.

Posted in General | Tagged | Leave a comment

The Emacs CL Controversy

The other day I was griping to Xah Lee off-line about the refusal of the Emacs maintainers to add the CL package functionality to the core Elisp distribution. Lee pointed me at several threads on the emacs-devel mailing list that explained both sides of the controversy. Now Lee has summarized those threads for the benefit of anyone else who may be interested.

My own opinions are somewhere in between the two extremes. I have no particular desire to make Elisp into Common Lisp so I tend to think of the CL package as adding useful functions to Elisp rather than making Elisp into CL, which the package certainly doesn’t do. Some folks, like RMS, may find CL ugly and they’re entitled to that opinion but why should that be an excuse to exclude things like incf, reduce, and remove-if-not useful functions that get implemented (for various values of implemented) by every Elisp user who makes the decision not to add

(require 'cl)

to their programs.

Other excuses, such as “it would make the Emacs manual too large” are non-starters. It would make the manual too large. Really? That’s your reason for not including the CL functions in core Elisp? Sorry but if you say stuff like that don’t expect people to take you seriously even if you are RMS.

Others have noted the plans to replace the Elisp engine with Guile (Scheme) but those plans actually call for using the Guile engine with its Elisp language layer not for replacing Elisp with Scheme so I don’t see how that fact enters the argument at all. You still need some sort of reduce function when writing in Elisp whether the underlying engine is the traditional Emacs one or Guile.

Sadly, this question has devolved into a religious argument so we can expect no resolution in any time span meaningful to human beings. Still, it would be nice if we could just add those functions that almost everyone agrees are useful and not mention Common Lisp at all. Can’t we just pretend we found them lying on the side of the road?

Posted in Programming | Tagged , | 3 Comments

Flame Malware Uses New MD5 Collision Attack

Much has been written lately about the provenance of the Flame malware. Recent reports suggest that it was a joint project of the United States and Israel. Now comes the startling revelation that Flame used a hitherto unknown MD5 collision attack to forge a Microsoft certificate used for security updates.

Cryptanalist Marc Stevens who published the first practical MD5 collision attack in 2009 has analyzed the MD5 collision attack in Flame and concluded that it used a previously unknown attack. This suggests, he says, that the team who wrote Flame included world-class cryptanalysts and mathematicians.

After Stevens revealed his attack, the use of MD5 to authenticate certificates was deprecated and its use quickly died out. Microsoft, however, continued to use a certificate signed with MD5 for its security updates and that was how Flame was able to infect its targets.

Posted in General | Tagged | Leave a comment

Installing Aspell

As I posted yesterday, it turns out that I have some old 32 bit software left over from Fink installs on my machines. As far as I know, none of it was being used except for Ispell. Once I got rid of the /sw subdirectory, I needed a new version of Ispell for Emacs. As long as I was changing things I also looked at Aspell and compared their features. No doubt about it, Aspell is superior but Ispell had one advantage: it has a filter that allows it to work with nroff files. Because I do a lot of writing using Troff, this was important to me so I decided to just update Ispell.

That turned out to be harder than I thought. Despite having a configuration file for OS X, it wouldn’t even compile on my machine. I played around with it a little until I decided that I was just wasting my time and that Aspell probably made more sense anyway. Unlike Ispell, the Aspell installation was a snap.

First go to the Aspell site and download the latest version by clicking on the “latest version” link. Then click on the “available dictionaries” link to choose a dictionary. I put both of these in ~/tars/, which is where all my tars live, and then unpacked them into ~/tools/ with

cd ~/tools
tar -xvzf ../tars/aspell-0.60.6.1.tar.gz
tar -xvjf ../tars/aspell6-en-7.1-0.tar.bz2

next I built Aspell with

./configure
make
sudo make install

The last line will install Aspell in /usr/local/bin. You can also copy the Ispell and Spell emulation scripts, if you want them, with

sudo cp scripts/ispell /usr/local/bin
sudo cp scripts/spell /usr/local/bin

Finally I installed the dictionary with

./configure
make
sudo make install

At this point I had a working Aspell. The last step was to tell Emacs to use Aspell, which I did with

(setq ispell-program-name "/usr/local/bin/aspell")

Then I restarted Emacs and was up and running again.

So far, I really like Aspell. It is much better at suggesting alternatives for misspelled words and seems every bit as speedy as Ispell. If you’re still using Ispell for hysterical raisins you might want to give Aspell a try instead. I think you’ll like it.

Posted in General | Tagged | 2 Comments

Building Emacs 24 on OS X Lion

Now that Emacs 24.1 was officially released it was time to stop messing around and actually get it installed. I tried that last year but had problems with configure not finding tputs in any of the curses libraries. This time it was even worse.

The first problem was that configure couldn’t find gcc. Regular readers will remember that my laptop recently underwent significant sugery and had a complete OS reinstall. It turns out that the new Xcode doesn’t automatically load the command line versions of the compilers. Fortunately, Graeme Mathieson over at Notes from a Messy Desk had the answer. It’s a little involved so I’ll just send you over to Mathieson’s blog if you need to do this. I will note, though, that I didn’t bother with OSX GCC Installer and just used Xcode to load the command line tools as Mathieson explains.

After getting over that problem I was back to having configure fail while looking for tputs. I knew that the ncurses library was installed and that tputs was there so I couldn’t understand why configure was failing. After trying various things, I finally just commented out the test for tputs in configure to see what would happen. That change made configure run but then the compile failed. That failure gave me the final clue as to what was happening. Long ago I used the Fink package manager but stopped after OS X moved to 64 bits because it was too hard to get Fink upgraded. However, the /sw directory in which Fink installed its software was still there and in that subdirectory was an old 32 bit version of ncurses. As the error message from the compile made clear, the linker was finding this outdated library and quitting because it couldn’t use it. Once I got rid of /sw everything worked fine and I know have a working Emacs 24.

None of this would be worth a post except for the fact that during my research into the problem I found several others who had the same problems. Perhaps they will find the help they need in this post once Google gets around to indexing it

Posted in Programming | Tagged | 4 Comments

Hashing Passwords

Patrick Nielsen over at Throwing Fire has an excellent post on Storing Passwords Securely that serves as a nice coda to my previous post on Password Advice. One of the problems that I pointed out in that post was the failure of Child Support Services to hash their passwords. Nielsen explains why this is a huge mistake.

More importantly and interestingly, Nielsen explains how to do the hashing correctly. He mentions most of the common libraries and their strengths and weaknesses. It turns out that doing it correctly is a lot more subtle than just running the password through MD5 and storing the result. Even the original Unix password hashing scheme did better than that: it used several iterations of a modified DES algorithm on a salted password. Today, machines are much more powerful and those involved with password cracking are building cheap, specialized machines using GPUs that can check billions of MD5 hashes per second.

Defending against all this is non-trivial and if you’re involved with securing passwords you should definitely take a look at Nielsen’s post. It’s got a lot of good advice and information.

You might also want to take a look at Poul-Henning Kamp’s article in the acmqueue on the dangers of not salting passwords and stretching hashes as illustrated by the recent LinkedIn password exploit.

Posted in Programming | Tagged | Leave a comment

Replacing a Region With the Last Kill

I learned a another neat trick from Aaron Hawley’s Giant Emacs Reference Sheet. This is another of those tricks, like the revert buffer shortcut, that uses keystrokes intended to do something else in a novel way to accomplish something unexpected.

In this case, we want to replace the current region with the last kill. Hawley says to do this with 【Ctrl+w Ctrl+y Meta+y】. This looks odd because the 【Ctrl+w】 is already a complete shortcut.

If you look at the entire sequence carefully, you see that it accomplishes the task in 3 steps:

  1. Ctrl+w】 kill the region
  2. Ctrl+y】 yank it back
  3. Meta+y】 replace the last yank with the penultimate kill

So it’s really just a matter of combining 3 commands to do something new. A very nice trick and easy to remember because it’s not really anything new.

Posted in General | Tagged | 4 Comments

A Page on Emacs 24’s New Features

Xah Lee has started a page on New Features in Emacs 24. He’s promising to add to it every few days so it might be a good place to go to get familiar with some of Emacs 24’s new goodies at a leisurely pace.

Posted in General | Tagged | 3 Comments

Muscle Memory

I can so empathize.

Posted in General | Tagged | 1 Comment