Deleting Blank Lines

The Learn Emacs Twitter feed has a handy tip for dealing with blank lines:

It turns out that the delete-blank-lines command is a little more nuanced than that. The actual rules for invoking it (according to the documentation) are:

  1. If the point is on a blank line surrounded by others, delete all the surrounding blank lines, leaving just one.
  2. If the point is on an isolated blank line, delete that line.
  3. If the point is on a nonblank line, delete any blank lines that immediately follow.

This isn’t a command that I’d use everyday but it seems perfect for cleaning up a text file with lots of blank lines. Often times, I see imported data like this so it’s worth remembering the command.

Posted in General | Tagged | Leave a comment

Release Candidate 1 for Emacs 26.2 Is Out

Nicolas Petton announced on the Emacs-Devel list that Emacs 26.2 RC1 is out. If you verify Nico’s signature—as you should—you’ll notice that GPG says the key has expired. As Nico explains, the key is still good but the GNU keychain has not been updated. You can safely ignore the message.

I compiled and installed it on my Mac in the usual way without problem and am using it to write this post. The installation is brand new so I don’t have much experience with it yet but so far everything seems excellent.

As usual, thanks to John, Eli, Nico, and all the others for their work in bringing us this release.

Posted in General | Tagged | Leave a comment

An Application of Bayes’ Theorem to Differential Privacy

In a nice followup to yesterday’s post about differential privacy, John Cook, the proprietor of the Data Privacy Twitter feed, has a nice post that uses Bayes’ Theorem to implement a simple differential privacy scheme.

The problem is to gather a yes/no answer to a question from a group of people without revealing any individual’s “true” answer. The post is nice because the method it uses is a simple application of Bayes’ theorem, making the mathematics accessible to most Irreal readers. The protocol involves each respondent flipping a coin once or twice to determine their answer—see Cook’s post for the details.

Differential privacy appears to be emerging as the go-to solution for anonymizing data in a way that protects the privacy of the respondents but still allows useful aggregate data to be extracted from the information. Even the U.S. Census Bureau will be transitioning to differential privacy for the 2020 census. If you’re interested in such things, the Census Bureau has a paper describing some of the details.

Last Minute Addition:
Just as I was getting ready to publish this, I came across this talk by John Abowd of the Census Bureau that talks about their plans for the use of differential privacy. The talk is an hour long so here are a couple of interesting points if you don’t have the time or interest to watch it. Abowd say that noise infusion is an absolute necessity to protect the data. As an example of why this is true and of how easy it is to identify respondents from limited data, the bureau combined commercial data bases with just 3 items from the 2010 census data: age, sex, and census block (a relatively small area that the bureau uses to group respondents by location). That was enough to uniquely infer the identity of the respondent for 48% of the population. When those results were checked against the actual data, it turned out that the inference was correct for 38% of the population.

Posted in General | Tagged | Leave a comment

Differential Privacy

One of the tough problems in ethical data gathering is how to collect statistics while respecting the privacy of those the data is being gathered from. It’s widely known that most forms of data anonymization are not robust and that it takes surprisingly little information to deanonymize it.

One method that does show promise is differential privacy. The basic idea is that the data is perturbed in such as way that its origin can not be reconstructed but such that statistical measures, such as mean values, can still be estimated. That allows the collection of aggregate data while protecting the individual targets of the collection.

Recently John Cook’s excellent Data Privacy Twitter feed had a pointer to an interesting post on the Microsoft Research Blog on how they collect user telementry anonymously using differential privacy techniques. The idea, they say, is to encode the data on the user’s device in such a way that the output of the encoding is approximately equally likely to have come from any other user. At the same time, the encoding allows the recovery of useful aggregate data.

The post describes a method of encoding the value of \(x \in [0,M]\) in a single bit in such a way that the mean can still be estimated. It’s a nice trick and the post is worth a read just to see how effective differential privacy can be.

Posted in General | Tagged | Leave a comment

Numbering Org Table Rows

Álvaro Ramírez tweeted a handy tip that I used to know about but had forgotten:

Lots of tables need a row number and using this tip it’s easy to add them when you’ve finished making the table rather than putting them in as you go along. That’s especially handy if you decide to reorder the rows.

Normally mc/insert-numbers will start the numbering at 0 but you can change that with a prefix argument. Long ago I mapped that function to Hyper+~ but I like the way Ramírez maps it to # in the region-bindings-mode-map. That makes it much more intuitive and easy to remember. Maybe if I’d done that to begin with, I wouldn’t have forgotten about it.

Posted in General | Tagged , | Leave a comment

Running Your Life With Emacs

I’ve written a lot about how I hate leaving Emacs and find that its consistent UX and key bindings make a huge difference in the efficiency of my workflow. Not everyone agrees. Many people think I’m being overly sensitive when I say that I can’t effectively use multiple editors because the different key bindings mess with my muscle memory.

On the other hand, Garrett Hopper agrees with me. In a post entitled Running Your Life With Emacs, he says

…I often want to use the same efficient key bindings I use while programming when I’m doing other tasks. I want to be writing an email or documentation and edit a code snippet in the same way I normally edit code. I want to manage Git repositories right from my editor without having to touch the mouse. I want to browse the web in my editor, so I can easily copy code examples and run them. I want to track my to-do lists and the amount of time spent on each task.

That’s an excellent summary of my feelings.

Hopper says he hates switching context and that by doing as much as possible in Emacs, he reduces it to a minimum. He even does much of his browsing in Emacs. I find that eww doesn’t render sites reliably so I have a hard time embracing it. Almost all my time is spent in either Emacs or Safari so eliminating my reliance on Safari would mean I would almost never have to leave Emacs. I can only hope.

The rest of the post covers the many advantages of Emacs including

  • Discoverability
  • Built-in documentation
  • Customizability
  • A rich package system
  • and, of course, Org Mode

It’s an interesting post and if you’re an “everything in Emacs” adherent, it provides some self affirmation.

Posted in General | Tagged | Leave a comment

Goto

Everyone in our field knows about Dijkstra’s famous paper Go To Statement Considered Harmful but how many have actually read the paper or know what his arguments were? Mostly we use it as a template to generate memes of the form “\(X\) Considered Harmful.”

Vivek Haldar has a video blog entry in which he reads the paper for us. “Read” means he goes over the paper in detail and talks about the arguments that Dijkstra makes. The paper is short—only one and a half pages—so this isn’t as tedious as it might sound. The video itself is just short of 6 minutes. If you haven’t read the paper, you really should watch the video if only to know what you’re talking about when you invoke Dijkstra’s name.

Dijkstra makes his argument in technical terms. A more succinct and approachable take is presented by Professor David Brailsford in the excellent Computerphile video, GOTO, Goto & Goto. In it, Brailsford says that the point of eliminating gotos is to make our intentions clear. Consider the while loop

while (x > 0)
{    
    do_something_with(x);
    x = x - 1;
}        

and its implementation with gotos

l1: if (x <= 0)
        goto l2;
    do_something_with(x);
    x = x - 1;
    goto l1;
l2:            

No one with more than a week’s experience will have the slightest difficulty understanding the while loop with a single glance but the goto version—especially with a less trivial example—is harder to understand because it’s not immediately clear that we have a loop. What’s the purpose of that first goto, for example? Without reading further down we can’t tell if it’s part of a loop, a simple if statement, or something else.

The Computerphile video, along with some silliness with a Rubik’s cube at the end1, is about five and a half minutes so you can watch both videos in less than a dozen minutes. You should: they’re both worthwhile.

Footnotes:

1

Involving the two Gotos at the end of the video’s title

Posted in Programming | Tagged | Leave a comment

Dealing with GitHub Pull Requests in Emacs

Laurent Charignon has an very nice package for dealing with GitHub pull requests from within Emacs. His package, github-review, allows you to retrieve the pull request from GitHub and deal with it entirely within Emacs. You can even work off-line if you retrieve the pull requests first.

When invoked, github-review displays the description from the PR and a diff of the proposed changes. You can add additional comments or code snippets to the buffer. After reviewing the PR, you can accept, reject, or comment on it and have the results returned to GitHub.

Besides the obvious benefit of not having to leave Emacs, you can easily see related code to provide better context. If you often deal with PRs, this package seems like a real win. It’s probably worthwhile even if you only occasionally have to deal with them. The interface is simple and easy to use. Although Charignon says it’s not yet in Melpa, it’s been added since his post.

Posted in General | Leave a comment

How and Why To Normalize Unicode

From the excellent TeX Tip twitter feed, I found a pointer to an excellent article by Alessandro Segala concerning something I didn’t know much about and that many Irreal readers might not know about either: how and why to normalize unicode. If you’re like me, you haven’t even heard of normalizing Unicode before.

The problem stems from the fact that many Unicode characters have more than one representation. The example that Segala gives is the character ë. It can be represented as either a single Unicode character or as the composition of two: the lowercase ‘e’ and the umlaute, ‘¨’. In both cases the displayed result is the same, ë, but the internal representation is different.

This matters a lot when you’re checking for equality, as in a search say. If someone enters their name as Zoë you may not find it in your database if it’s stored in a different representation. Unicode normalization is a way of solving this problem. The idea is to convert all representations of ë to a single one. According to Segala, there are 4 standard representations and you can use whichever is more convenient but the goal is to have all characters use the same one.

Happily, there are standard library functions to do this. For example, in JavaScript you can use the built-in function String.prototype.normalize() to do it. Take a look at Segala’s post for details and more information.

Posted in General | Tagged | Leave a comment

EmacsCast #8: Writing

Rakhim Davletkaliyev is back with another episode of his Emacs podcast, EmacsCast. This time he presents part one of a two-part series on writing in Emacs and Org mode. My first thought as I started to listen to the podcast was, “Mwa Ha Ha, he’s now been totally assimilated into the Emacs Borg.” I don’t know if that’s really true or not but in the first episodes he made a point of saying that he wasn’t looking to switch editors, he just wanted to experiment with Emacs and see what all the excitement is about. Since then, he starting using Emacs and Org mode to produce his blog(s) and was doing more and more of his work in Emacs.

This podcast documents his continuing journey down that road. The current episode concentrates on using Emacs for writing. Davletkaliyev says that he now does all his writing in Emacs and Org mode and he spends most of the podcast—after his usual recap of recent configuration changes—discussing how Org mode makes writing easier and is really the best tool he’s found for writing projects.

He begins by noting that Org mode matches his default writing method. He likes to start with an outline—maybe as simple as a list of chapters, perhaps more detailed—and then “fill in the blanks.” He describes the outline as a skeleton and adding the actual content as putting meat on the skeleton.

One common use case in writing is having the text open in two different windows. For example, a complicated novel may have several niche characters and it’s helpful to have a list of their names and other information about them available while writing the story. Or you may want to keep your outline open in one window while working on a particular chapter or scene in another window. That’s basically the setup that Jay Dixit uses. In either case, Emacs’ indirect buffers are exactly what you need. Davletkaliyev talks about that in some detail.

Finally, when the writing’s done you’ll probably want to export to some other format such as PDF, HTML, or docx/ODT. Org mode makes that easy, either directly or through its interface to Pandoc. Davletkaliyev talks about a book he’s writing that he exports to several formats. He has things set up so that when he saves the source document, all the other formats are generated automatically.

He promises to discuss more use cases in part 2 of the podcast. The podcast is just short of 26 minutes and definitely worth listening to when you have a half hour to spare.

Posted in General | Tagged , | Leave a comment