List of Free Programming Books

Victor Felder has an excellent list of free programming books over at Github. The list is indexed in several ways so it’s pretty easy to find books in the area you’re interested in. Among other things, I learned that there are a couple of free Lisp books I haven’t looked at.

This is a useful resource and worth bookmarking for the day when you need a pointer to a readily available programming book.

Posted in Programming | Tagged | Leave a comment

Specifying Indent Rules for Emacs Lisp

Eric J.M. Ritz has an excellent post on indenting Elisp code. Say what? Isn’t that what Emacs is for? Yes but there’s a corner case when you’re writing macros.

Here’s a macro that I use to make my Elisp code work on a region if one’s defined or on the whole buffer if not.

(defmacro with-region-or-buffer (args &rest body)
  "Execute BODY with BEG and END bound to the beginning and end of the
current region if one exists or the current buffer if not."
  `(let ((,(car args) (if (use-region-p) (region-beginning) (point-min)))
         (,(cadr args) (if (use-region-p) (region-end) (point-max))))
     ,@body))

As it stands, a call to that macro would get formatted as

(with-region-or-buffer (start end)
                       (blah start end)
                       (more blahs start end))

but that’s not what we want. We’d like it to get formatted as

(with-region-or-buffer (start end)
  (blah start end)
  (more blahs start end))

The easy way to get Emacs to indent it properly is with the declare declaration as shown in the slightly revised version of with-region-or-buffer shown below.

(defmacro with-region-or-buffer (args &rest body)
  "Execute BODY with BEG and END bound to the beginning and end of the
current region if one exists or the current buffer if not."
  (declare (indent 1))
  `(let ((,(car args) (if (use-region-p) (region-beginning) (point-min)))
         (,(cadr args) (if (use-region-p) (region-end) (point-max))))
     ,@body))

It’s really hard to find the documentation for this (at least I always find it hard) so I’m glad to have Ritz’s post for bookmarking purposes. The post has a link to the documentation for declare so you can see what other arguments to the indent declaration are possible.

Update: what’s → what

Posted in Programming | Tagged , | 6 Comments

Emacs Rocks at WebRebels 4

The fourth episode of Magnar Sveen’s cleaned up WebRebels talk is available. This section continues the demonstration of his JavaScript refactoring tools. He’s able to select a code snippet and turn it into a function with a single call. He can even parameterize the process in a way that’s hard to explain in print but easy to understand when you watch it. He’s also added some of the Paredit functionality. Very nice; it’s almost enough to make me start programming in JavaScript.

This episode is just under 2 minutes so you can watch it any time. You can find the code that he’s using at Sveen’s github repository (the js2 refactoring code is here).

Posted in General | Tagged | Leave a comment

NIST and Keccak

I’m a bit of a crypto nerd—though far from a practitioner or expert—so I’m on NIST‘s SHA-3 mailing list. The mailing list’s main purpose was to keep the contestant teams and other interested observers up to date on the competition. The winner was the Keccak team and just about everyone believes it was a good choice.

It’s NIST’s job to turn the Keccak algorithms into the SHA-3 standard. That’s were the trouble began. NIST made (what some call substantial) changes to the Keccak algorithm and reduced its security in service of increasing its speed. The list went crazy and now the technical press has taken note.

I don’t have the expertise to evaluate the arguments going back and forth but it is worth noting that the Keccak team is on board with the proposed changes. Last year that would have been the end of it but now everyone is donning their tin foil hats. After the Snowden revelations concerning the NSA’s successful attempt to weaken other crypto standards, I can’t understand what NIST is thinking.

Well, actually, I can. It’s the typical nerd reaction of, “the facts are on my side so I don’t have to pay attention to what anyone says about this.” The problem is most people—even most people who are going to use SHA-3 in their code—don’t have the wherewithal to make an informed judgment on the merits of the arguments but they sure understand that (1) NIST, by law, must solicit input from NSA and (2) the NSA is not to be trusted. Ever. Thus by forging ahead, NIST risks blowing up the whole SHA-3 process. As Schneier and others have said, there isn’t an urgent need for SHA-3 because the SHA-2 family is apt to be secure for some time. The careful (or paranoid) engineer is very apt to say, “Forget SHA-3, I’ll stick with SHA-512.”

That would be too bad but it’s exactly what NIST is risking by ignoring the public’s suspicion and distrust. It’s fine to dismiss them all as crazies who don’t understand the crypto but NIST has already shown itself susceptible to abuse at the hands of the NSA. Those “crazies” will just pick up their marbles and walk.

Posted in General | Tagged , | Leave a comment

Emacs Rocks at WebRebels 3

Magnar Sveen has posted the third part of his cleaned up WebRebels talk. This section demonstrates some Javascript refactoring. It’s only 58 seconds long so you won’t have to map out a block of time to watch.

Posted in General | Tagged | Leave a comment

WDIRED

Mickey over at Mastering Emacs has a nice post on wdired. Dired is an underappreciated part of Emacs but even many who use it don’t realize that you can edit file names, permissions, and owner/group directly in the dired buffer and have the changes reflected in the file system. That ability is already built-in. All you need to do is toggle it on with 【Ctrl+x Ctrl+q】 and make your changes. See Mickey’s post for the details.

If you want to see it in action, watch Magnar Sveen use it to change the names of several files at once using wdired and multiple cursors.

Posted in General | Tagged | Leave a comment

Word

Over at Charlie’s Diary, Charlie Stross has an excellent rant entitled Why Microsoft Word Must Die. I’ve written previously of my own feelings about Word: hatred bordering on the pathological. I consider it the apotheosis of everything that can be wrong in a piece of software. Sadly, its open source clones aren’t any better. They are, as the saying goes, bug compatible with the monstrosity they are emulating.

As great as Charlie’s post is, the comments are what’s really interesting. With a couple of exceptions they mostly amount to a long wail of anguish from pitiful souls condemned by circumstances to use Word. I was surprised to learn that even some scientific researchers are being forced to use it.

Charlie’s concern, of course, is writing fiction. He uses a number of tools for that including Scrivener and Vim. In the end, though, he must convert it to Word for his publishers. Other writers do the same. Vernor Vinge, for example, writes his novels with Emacs. Cory Doctorow uses Vim. No one, it seems, wants to actually do their writing in Word.

I wrote and typeset my two (technical) books using Vim and Groff. These days, all my writing is done with Emacs and Org Mode. Mostly that writing gets exported to HTML, but I’d feel comfortable using Org Mode to write a book. In many ways, it’s a superior solution to using Groff. It means working with LaTex instead of Groff1, which I’m most familiar with, but being able to write in Org Mode would be well worth the effort. My publisher is willing to accept camera ready copy so I would just export to LaTex and run off the PDF.

Even fiction writers can benefit from Org Mode. As of version 8, Org Mode can also export to ODT which should make submitting Word compatible files easier. Writers will choose their own tools for their own reasons but if you want a simple, powerful platform that doesn’t second guess you and can produce output in a variety of formats, it’s hard to beat the Emacs/Org Mode combination.

Footnotes:

1

There is an Org Mode back end that exports to Groff but it uses a different Troff macro package and I’ve never used it.

Posted in General | Tagged | Leave a comment

Magit Stage All Changes

As I’ve mentioned previously, I keep my blog posts—all my work, really—in a git repository. I manage the repositories with magit. If you aren’t a magit user, you’re really missing out and should take a look.

When I publish a post there are usually 3 files affected that need to be committed. In magit-status, I just type 【S】 to stage them all and can then commit. Recently, magit was changed to ask for confirmation before staging all the changed files. While I appreciate the offer, I find it annoying. If I change my mind I can just unstage everything with 【U】 and start over. Others, I’m sure, have different needs but I really don’t want to be asked every time I commit.

Happily, there’s an easy solution. After a little grubbing around in the code, I discovered that there’s a configuration variable to inhibit the confirmation. Just set

(setq magit-stage-all-confirm nil)

and you’re back to the old way. As usual, Emacs makes it easy to have things your way.

The unstage-all command also has a new confirmation. You can get rid of it, if you like, with

(setq magit-unstage-all-confirm nil)

but I didn’t bother with it because I rarely use that command.

Posted in General | Tagged | Leave a comment

Using yasnippet to Reduce Blogging Friction

Every Irreal blog post begins with some header information that tells org2blog the title, category, and tags for the post. These get communicated to WordPress when org2blog exports the post. Those lines look like this:

#+TITLE: Using =yasnippet= to Reduce Blogging Friction
#+CATEGORY: Blogging
#+TAGS: Emacs

There are 862 posts on Irreal at the moment and everyone of them begins with those 3 header lines. That’s a lot of typing, especially with all the capitalization. (Yes, yes, I know all about upcase-word and in fact I type them in lower case and then use 【Meta+b Meta+u】 to capitalize them—it’s still a lot of typing.)

I finally reached the end of the rope and decided that it was past time to install yasnippet so that I could automate that. After some floundering around, I figured out how to get snippets to load with Org Mode and added this snippet:

# -*- mode: snippet -*-
# name: header
# key: bh
# --
#+TITLE: $1
#+CATEGORY: ${2:General}
#+TAGS: $3

Now when I start a post, I begin with bhTab】 and the header skeleton is automatically inserted. I know I’m late to the party on this. Everyone else is already using yasnippet and wondering what took me so long.

All this probably isn’t going to save me huge amounts of time but it does reduce blogging friction a bit so it’s a win. Now that I have yasnippet installed I’ll be looking for other ways to leverage its power.

Posted in Blogging | Tagged | 6 Comments

Air Gaps

Bruce Schneier has an interesting post on setting up an air gap computer. It seems simple: just never connect your computer to the Internet. The problem is a completely isolated computer isn’t much use unless all you want to do is play Reversi or solitaire. To get any useful work done you need to move files onto and off of the computer.

At first glance it’s hard to see how a “normal” person would even need such a thing. But once Schneier became involved in the analysis of the Snowden documents he needed to isolate and protect them. When the need presents itself, you have to consider how best to protect yourself and your data.

Schneier began by buying a new laptop from a big box store and taking it to a friend’s house to download the software he needed. After that he never connected it to the Internet again. Still, there is the need to transfer data to and from the machine. It’s not nearly as easy as it seems.

Follow the link the see how Schneier handles the problem. The real meat in the post is in the comments. Almost everyone said, “Yikes! You’re using Windows? You should be using Linux.” That’s probably good advice but not too helpful. The other comments represent some useful advice. It’s a fairly long post with a lot of comments but it’s definitely worthwhile if you have to do something similar.

Posted in General | Tagged | Leave a comment