Modulo Bias

A common operation in software is to reduce a larger number to a smaller one by the modulo operation. As a toy example, suppose we have random numbers in the range 0–7 but need to reduce those values to the range 0–4. The standard way of doing that is to reduce the first set modulo 5.

Now suppose the first set is uniformly distributed. That is, each value from 0 to 7 is equally likely. Suppose that we want the reduced set to be uniformly distributed too. Let’s see what happens:

n n (mod 5)
0 0
1 1
2 2
3 3
4 4
5 0
6 1
7 2

Notice that the values 0, 1, 2 occur twice but the numbers 3 and 4 occur only once so the reduced set is definitely not uniformly distributed. That’s because 5 does not divide the number of values in the first set (8) evenly. If the original set had been 0–9, the reduced set would have been uniformly distributed too.

This problem is called modulo bias. I wrote about it in passing in my post on a Diceware implementation. Yolan Romailler has a nice post on modulo bias over at Kudelski Security Research. He gives a slightly larger example of modulo bias, and describes some of the ways of dealing with it. More importantly, he describes how it can be a significant problem, especially in cryptographical applications, where reduction with the modulo operation is common.

If you ever use the modulo operation, you should take a look at Romailler’s post to make sure you aren’t introducing unintended biases.

Posted in Programming | Tagged | Leave a comment

Everyone Has Something To Hide

One of the most ridiculous arguments about privacy is the oft-stated “If you have nothing to hide, you have nothing to fear.” Irreal has many articles debunking this notion—here’s a list—but it seems the argument is evergreen.

Kev Quirk has (yet another) post laying waste to this completely bogus idea. His post, Privacy vs “I have nothing to hide”, takes a critical look at this outrageous argument. If you’ve followed the issue, nothing in Quirk’s article will be surprising but he does point out the reason that no one reads those terms of service that companies use to excuse their behavior. For example, the Paypal terms of service of is longer (in words) than Shakespeare’s Hamlet. Likewise, the Appletunes terms of service are longer than Macbeth. No one, no one, is going to read through all that but the companies will cite your click through as evidence that you’re fine with their spying on you.

As I’ve said before, if you hear someone raise this argument, walk away. The person advancing it either doesn’t know what they’re talking about or they’re trying to run a scam on you. In either case, ignore them. We all, whether we have something to hide or not, are entitled to our privacy and should tell those who say otherwise to go pound sound.

Posted in General | Tagged | Leave a comment

Adopting A New Emacs Workflow

Over at TAONAW, JTR has a short post post on how his changing work duties—that now include more technical writing—has caused him to evolve his Emacs workflow. A lot of his work involves writing Knowledge Base articles that get added to the ServiceNow platform.

Of course, being an Emacs user, JTR wants to do his writing in Emacs and then import it into ServiceNow. He did this by exporting his Org document to HTML and using a browser to paste it into the ServiceNow platform. Apparently Service Now is not very forgiving about its input so JTR had to tweak his Org headers to get acceptable HTML to import.

The real problem, though, was getting changes made within ServiceNow back out to Emacs. There doesn’t seem to be a good way to do that so JTR was reduced to manually copying the changes back to Emacs.

The big takeaway for me in his post was the ends that an Emacs user will go to to do their work within Emacs. I can sympathize. I’m also willing to jump through some hoops just so that I can do my work in Emacs. Once you’ve been spoiled by an Emacs workflow, it’s hard to use anything else.

Posted in General | Tagged , | Leave a comment

Emacs 28.2 Released

Stefan Kangas writes that Emacs 28.2 has been released and is available in the usual places.

As always, thanks to all the developers who selflessly worked to bring us this newest official release of Emacs.

Posted in General | Tagged | Leave a comment

Fast Emacs Startup by Dumping

Many Emacs users obsess about the editor’s startup time. I’ve never understood this. Even if Emacs takes 15 seconds or more to start, who cares? The thing is that if you are using Emacs correctly, you need only start it when you boot your machine or, perhaps, update your packages. The point is, starting Emacs is, or should be, a rare event.

When I moved to Emacs from Vim 15 or 16 years ago, the hardest thing to get used to was not firing up my editor when I needed it. The correct operation was to simply start it once and switch focus to it when I needed it. Even if you can’t break the “startup the editor when I need it” habit, you can still start it once in server mode and simply invoke emacsclient when you need the editor.

Still, some folks can’t let go of the startup time issue. For those people, mmontone has a solution: dump the Emacs image after it has loaded all its packages and been completely configured. You can see exactly how to do it by following the link but Eli Zaretskii notes in the comments that the technique is not yet 100% reliable and you may have to tweak your configuration a bit to get it to work. Even so, mmontone says it’s working well for him.

Again, you’ll be much happier if you accept that Emacs should be started rarely and can wean yourself from worrying about how long those infrequent startups take.

Posted in General | Tagged | Leave a comment

Entering Special Characters with Abbrev

As I’ve said before, I do almost all my writing in Org-mode so entering special characters is easy. I can either use the built-in Org characters or drop into TeX input mode. But, of course, I’m not always in Org-mode. Sometimes I want a special character when entering a Git description—most often → but occasionally others—and there are other situations where I need them as well.

My solution—that I learned from Xah Lee—is to use the abbrev system that’s built into Emacs. Thus, I have the abbreviation /ra for →. The other day, I saw this post by The Emacs Cat on using abbrev for inputting special characters anywhere within Emacs. It’s basically the same system that I use except that I depend on hippie expand to resolve my abbreviations rather than having them expand automatically, which I find jarring.

The Emacs Cat begins each of the abbreviation keys with 8 to avoid having accidental expansions. That’s a good solution and one that many may prefer. Regardless of which method you employ, using abbrev-mode to enter special characters that you need frequently is a win. You can always drop back to insert-char, bound to Ctrl+x 8 Return, to enter those that you don’t use often.

Take a look at The Emacs Cat’s post for the details on how to set things up.

Posted in General | Tagged | Leave a comment

Time Tracking With Org-mode

Jeremy Friesen over at Takes on Rules has an interesting post on using Org-mode for his workflow. The exact situation is a bit more complex but it’s best thought of a way of time tracking.

Rather than use a packaged solution like Org-roam, Friesen rolls his own using the Org-capture template system. The basic idea is that he has projects and tasks in support of those projects. As he starts work on a project, he captures that project and further tasks are all accumulated under that project.

At the end of the month he runs org-clock-report to generate a time report for all the projects and tasks. It’s a nice workflow. One could, of course, prompt for the project for each task entry but whether that’s optimal or not depends on the individual workflow. Either way, it’s a good way of capturing the details of a workflow.

Posted in General | Tagged , | Leave a comment

Configuring Eshell

As most of you know, I’m a big fan of Eshell. It’s easy to pop in and out of it and I really enjoy its tight integration with the rest of Emacs, particularly the ability to cd to a remote machine.

Still, it’s not a “normal” Unix shell so muscle memory is useless when you want to do things like set an alias, configure the prompt, or enable color output. Fortunately, The Emacs Cat has a helping hand. In a post entitled Eshell Aliases, Prompt, And Colors, The Emacs Cat tells us exactly how to configure these Eshell features.

One thing that the post doesn’t mention is how add an alias directly from Eshell without editing your init.el or eshell/alias file. Eshell is famously lacking in documentation and it’s hard to find documentation on setting an Eshell alias. For the record, it’s here.

Setting the prompt is very fussy. Basically, you need to provide a function whose output is the prompt. The post has an example of a complex prompt that’s probably more than most people need but it’s a good go-by.

Finally, enabling color output isn’t hard but requires setting a hook function. All the details are in the post so be sure to take a look.

It’s nice to have this post because it removes some barriers to using Eshell. That is, I think, a good thing because Eshell is a powerful part of Emacs that can make all our workflows more frictionless.

Posted in General | Tagged | Leave a comment

Using Emacs to Write the Perfect Sentence

Chris Maiorana has an interesting video on using Emacs to level up on your writing. He was inspired by Jordan Peterson’s writing application essay.app. Maiorana realized that essay was pretty much like Org-mode except that it has a feature missing from Org: you can select a sentence and have it appear in a second window where you can write various versions of it and select the one you like the best. After selecting your favorite, that version is exported back to the text in the original window.

Peterson claims and Maiorana agrees that this method in effective in writing the best possible sentence. Org-mode doesn’t support this, of course, but as Maiorana demonstrates, it’s pretty easy to implement. Maiorana isn’t a programmer so his code is pretty simple but works well.

When he described the problem, my first thought was to use an indirect buffer. One of the commenters, Leslie Russell, had the same thought and came up with a slightly better implementation. It’s still pretty elementary and easy to follow. If you’re interested in something like this, grab Russell’s code (use the second version). You can just paste it into your init.el and give it a try.

I haven’t used this method but it’s certainly true that the best way to improve a piece of writing to try rewriting it. This code makes it easy to do that in sentence sized bites.

Posted in General | Tagged , | Leave a comment

John Cook on Literate Programming

John D. Cook has another post in his series of posts discussing the use of Org mode in his professional duties as a consulting mathematician. This time he discusses the pros and cons of literate programming.

He recounts the story of a blog post that had some errors that he believes might have been avoided if he’d used literate programming. He rewrote the post using literate programming and had a few observations.

First, he found that it was harder to compose the post using literate programming. There’s a lot of little markup details that you have to deal with that aren’t necessary when you just paste in a value from a separate computation. Still, that effort pays dividends if you have to update your post with new parameters and can help reduce errors.

I’ve reached the point where I do all my writing in Org-mode and always do any necessary computations in a code block. It’s a real win because if parameters change I just need to change it in one place and regenerate the document and I don’t need to worry about errors induced by pasting in values.

Take a look at Cook’s post for the point of view of someone who, although technical, is not really part of the developer community.

Posted in General | Tagged , | Leave a comment