Chris Wellons on State Machines

As I’ve mentioned a few times, I love programming state machines. I spent many years writing software for communications software using odd protocols. The easiest way of implementing those protocols was almost always to use a state machine. Once you get used to working with them, you discover that all sorts of problems fit the paradigm.

A couple of weeks ago, Chris Wellons published an instructive post on state machines that I really liked. Most articles you see on state machines illustrate the idea with a simple problem and don’t worry about efficient implementations Wellons, of course, is having none of that. His problems are nontrivial and he spends time deriving efficient implementations.

For example, his first problem is a Morse code decoder. It’s a problem crying out for a state machine and if you spend a couple minutes thinking about it, a natural implementation for the state diagram is a binary tree. Naturally, Wellons noticed this and came up with a beautiful solution. He implemented the state table as a binary heap so that there was no need to store a representation of the edges. See his post for the details. The result is an implementation that compiles to under 200 bytes.

Wellons also discusses a UTF-8 decoder, a word counter, and a couple of other problems. Along the way, he looks at using co-routines and generators as an implementation strategy.

The post is dense so you’ll have to read it carefully and spend a bit of time understanding everything but the rewards are worth it. State machines are a powerful tool and it’s worth spending some time getting comfortable with them.

Posted in General | Tagged | Leave a comment

Knuth’s Literate Programming Paper

Literate Programming. Back in 1984 when Knuth published his paper proposing Literate Programming, he believed that the concept would take over the programming world. I remember him saying that companies that failed to adopt Literate Programming would soon fall behind those that do. It hasn’t worked out that way.

Literate Programming failed to gain traction until recently. Now a sort of watered down version can be found in the various programming language notebooks. Org-mode Babel can—but doesn’t have to—support Knuth’s model so after almost 4 decades one could say that Literate Programming is finally seeing its day in the sun.

Although I love the idea, I’ve never been able to embrace the Knuth model. I want—need—to see the whole program all at once, which isn’t practical with the Knuth model. Even with Babel, I don’t use the full Literate Programming capabilities. I prefer the Literate Devops model used by Howard Abrams, a weaker model similar to that provided by the programming language notebooks.

Given the resurgence of interest in Literate Programming, it seems appropriate to revisit Knuth’s original paper. Vivek Haldar has added it to his Read A Paper series and gives a nice exposition of the paper. The video is just over 9 minutes so you can watch it on a coffee break. If you have an interest in Literate Programming in any of its incarnations, it’s worth taking a look at where it all started.

Posted in General | Tagged , , | Leave a comment

Setting Up Mu4e

Yesterday’s post discussed David Wilson’s video on setting up and using authinfo. In that video, Wilson mentioned his videos on setting up mu4e and how authinfo fit into configuring mu4e and mbsync.

Those videos are also worth watching. The first talks about setting up mu4e and mbsync for a Gmail account. The second—more interesting—video explains how to use mu4e on multiple accounts. Together, the videos cover two of the problems that I read about the most:

  • How to set up mbsync up for Gmail.
  • How to set up multiple accounts with mu4e.

If you’d like to move your email to Emacs, I can unreservedly recommend mu4e although there are other possibilities. Wilson’s two videos will help you get things running.

The first video is a couple minutes over an hour and the second is 31 minutes so you’ll definitely need to schedule some time but if you’re stuck getting mu4e configured, they could be just what you need to get unstuck.

Posted in General | Tagged | Leave a comment

Setting Up and Using Authinfo With Emacs

Once you start moving more and more of your computing tasks into Emacs, you’re going to need a way of handling passwords. Mail is the canonical example but there are also things like blogging sites, ftp servers and other functions that you want to access from Emacs but that require a password.

With mail, for example, you need a login and password to retrieve your mail from, say, your mail provider’s IMAP server and you may need another set for their SMTP server so you can send mail. One solution is to simply add these to your configuration files but that’s horribly insecure. Of course, as usual, Emacs has us covered. The proper way of doing this is to put all the login/password information into an authinfo file and encrypt it. Emacs will read, decrypt, and parse this file to get the required login/password, requesting the key to decrypt the file if necessary.

Setting this up can be a bit tricky but David Wilson has a nice video that explains how to set up and use the authinfo system. He takes you step-by-step through the process but be sure to read Chris Wellon’s (skeeto) comment on how and why to use an elliptic curve instead of the RSA-based key that Wilson uses.

The video is 38 minutes, 13 seconds so plan accordingly.

Posted in General | Tagged , | Leave a comment

Adding a Third Monitor to EXWM

Twelve or thirteen years ago, I got my first Mac. Fast forward to today and you’ll find that the Irreal bunker is firmly in the Apple ecosystem. One of the things I don’t miss—at all—is struggling with getting X configured. I’m told by reliable sources that things are much easier now but the horror of X configuration was brought back to me by Tory Anderson’s post on how he added a third monitor to his EXWM configuration.

I love the idea of EXWM and wish it were available for the Mac but for now, I’ll have to look on enviously. Anderson runs EXWM and had it set up for his main monitor and his laptop screen. Then he got another monitor and wanted to add it to his EXWM system. His post is a detailed step-by-step tutorial on how to do that.

If you read his post, you’ll see what I mean about X configuration. He had to do some fiddling with his X configuration to get things running. No doubt I’m just being a sissy and making things seem harder than they are but I’ve grown soft living in the Apple walled garden where none of this is necessary. If you’re looking to add another monitor to your setup, you should take a look at Anderson’s post.

Posted in General | Tagged , | Leave a comment

Prot on Embark

Protesilaos Stavrou (Prot) has a new video up in which he discusses Embark and some of his extensions to it. For those unfamiliar with Embark, it’s a package that lets you bind actions to keys in a context sensitive way. That is, the action taken for a given key will be different when the point is on a URL from what it will be if it’s on a file name.

The system’s a bit complicated and hard to describe succinctly but Prot demonstrates its major functionality. Of course, being Prot he’s added a few extensions to make it better match his workflow.

The Embark system reminds me a lot of Ivy but as Prot says, the context sensitivity gives it a more focused feel. Watch the video to see what I mean. It’s 33 minutes, 21 seconds so you’ll need to set aside some time but it’s worth taking a look. As usual, Prot provides links to the relevant code so you can see how he has things set up if you want to replicate his workflow and use it as a starting point for your own.

Posted in General | Tagged | Leave a comment

Group Tags in Org-mode

I know about Org’s group tags but like any things in Emacs, I wasn’t using them so they slipped out of my mind. Until today. Today, I saw this Tweet:

and it reminded me that they can be really helpful in some use cases. The documentation for them is here but the TL;DR is that you can assign a set of tags to a group and then search for items with any of the tags by searching for the group name.

You can obviously get along without them but for some applications they’re the perfect solution. Take a look at the documentation to get the full story.

Posted in General | Tagged , | Leave a comment

Read Meat Friday: A Trojan In Your Editor

Is there a backdoor in your editor? Probably not, even if you’re using IntelliJ, but in a moment of schadenfreude for FOSS folks, the New York Times is reporting that JetBrains software may have been used as vector in the Russian hack.

It’s a good policy not to believe anything you read in the press about technical matters and JetBrains for its part is denying that there’s a backdoor TeamCity—the software in question—but admitted that it’s possible it was exploited somehow to install the trojan. Still, if you’re an IntelliJ user, you’ve got to be wondering what’s in your software.

The problem is, you don’t know because it’s closed source. That’s a problem users of Emacs and other FOSS editors don’t have. It’s easy to minimize the benefits of FOSS because most of us don’t, after all, make changes to—or even read—the source code of most of our applications. And yes, it’s possible for FOSS to be infected too but it’s more difficult and easier to discover.

This episode, whatever its truth, is a useful reminder that having access to the source code of your tools is important. Of course, as Ken Thompson reminds us, that may not be enough, but it’s sure better than using a black box.

Posted in General | Tagged , , | Leave a comment

The Guile Hacker’s Handbook

Jeremy Korwin has an interesting project underway. He’s writing a Guile hacker’s handbook. Guile, of course, is the official GNU extension language. Korwin’s idea is to document what a beginning Guile hacker needs to know to install, and learn the Guile version of the Scheme language.

An important part of his exposition, so far, is how to configure and use Emacs as a Guile IDE. He suggests using geiser, a Slime-like interface for Scheme. It’s what I use for writing in Scheme and I really like it. It makes the interactive style of programming that I prefer easy and pleasant.

The book is still in its early stages so it’s not really ready for use but it’s interesting to see how it’s evolving.

Posted in General | Tagged , | Leave a comment

Building A Password Generator in 3 Minutes

Today—the whole week really—has been consumed by yak shaving so this is a short offering. Salah Qadri has a nice 3 minute video (3 minutes, 48 secs actually) in which he builds a reasonably good password generator.

The generator builds a password from upper/lower case letters, numbers, and symbols. The type of character and which one it is used are chosen randomly at each step using the Python random.choice method. One can argue that Qadri should have used the secrets.choice method instead but for occasional one-off passwords random.choice is probably adequate.

My only other nit is that I would have used a more functional approach rather than relying on globals but that’s more a personal preference. If you want to generate random passwords, Qadri’s video has some nice ideas. I like the way he handled choosing a type of character randomly. The code is easy to follow even if you aren’t a Python coder.

Posted in General | Tagged , | Leave a comment