WFHing with Emacs: Work Mode and Command-Line Options

Like the rest of the world, I’m working from home these days. One of the changes I’ve made has been to set up Emacs to work from home.

I use Emacs extensively both at home and at work. So far, my method for keeping personal stuff and work stuff separate has been to, well, keep separate copies of ~/.emacs.d/ on work and home machines. But now that my home machine is my work machine, I figured I’d combine their configs.

To do this, I just added a -work command-line option, so that emacs -work runs in work mode. The command-switch-alist variable is useful here: it allows you to define a command-line option, and a function to call when it is encountered:

(defun my-work-setup (arg)
   ;; Do setup for work-mode
  )
(add-to-list 'command-switch-alist
  '("work" . my-work-setup))

Of course, I’ve never liked defining functions to be called only once. That’s what lambda expressions are for:

(add-to-list 'command-switch-alist
  '("work" .
    (lambda (arg)
      ;; Do setup for work-mode
      (setq my-mode 'work)
      )))

One thing to bear in mind about command-switch-alist is that it gets called as soon as the command-line option is seen. So let’s say you have a -work argument and a -logging option. And the -logging-related code needs to know whether work mode is turned on. That means you would always have to remember to put the -work option before the -logging option, which isn’t very elegant.

A better approach is to use the command-switch-alist entries to just record that a certain option has been set. The sample code above simply sets my-mode to 'work when the -work option is set. Then do the real startup stuff after the command line has been parsed and you know all of the options that have been passed in.

Unsurprisingly, Emacs has a place to put that: emacs-startup-hook:

(defvar my-mode 'home
  "Current mode. Either home or work.")
(add-to-list 'command-switch-alist
  '("work" . (lambda (arg)
                (setq my-mode 'work))))

(defvar logging-p nil
  "True if and only if we want extra logging.")
(add-to-list 'command-switch-alist
  '("logging" . (lambda (arg)
                  (setq logging-p t))))

(add-hook 'emacs-startup-hook
  (lambda nil
    (if (eq my-mode 'work)
      (message "Work mode is turned on."))
    (if logging-p
      (message "Extra logging is turned on."))
    (if (and (eq my-mode 'work)
             logging-p)
      (message "Work mode and logging are both turned on."))))

Check the *Messages* buffer to see the output.

Popular Vote: Majority Rule Is Disenfranchisement

Here’s a rather breathless letter to the editor of the Brattleboro (VT) Reformer, promising dire consequences if we start electing presidents the same way we elect governors, senators, mayors, and school board members:

The Los Angeles Times editorial (Feb. 17 in the Reformer) would like to disenfranchise more than half our nation by ending the electoral college, validating only “mob rule” elections dominated by metropolitan area voters and perhaps a portion of their rural allies. Vermont’s legislature endorsed the “National Popular Vote Interstate Compact” which would effectively disenfranchise a sizable portion of Vermont voters, as actually happened prior to that in the 2016 election when our three electors all voted for one popular candidate, even though the Vermont voters were divided 2 to 1. So one third of our voters were ignored entirely.

Dave Garrecht, Guilford, VT

Mr. Garrecht seems confused with worry. For one thing:

disfranchise [ dis-fran-chahyz ]:
verb (used with object), dis·fran·chised, dis·fran·chis·ing.
1. to deprive (a person) of a right of citizenship, as of the right to vote

dictionary.com

No one is talking about taking away anyone’s right to vote. What he’s upset about is not getting his way, as he demonstrates in the rest of the sentence:

as actually happened prior to that in the 2016 election when our three electors all voted for one popular candidate, even though the Vermont voters were divided 2 to 1. So one third of our voters were ignored entirely.

No, no one ignored anyone. It’s just that the minority lost. That’s how it works in a democracy. Get used to it.

He mentions “mob rule”, as do a lot of other people, so that’s worth addressing. Wikipedia’s definition seems as good as any I’ve seen:

Ochlocracy […] or mob rule is the rule of government by mob or a mass of people, or, the intimidation of legitimate authorities. As a pejorative for majoritarianism, it is akin to the Latin phrase mobile vulgus, meaning “the fickle crowd”, from which the English term “mob” originally was derived in the 1680s.

Now, no one is condoning, or even suggesting, intimidating anyone. So really, the biggest fear worth addressing is that the majority might vote to take away the rights of the minority, as in the old quotation about how “Democracy is two wolves and a lamb voting on what to eat for lunch.” It’s worth reading the context, in Marvin Simkin’s article in the Los Angeles Times:

Democracy is not freedom. Democracy is two wolves and a lamb voting on what to eat for lunch. Freedom comes from the recognition of certain rights which may not be taken, not even by a 99% vote. Those rights are spelled out in the Bill of Rights and in our California Constitution. Voters and politicians alike would do well to take a look at the rights we each hold, which must never be chipped away by the whim of the majority.

This problem has been recognized for a long time, and that’s why the first ten amendments to the US Constitution spell out a list of rights that can’t be taken away by a simple vote. And nobody’s trying to take that away here.

In short, Mr. Garrecht is upset over nothing. No one’s taking away anyone’s vote. If anything, the popular vote would make more people’s vote significant. And really, if you’re supporting an unfair system for fear of what other people might do to you if their vote counts the same as yours, what does that say about you?

Counting Every Vote Will Nullify Your Vote

An editorial at Fredericksburg.com warns of dire consequences if the National Popular Vote Interstate Compact passes:

The House of Delegates voted to have the Old Dominion join the National Popular Vote Interstate Compact, an agreement that would force Virginia’s 13 electors to vote for the candidate chosen by the national popular vote.


Joining this compact would have nullified Virginia’s voice in this most important of all elections, enabled the tyranny of the majority, and upended a system that has worked well for 233 years.

This is an argument I’ve seen elsewhere; particularly the “nullify” part of it. As I see it, it’s just seizing on the more eyebrow-raising part of the NPVIC–the idea that a state’s Electoral Votes will sometimes be given to a candidate who didn’t win that state’s popular vote–and presenting it as though it were a new idea.

The word “nullified” makes it sound as though Virginia’s voters would be deprived of their chance to participate in the election. In fact, if this situation were to arise, it would simply mean that the majority of Virginia’s voters would have lost the election, something that has happened any number of times.

In fact, a popular vote would achieve the reverse of what the author fears. Let’s say that the Compact passes, with states totaling 270 Electoral Votes signing on, but Virginia holds out and doesn’t sign on.

In the next election, the winning strategy changes: instead of looking at states as blocks and assuming that California will vote Democratic and Texas will vote Republican, candidates will have to appeal to broad swaths of people: suddenly the Republicans in California and the Democrats in Texas are worth reaching out to. And so are the voters in Virginia, be they Democrat, Republican, third-party, or independent. Unlike the present system, every one of those votes will move the dial a little bit to the left or to the right.

So far from nullifying anyone’s vote, the popular vote would make everyone’s vote count.

Silly Objections to the Popular Vote

Of late, I’ve been taking an interest in the National Popular Vote Interstate Compact. For those who haven’t heard about it, the basic idea is that the US’s system of electing presidents through the Electoral College is archaic and convoluted, and too often doesn’t elect the person who won the most people’s votes.

Since the Electoral College is in the Constitution, it would take a constitutional amendment to get rid of it, and that’s notoriously difficult. However, there’s a workaround: have states allocate their Electoral Votes not to the candidate who won the state’s popular vote, but to the one who won the national popular vote. Yes, it means that if most people in a state vote for candidate A, but candidate B wins the vote nationwide, then that state will allocate its Electoral votes to candidate B. Naturally, it would be crazy for a state to go it alone in this. So this would only kick in once enough states signed up to determine the outcome of the election, i.e., states with 270 Electoral Votes between them.

It sounds weird at first, but it could work. And it’s because it sounds crazy that I’ve started following the issue. But one thing that struck me is just how few good arguments there are against it.

Take, for instance, this letter to the editor of the Richmond Times-Dispatch:

As far as presidential elections go, contenders should learn some things from sports. Know the rules. More importantly, play by the rules. They should broaden their support and try to win more states. They know what the rules are. A contender should need to win more than 11 states (the most populous of which total 270 electoral votes), potentially negating the other 78% (39 states).

For starters, presidential candidates and their campaign managers do know the rules, and do play by them; that’s why they only really campaign in a handful of swing states: everyone knows that, say, New Jersey will vote Democratic no matter what, so the Republicans can just write it off and spend their campaign money elsewhere, where it’ll do more good (i.e., where advertising is likely to get them some more Electoral Votes). The Democrats, meanwhile, can take New Jersey pretty much for granted, and spend their campaign money elsewhere, where it’ll do more good.

Secondly, the author makes a mistake that many opponents of the NPVIC make: that of thinking in terms of states instead of people: states don’t vote; individual voters do. Under a popular vote system, it doesn’t make sense to talk about “how New Jersey voted”, except as a broad trend. The more important question is, how many people in New Jersey voted for each candidate?

Note, too, that the 11 most populous states (also the ones with the most Electoral Votes) are California, Texas, Florida, New York, Pennsylvania, Illinois, Ohio, Georgia, North Carolina, Michigan, and New Jersey. The author’s fear lies on the premise of everyone in those 11 states voting the same way. I can’t imagine an election in which everyone in California votes the same way, let alone one where everyone in Texas votes the same way as everyone in California. If a candidate comes along who’s such a uniter that they can get a majority of the vote in those 11 states, then I think that person deserves the presidency.

Furthermore, while those 11 states add up to 270 Electoral Votes, they also have 52% of the population. So what this person is arguing against is the idea of majority rule.

But the biggest mistake this writer makes, in my opinion, is the one I mentioned first: it’s in part because of the Electoral College that presidential candidates only try to win a handful of states and ignore the rest. If he wants them to reach out to, say, Republicans in rural California and New York, or Democrats in Austin and Salt Lake City, then a popular-vote approach is the way to go.

Ansible As Scripting Language

Ansible is billed as a configuration manager similar to Puppet or cfengine. But it occurred to me recently that it’s really (at least) two things:

  1. A configuration manager.
  2. A scripting language for the machine room.

Mode 1 is the normal, expected one: here’s a description; now make the machine(s) look like the description. Same as Puppet.

Mode 2 is, I think, far more difficult to achieve in Puppet than it is in Ansible. This is where you make things happen in a particular order, not just on one machine (you’d use /bin/sh for that), but on multiple hosts.

For instance, adding a new user might involve:

  1. Generate a random password on localhost.
  2. Add a user on the Active Directory server.
  3. Create and populate a home directory on the home directory server.
  4. Add a stub web page on the web server.

This is something I’d rather write as an ansible play, than as a Puppet manifest or module.

Which brings me to my next point: it seems that for Mode 1, you want to think mainly in terms of roles, while for Mode 2, you’ll want to focus on playbooks. A role is designed to encapsulate the notion of “here’s a description of what a machine should look like, and the steps to take, if any, to make it match that description”, while a playbook is naturally organized as “step 1; step 2; step 3; …”.

These are, of course, just guidelines. And Mode 2 suffers from the fact that YAML is not a good way to express programming concepts.  But I find this to be a useful way of thinking about what I’m doing in Ansible.

Buying Lunch with Bitcoin?

This weekend, I had occasion to eat at a food truck that had this intriguing sign in the window:

Sign reading "Crypto accepted here, with the icons of various cryptocurrencies" in the window of a food truck.

This intrigued me, because the way I understand it, it takes 10-20 minutes for Bitcoin transactions to go through. That’s why it doesn’t work everyday purchases like, for instance, lunch at a food truck.

I asked the vendor about this, and he told me that “Oh, no. If you have $APP, it goes through right away!” There was a line, so I wasn’t able to ask more questions, but when I read the reviews for the app, a lot of the complaints involved how long it took for transactions to be processed: up to an hour, in some cases.

So I suspect that the food truck guy is confused: yes, you can instantly get a hash that says to transfer X amount of Bitcoin from address A to address B. But the real question is, will that transaction actually get recorded in the consensus ledger? This is similar to the way it only takes a few seconds to write someone a check; but you can’t really spend that money until the check clears, which can take a week. But if I went around to two or three food trucks in the same ten-minute window, I think I could “spend” the same money, and only one of the transactions would clear, in the end.

In short, I think this guy is lucky that he’s only dealt with honest people. Either that, or he figures that there’ll be some amount of theft, and that’s just the price of doing business.

Ansible: Running Commands in Dry-Run Mode in Check Mode

Say you have an Ansible playbook that invokes a command. Normally, that command executes when you run ansible normally, and doesn’t execute at all when you run ansible in check mode.

But a lot of commands, like rsync have a -n or --dry-run argument that shows what would be done, without actually making any changes. So it would be nice to combine the two.

Let’s start with a simple playbook that copies some files with rsync:

- name: Copy files
  tasks:
    - name: rsync the files
      command: >-
        rsync
        -avi
        /tmp/source/
        /tmp/destination/
  hosts: localhost
  become: no
  gather_facts: no

When you execute this playboook with ansible-playbook foo.yml rsync runs, and when you run in check mode, with ansible-playbook -C foo.yml, rsync doesn’t run.

This is inconvenient, because we’d like to see what rsync would have done before we commit to doing it. So let’s force it to run even in check mode, with check_mode: no, but also run rsync in dry-run mode, so we don’t make changes while we’re still debugging the playbook:

- name: Copy files
  tasks:
    - name: rsync the files
      command: >-
        rsync
        --dry-run
        -avi
        /tmp/source/
        /tmp/destination/
      check_mode: no
  hosts: localhost
  become: no
  gather_facts: no

Now we just need to remember to remove the --dry-run argument when we’re ready to run it for real. And turn it back on again when we need to debug the playbook.

Or we could do the smart thing, and try to add that argument only when we’re running Ansible in check mode. Thankfully, there’s a variable for that: ansible_check_mode, so we can set the argument dynamically:

- name: Copy files
  tasks:
    - name: rsync the files
      command: >-
        rsync
        {{ '--dry-run' if ansible_check_mode else '' }}
        -avi
        /tmp/source/
        /tmp/destination/
      check_mode: no
  hosts: localhost
  become: no
  gather_facts: no

You can check that this works with ansible-playbook -v -C foo.yml and ansible-playbook -v foo.yml.

Pseudo-Numeric Identifiers

Let’s say you’re a programmer, and your application uses Library of Congress Control Numbers for books, e.g., 2001012345, or ZIP codes, like 90210. What data types would you use to represent them? Or maybe something like the Dewey Decimal System, which uses 320 to classify a book as Political Science, 320.5 for Political Theory, and 320.973 for “Political institutions and public administration (United States)”?

If you said “integer”, “floating point”, or any kind of numeric type, then clearly you weren’t paying attention during the title.

The correct answer was “string” (or some kind of array of tokens), because although these entities consist of digits, they’re not numbers: they’re identifiers, same as “root” or “Jane Smith”. You can assign them, sort them, group them by common features, but you can’t meaningfully add or multiply them together. If you’re old enough, you may remember the TV series The Prisoner or Get Smart, where characters, most of them secret agents, refer to each other by their code numbers all the time; when agents 86 and 99 team up, they don’t become agent 185 all of a sudden.

If you keep in mind this distinction between numbers, which represent quantities, and strings that merely look like numbers because they happen to consist entirely of integers, you can save yourself a lot of grief. For instance, when your manager decides to store the phone number 18003569377 as “1-800-FLOWERS”, dashes and all. Or when you need to store a foreign phone number and have to put a plus sign in front of the country code.

Removing Magic

So this was one of those real-life mysteries.

I like crossword puzzles. And in particular, I like indie crossword puzzles, because they tend to be more inventive and less censored than ones that run in newspapers. So I follow several crossword designers on Twitter.

Yesterday, one of them mentioned that people were having a problem with his latest puzzle. I tried downloading it on my iPad, and yeah, it wouldn’t open in Across Lite. Other people were saying that their computers thought the file was in PostScript format. I dumped the HTTP header with

lynx -head -dump http://url.to/crossword.puz

and found the header

Content-type: application/postscript

which was definitely wrong for a .puz file. What’s more, other .puz files in the same directory were showing up as

Content-type: application/octet-stream

as they should.

I mentioned all this to the designer, which led to us chatting back and forth to see what the problem was. And eventually I had the proverbial aha moment.

.puz files begin with a two-byte checksum. In this particular case, they turned out to be 0x25 and 0x21. Or, in ASCII, “%!“. And as it turns out, PostScript files begin with “%!“, according to Unix’s magic file.

So evidently what happened was: the hosting server didn’t have a default type for files ending in .puz. Not terribly surprising, since that’s not really a widely-used format. So since it didn’t recognize the filename extension, it did the next-best thing and looked at the first few bytes of the file (probably with file or something equivalent) to see if it could make an educated guess. It saw the checksum as “%!” and decided it was a PostScript file.

The obvious fix was to change something about the file: rewrite a clue, add a note, change the copyright statement, anything to change the contents of the file, and thus the checksum.

The more permanent solution was to add a .htaccess file to the puzzle file directory, with

AddType application/octet-stream .puz

assuming that the hosting provider used Apache or something compatible.

This didn’t take immediately; I think the provider cached this metadata for a few hours. But eventually things cleared up.

I’m not sure what the lesson is, here. “Don’t use two-byte checksums at offset 0”, maybe?

Do You Even Science, Frater?

The other day, I went to a Thomistic Society talk about Aquinas’s views on the Problem of Evil and other topics. At one point, the presenter casually mentioned that humans engage in self-destructive behavior, like alcoholism, self-mutilation, drug addiction, etc., while non-human animals don’t.

That made my [citation needed] sense tingle, so I looked around. Among other things, I found Animal models of self-destructive behavior and suicide:

Research on nonhuman primates has demonstrated that self-mutilation is a common reaction to extreme disruptions of parental caretaking in other mammalian species as well. For example, isolated young rhesus monkeys engage in self-biting and head slapping and banging (21). Analgesia is also common in self-destructive animals.

Or this non-scholarly page about the effects of drugs, including addiction, in animals such as horses, goats, and even bees.

So apparently this speaker simply wasn’t aware of self-destructive behavior in non-human animals. I don’t remember what her point was, so it might have been a minor thing, but still, it wasn’t true.


But this brought to mind the previous Thomistic Institute talk I went to: there, the presenter casually mentioned that humans engage in abstract reasoning, while animals don’t.

Again, this didn’t seem quite right. This study from 2007 involved teaching dogs to push a button when shown a set of pictures of dogs, and another button when shown a set of pictures of landscapes.

Interestingly, presentation of pictures providing contradictive information (novel dog pictures mounted on familiar landscape pictures) did not disrupt performance, which suggests that the dogs made use of a category-based response rule with classification being coupled to category-relevant features (of the dog) rather than to item-specific features (of the background).

Or this paper, entitled simply Concept Learning in Animals, whose abstract says:

We suggest that several of the major varieties of conceptual classes claimed to be uniquely human are also exhibited by nonhuman animals. We present evidence for the formation of several sorts of conceptual stimulus classes by nonhuman animals: perceptual classes involving classification according to the shared attributes of objects, associative classes or functional equivalences in which stimuli form a class based on common associations, relational classes, in which the conceptual relationship between or among stimuli defines the class, and relations between relations, in which the conceptual (analogical) relationship is defined by the relation between classes of stimuli. We conclude that not only are nonhuman animals capable of acquiring a wide variety of concepts, but that the underlying processes that determine concept learning are also likely to be quite similar.

No one will deny that humans can perform mental feats that non-human animals can’t, as far as we can tell. Other animals can’t play chess, prove mathematical theorems, or form complex sentences, as far as I know. But at the same time, the issue isn’t a black-and-white “humans can reason abstractly and animals can’t.”


Lastly, I’ve written at length about Thomist Edward Feser, and his ignorance of science from Newton on up.

Individually, each of these mistakes are just that: mistakes. Or ignorance: philosophers can’t be expected to be masters of nuclear physics or animal cognition. Or simplifications that gloss over a complex idea in order to make a broader point.

But collectively, I do see a pattern of Thomists being wrong on matters of science in a thousand small ways. That suggests that either they don’t bother checking whether their beliefs are true, where possible, and correct their errors, or else they have other beliefs that lead them to erroneous conclusions. And either way, if I can’t trust them on the small stuff, why should I believe them on the big stuff?