Sunday, April 13, 2008

Renaming a Pack-o-Files

A friend asked me a question that got me thinking that emacs must provide an easy way to rename a bunch of files in a directory from one thing to another. E.g., suppose I want to rename every file ending in .doc to a .tex extension. Point emacs at the directory, and type %m This fires off dired-mark-files-regexp, which selects files matching a regular expression. For the regular expression, try .doc$ Hit enter after each command. The '$' indicates that the pattern must occur at the end of a line. Now you can rename the marked files: %r This invokes dired-do-rename-regexp, which, for every marked file, asks what pattern to replace: doc$ It then asks what to change matching substrings to: tex ¡Voila! Much of the above is condensed from

Monday, April 7, 2008

Linux, Unix, and all That

"Those who don't understand Unix are condemned to reinvent it, poorly" --Henry Spencer "It seems few Linux developers understand Unix" -- me.

MD Funds Move Away from DRE Voting Machines

In a move that will both save Maryland taxpayers a considerable chunk of money and make voting in Maryland more secure, the general assembly just funded the replacement of electronic voting machines by machines with optical scanners. The move is expected to save the state $6M annually. The switch has been promised for some time, but there's always been the chance that it wouldn't be funded. Wired recently reported on a study on the cost of e-voting which outlined how the cost of the Diebold machines, though higher than the cost of other voting technology, is only the start since Diebold also charges for training, maintenance, software upgrades, etc. Other recent stories have centered about Linda Lamone, the administrator of the state board of elections appearing in a Diebold ad and the fact that the physical security of Maryland's machines lies in the hands of John Kane, former chairman of the MD Republican Party. Couple this with former Gov. Ehrlich's description of the SAIC study of the Diebold machines as a "positive report," though the report, commissioned by the state of Maryland said that the Diebold machines "do not, in many cases meet the standard of best practice or the State of Maryland Security Policy." SAIC went on to say they found "several high-risk vulnerabilities in the implementation of the managerial, operational, and technical controls for AccuVote-TS voting system. If these vulnerabilities are exploited, significant impact could occur on the accuracy, integrity, and availability of election results." In sum, there were always a large number of questions about how Maryland came to get electronic voting machines and how they were managed.

Saturday, April 5, 2008

kcalc, gcalctool

A lot of people dislike kcalc, and a lot of people don't like the Gnome calculator. One feature I do like about the Gnome one is the insert ASCII value feature. I tend to use xcalc and am generally happy with it. IMHO it's more usable than either of the other two, especially since it has an RPN mode. OTOH, I tend to use spreadsheets for a lot of things that I used to use calculators for.

Is the iPod Shuffle Mode Really Random?

I don't have an iPod and have never used one, but the obvious answer is "No." I've recently heard this discussed on the Network Security Podcast and on NPR Weekend Edition. What's random on a digital device? A good example is Stephen Park and Keith Miller's minimal standard generator (see their 10/88 CACM article). This is (perhaps) the same generator, being based on a linear-congruential generator from Dr. Park's simulation course at William & Mary, spring 1986:
double Random(long *seed) {
  const int a     = 16807;       /* multiplier */
  const int m     = 2147483647;  /* modulus */
  const int alpha = 127773;      /* m div a */
  const int beta  = 2836;        /* m mod a */

  int    lo, hi, test;

  assert(*seed > 0);

  hi = *seed / alpha;
  lo = *seed - alpha * hi;
  test = a * lo - beta * hi;
  if (test < 1)
      *seed = test + m;
     *seed = test;
  return ((double) *seed / (double) m);
This produces a stream of pseudorandom numbers, with the stress on pseudo. Random number generation is hard, and there are many, many bad generators out there--see the Park & Miller article.

The guys on the network security podcast discuss randomness in the context of human perception, which is also a big part of the NPR piece. One of the NSP guys (Rich) referred to people as pattern recognition machines since they will tend to see patterns in randomness. The guest on that episode, Mike Murray, instead refers to people as pattern creation machines: "People create patterns in their heads where randomness occurs."

This discussion is part of a larger one on the undersea cable breaks of early 2008 and, of course, the iPod. Bruce Schneier provides a good, non-technical, short description of pseudorandom number generation: What's a PRNG? It's a mechanism for generating random numbers on a computer. They're called pseudorandom, because you can't get truly random numbers from a completely non-random thing like a computer. In theory, true random numbers only come from truly random sources: atmospheric noise, radioactive decay, political press announcements. If a computer generates the number, another computer can reproduce the process.

An amusing quote from a comment in Schneier's blog: A (non-security/crypto) tale of PRNGs: When I was studying astronomy, a curious result was published: a very narrow (small area of sky), deep (includes very dim galaxies) survey of galaxy red-shifts had been done. (Red-shift corresponds to velocity, which due to expansion of the universe corresponds closely to distance.) The red shifts showed significant periodicity. (I.e. at regular intervals in red shift, there were more or fewer galaxies found.) One of my professors had been doing large computer simulations of large scale structure in the universe. He said "I know what causes this. I've seen it in my simulations. God used a bad random number generator." Posted by: Filias Cupio at June 14, 2006 10:36 PM Footnote: yesterday and today I had my first occasions in awhile to look at C code. One should do this periodically as a reminder of how awful C is. The generator above was originally coded in Pascal, which hasn't been particularly useful for a long, long time.

Tuesday, April 1, 2008

Emacs Incremental Search Highlighting

Sometime in the fairly recent past default emacs incremental search behavior was modified to underline every occurrence of the search string in the current view. This makes searching very difficult to use if one wants to just skip ahead, e.g., a few 'o' characters, because every 'o' is highlighted, with no way to know which one is at the cursor. To return to the original, more usable behavior add this to your .emacs file: (setq isearch-lazy-highlight nil) ⟨editorial⟩ Emacs more and more is acting less and less like a text editor, and trying to get cute about things. Default behavior keeps changing, and often for the worse. This incremental search highlighting is a good example. Another is that in text mode it's now hard to line things up consistently because tab is no longer tab. Instead tab inserts enough spaces or tabs to line the cursor up with the beginning of the previous line, or with the beginning of a word in the previous line. I'd rather tab be tab. ⟨lairotide⟩