Variables In Org Capture

Martin Schell has an excellent post on building and using Org capture templates. What’s interesting about his approach is that his template prompts for certain information—customer ID and site location in his example—captures that information in some local variables, and uses those variables to customize the capture for the particular customer.

His two main tools for doing this are:

  1. The %^{PROMPT|A|B|...} placeholder to prompt for data.
  2. The %(EXP) placeholder to execute the Elisp expression EXP.

He wrote some helper functions to deal with setting and accessing local variables. The first, ms/set-var, prompts the user for the value of a variable, creates the variable, sets its value, and returns the value. This is different from the %^{...} placeholder in that it captures the value of the user’s answer for later use. The other helper functions make use of the captured variables.

Take a look at Schell’s post to see the functions and how the whole thing hangs together. His needs may be more complicated than normal but the ideas he uses to solve them are handy and applicable to many—even simpler—situations.

I’ve used all the placeholders that uses in my own templates but the idea of capturing a variable for later reuse in the template is new to me. It’s a neat idea and definitely worth knowing.

Posted in General | Tagged , | Leave a comment

Success!

I’ve successfully updated PHP so although I will continue to monitor
things, everything looks fine. Let me know if you experience any problems.

Posted in Administrivia | Tagged | Leave a comment

Site Update

For some time, WordPress has been nattering at me to update PHP. I’ve been avoiding that because I’m afraid something will go wrong and the site will go offline but the recent PHP exploits have convinced me that it’s time to act. I queried my site provider and they assure me that the process is simple and direct so I’m going to do it right after I publish this.

That’s a bit silly, of course, because if something does goes wrong you probably won’t see this post either. I’ll wait a bit so that the post can get into RSS so at least I’ll be leaving some breadcrumbs.

In any event, I hope to be seeing you on the other side but if Irreal disappears for a while that’s why. Be assured that I’ll be doing everything I can to get things working again.

Posted in Administrivia | Leave a comment

Dictating Into Emacs

Sacha Chua has a really nice post on dictating into Emacs. She starts by quoting Matt Weber on how he writes better than he speaks. Chua can relate and so can I. We both feel the same way. As I’ve said before, “…my written thoughts are always much better organized than my spoken ones…”.

Being who she is, Chua resolved to fix this by arranging to dictate her posts into Emacs. As you can imagine, she encountered all sorts of problems along the way but was mainly able to find solutions for them. You can check her post—and Weber’s—to see how they’re doing that.

When I read Chua’s post, I thought, “maybe I should do that too” but then I realized that I don’t want to dictate my text. The truth is, I enjoy writing a lot more than I do speaking and I especially enjoy writing with Emacs. Although it’s not always obvious, I do a lot of revising on my posts as I write them and I usually try to make a final editing pass at least one day after I’ve written them. Speaking, on the other hands, feels more like “one and done” to me. I know that I could dictate a post and then edit the result but it’s not the same. And in any event, as I say, I enjoy writing a lot more than I enjoy talking.

I suppose, as Chua says, the day may come when ever encroaching old age, disease, or accident may make typing hard or impossible and I may be forced to consider dictation but until then, I’m happy to continue typing my text.

Posted in General | Tagged | Leave a comment

The iPhone Duo

There’s a tremendous amount of excitement about Apple’s new foldable iPhone, the Duo. A grown journalist squealed like a teenager when she saw John Ternus sporting one at a recent event. Apple is claiming that demand is so high that fulfillment wait times on orders could be as long as 3 months.

I hate to be the guy raining on everyone’s parade but I don’t get it. Rumors of an Apple foldable phone have been around for years but I always hoped they weren’t true. I’d much rather Apple devote its time to improving the regular iPhone or perhaps finally taking HomeKit seriously. The results from other manufacturers where not encouraging. All their foldable offerings were a disaster, some barely surviving their unboxing. Apple says they’ve solved all those problems but this thing has a foldable screen and it’s hard to believe it’s not going to have problems with all those repeated foldings and unfoldings.

Regardless, why would you want a folding phone? I just don’t see the attraction. John Gruber suggests an answer. The Duo, he says, is a terrible phone, far worse than any phone Apple has ever made. But he notes that what it does have going for it is that it’s a great tablet that folds up and fits in your pocket. If that’s what you’re looking for, maybe the Duo is right for you. If what you want is a phone, any recent iPhone is a much better bet. I agree with all that but I can’t get over the idea that the Duo is just a stunt.

Posted in General | Tagged | Leave a comment

Bloom Filters To The Rescue

Cristi Cretan has a very nice post on using Bloom filters to reduce system load. The TL;DR is that his team had a system that used a database to determine if they had seen a certain file before. That’s pretty straightforward but the requests were bursty and even though they had some front ends mediating the requests, it sometimes overloaded the database.

When Cretan looked at the requests, he discovered that the answer was almost always that the file was unknown. That suggested filtering the requests to avoid the expensive database lookup if the file didn’t exist. That’s a perfect case for the application of a Bloom filter. The idea is that that you hash the file identifier with a set of hash functions and set a corresponding bit for each function. On lookup, if the corresponding bit for each hash function is set, it’s likely that the value is in the set. More to the point, if any of the hash values come up with an unset bit, it’s a sure sign that the value is not in the set.

The salient point is that if any hash function comes up with an unset bit, it’s absolutely certain that the value is not in the set and the expensive database search can be avoided. You can see the details in Cretan’s post.

As I said, this is a nice application of Bloom filters but I have a couple of observations. First, Cretan got push back from his colleagues on the grounds that Bloom filters are probabilistic and the application demanded certainty. That push back speaks poorly of his colleagues as it reveals their lack of understanding of how Bloom filters work in the negative case.

Second, it’s not clear to me that a Bloom filter is needed here. To a first approximation, a single hash function should be sufficient here since we’re only interested in the negative case. It might be that a single hash function would have too many false positives and that multiple hash functions reduces that problem.

Regardless, the application of Blooms filters is just what this problem needed and it did, indeed, reduce system requirements.

Posted in General | Tagged | Leave a comment

A Small Improvement

As you all know by now, I really hate being spied on by web sites and other on-line entities. I’m pretty sure this misbehavior won’t be legal much longer but I’m equally sure that the on-line advertising industry won’t go gentle into that good night and will find ways to nibble around the edges of whatever laws get passed.

Happily, there’s Magic Lasso which pretty much solves the problem for Safari users. That would be the end of the story except that I use XWidgets with mu4e to read HTML emails and Elfeed entries through the wonderful elfeed-webkit. They work nicely but now Magic Lasso is no longer filtering their content so cookies and trackers are being accumulated. For the longest time I couldn’t find where they were being stored. I finally stumbled on its location and discovered that it was a simple text file that could simply be deleted.

The problem was that I had to remember to do it and more specifically, where the file was located. I finally stopped being stupid and wrote a simple function to delete the file:

(defun jcs-kill-cookies ()
  "Delete the cookies from Webkit"
  (interactive)
  (delete-file ".emacs.d/url/cookies")
  (message "Cookies deleted."))

It’s almost too simple to bother showing.

While I was at it, I also called jcs-kill-cookies when I quit elfeed so I don’t have to remember to do it manually. All of this is trivial, of course, but it’s another example of sanding down your workflow to make it as simple as possible. Now things pretty much take care of themselves. I suppose I should figure out a way to delete cookies after email too but for now I’m happy that the problem is mostly solved.

Posted in General | Tagged | Leave a comment

The Takete-Maluma Effect

Many years ago when I was still an undergraduate, I took a general psychology course as one of those annoying Liberal Arts electives that nerds—even at technical schools—are forced to endure. It turned out that I enjoyed it but now remember only one thing from it: the takete-maluma effect. The idea is that you are shown two shapes, one jagged and one rounded, and asked which is takete and which is maluma. It turned out that virtually all human beings, regardless of background and spoken language, chose takete for the jagged shape and maluma for the round one. You can see the shapes at the link above. It’s amazing how this stuck with me all those years. I misremembered maluma as being spelled “malumba” but otherwise recalled everything exactly.

The thing that’s striking about the effect is how universal it is. The only exceptions are people with certain physical defects and some people on the autism spectrum. Everyone else agrees: takete is jagged, maluma is rounded. Now it turns out that even dogs agree. Some researchers from the University of Parma in Italy reproduced the experiment for dogs. You can read the details at the link. The the words are different—bouba and kiki—but the results are amazingly consistent with but not as perfect as those for humans. What is it about these sounds that suggest a shape even to animals?

Posted in General | Tagged | Leave a comment

Debugging Init.el Files

Randy Ridenour has an interesting post about debugging your init file. The main problem, he says, is that he sometimes makes a change that results in unbalanced parentheses. Often he doesn’t discover this until the next time he reboots Emacs, something he doesn’t do often.

He says that his usual method for finding the problem was to do what amounts to a binary search on his init file: He comments out half the init file. If the problem occurs, he repeats the process with the commented potion; otherwise he continues with the uncommented half. But then he discovered the built-in function check-parens that checks for unbalanced delimiters in the current buffer. That’s a nifty solution to Ridenour’s problem that I didn’t know about. Another tool in the toolbox.

The other thing about his post is that it reminded me of a package I wrote about in 2015 from Artur Malabarba: elisp-bug-hunter. I haven’t used it in a while but every time I do, it works perfectly and invariably finds the error often without any further action. What it does is automate the binary search that Ridenour used to hunt down his unbalanced parentheses but it works for any problem.

If the problem throws an error, elisp-bug-hunter will find it without any user input but for more complicated situations, you can specify a predicate to indicate whether the current run succeeded or not. I load it early in my init so it will be available if there is a problem.

So the take away from this post is two really useful debugging tools: check-parens for finding unbalanced delimiters and elisp-debug-hunter. Everyone should know these tools.

Posted in General | Tagged | Leave a comment

Updating Clock Tables

I usually write my posts the evening before I publish them but yesterday, as they say, life intervened. I went to a wedding and by the time I got home it was too late and I was too tired to concentrate on writing a post. Therefore, I’m writing this the next morning so things are a bit rushed.

Marcin Borkowski (mbork) has an interesting problem whose solution is harder than you think it would be. The problem is pretty simple: Every Sunday morning when he writes his weekly review, he needs to update all the clock tables in his journal. That usually takes about a minute and mbork had the idea that he could use an idle timer to run the update. Specifically, he reasoned that if Emacs were idle for a minute it probably meant that he was otherwise engaged and that Emacs would be idle for another minute so why not fire off his update?

Of course, he wanted to do this only once a week on Sundays so it was a bit more complex than just setting the idle timer. He came up with the idea of setting a (normal) timer for 3 AM on Sunday that would set the idle timer. That didn’t quite work because of a technical issue but he got things working with yet another timer.

You should read his post for the details. His solution is interesting and shows that sometimes even simple things can be harder than we imagined.

Posted in General | Tagged , | Leave a comment