Adding System Notifications to Your Org Agenda

If you’re a Unix/Linux/MacOS user, chances are you have one or more cron jobs set up to handle routine maintenance chores. Cron jobs are an extraordinarily useful tool to make a lot of busy work disappear. Still, sometimes things go wrong and you’d like to know about it. That’s easy to do too. You can simply have your script output a notification of any anomalous conditions and cron will mail the notification to you.

The problem is that cron mails the notifications to your local machine mail account, which virtually nobody checks. You can, as Karl Voit used to do, set yourself a reminder to check it once a week or month or whatever time frame makes sense for you but that just leads to more busy work and problems may sit unnoticed between your scheduled checks.

Voit finally got tired of checking the machine mail account on each of his machines and set up a general mechanism to add cron job exception reports to his Org mode agenda. That turned out to be pretty easy to do. Voit doesn’t like programming in Elisp so he wrote some python scripts to append Org entries to his errors.org file. The cron job scripts call the python script to add errors and appropriate information to error.org which then gets displayed in his agenda. Follow the link to Voit’s post for the details including a few of the actual scripts he uses. It’s a very nice system and removes the need to periodically check for problems.

Of course, if you like Elisp, it would be easy to replace the Python with some Elisp, perhaps calling it from a script as Karlicoss showed us. In either case, take a look at Voit’s post. It’s full of good ideas for handling the routine but boring details of administering your own machine.

Posted in General | Tagged , | Leave a comment

SICP with JavaScript

ADDED BEFORE PUBLICATION: This isn’t really a Red Meat Friday item but the content could be considered controversial and it is Friday so if you’ve been yearning for another Red Meat Friday post, you’re welcome.

I’ve been dithering on whether or not to comment on this for a couple of weeks. On the one hand, it makes the beautiful and important SICP available to those for whom Scheme is too scary—although I’d argue that JavaScript is by far the scarier language—and brings its important lessons and techniques to a wider audience. Those of you who have read Irreal for a while know that I consider SICP to be arguably the best book ever written on Computer Science. Certainly, it’s among the best so I’m happy to see its wisdom spread wider.

On the other hand, it does seem like sacrilege. It’s not unlike rendering Beethoven’s Fifth as Heavy Metal. Sure, you can do it and some people will probably like it but somehow it just doesn’t seem right. Commenters on the current programming language landscape can’t seem to agree on whether JavaScript or PHP is the worst widely used language but JavaScript is certainly in the running so it is a shame to replace the small, well-defined and elegant Scheme with it.

None of the above, by the way, is to disparage the work by those who worked on the project. It obviously took a lot of effort and, from my brief skimming of the results, they did a good job. Still, I just can’t get over the notion that it’s blasphemy.

Posted in General | Tagged | Leave a comment

In Praise of C

I’ve been lucky to spend almost my entire career working in C. These days, I do more Lisp but for many years, C put bread on the table. Like all earthly things, C is starting to suffer a decline in popularity if not in use. There are many reasons for this. Some of them are stupid: “C is used only by old fogey gray beards and why should I waste my time on that when I can use this shiny new scripting language? Besides, who needs to get close to the machine these days?” One often hears similar remarks about Emacs.

But there are good reasons too. Memory management in C is a mine field and famously able to generate errors. As Perry Metzger says, C also has a large body of undefined behaviors that are apt to bite even the most careful programmer. Still, I love C and enjoy using it. Many folks feel the same.

One of those folks is Christopher Thomas who devotes a post to explaining why he loves coding in C. His reasons are mostly that C lets him get close to the machine when he needs to and that gives him a feeling of power in his programming. His other main point is that C serves as a model for most other “modern” programming languages. C is, he says, an Ur-language.

Many, many years ago most software was written in assembly language and programmers—despite importuning from management—were loath to give it up. A significant reason for C’s ascendancy was the fact that it was the only language that programmers would use without cheating and dropping back to assembly. Current C programmers probably have similar feelings and will only reluctantly be dragged into safer languages.

Posted in Programming | Tagged | Leave a comment

Why (or Why Not) Switch to Emacs

Protesilaos Stavrou has a very nice, detailed video that addresses the question of switching to Emacs. His approach to Emacs is, it seems to me, the correct one. He starts by stating—emphatically—that Emacs is not an editor; it’s a Lisp interpreter. That means you can make it do whatever you want: email, RSS, calendar, music, even text editing if you want.

His second point is little appreciated and much more controversial: the default Emacs keys are not that crazy. It’s not an easy case to make, especially when compared to Vim. While Vim has a logical set of composable commands that are easy to learn, Emacs’ key sequences seem random but are mnemonic once you learn the design principals. Still, Stavrou makes a reasonable case. They’re definitely not as easy or logical as Vim’s but they do have a certain tractive logic.

The most unusual part of Stavrou’s presentation is his list of reasons why you might not want to change to Emacs. It won’t, he says, make you cool or give you social acceptance. At the end of the day, no one cares whether or not you use Emacs. Not your employers and not your colleagues. In particular he says that if your current work flow is working for you, there’s no reason at all to switch to Emacs.

His final point is that Emacs requires commitment. You can’t be an “Emacs tourist.” Mastering it will take effort and won’t happen over the weekend. I see this realization a lot from people who have tried several times to adopt Emacs but couldn’t make it stick. It was only when they fully committed using Emacs all the time that they got over the initial hump and made Emacs their own.

The video is an hour long so you’ll definitely need to schedule time but I found it enjoyable and worth the time.

Posted in General | Tagged | Leave a comment

Emacs for Writers

Jacob Moena has a long post on using Emacs for creative writing. He begins by explaining why anyone would want to do such a thing. Of course, Emacsers already know the answer: Emacs will make you more productive, especially if you are a touch typist.

The majority of his post is a “whirlwind tour” tour of Emacs. It’s a fairly detailed tutorial on the editor’s features that a creative writer is apt to find useful. He also covers some of the packages that he uses in his own writing, including, of course, Org mode. He notes that it’s most useful to think of Emacs as an editor construction kit—although he doesn’t use those terms—and that this is its great strength: you can make Emacs adapt to your way of working instead of having to adapt your way of working to your editor.

His most important takeaway, I think, is

“The secret about Emacs is that it is driven by muscle memory, just like a musical instrument. It takes some time to get there, but once you do, you can operate it instinctively.”

If you’re an experienced Emacs user, you’ll probably find the whirlwind tour boring since it covers material you’re already familiar with. Still, he does cover some specialized commands that you may not know about so it’s worth at least skimming over it. If you’re an Emacs n00b and interested in seeing if Emacs is a good fit for your writing, Moena’s post will help you get started and tell you what to expect. There are a few typos (usually involving command shortcuts) that may be confusing so if you see something that doesn’t appear to make sense, it’s probably just a typo.

Posted in General | Tagged | Leave a comment

Easing the Use of Strong Passwords on a WiFi Router

François Marier has a cute trick to make using long and secure passwords on your WiFi router a little less painful. Setting a, say, 64 random character password isn’t too much trouble if you’re the only one using the router and you have a single device. But as soon as you have multiple devices or multiple people—guests, say—needing to use the router it becomes a nuisance. Marier’s idea is to store the password as a QR code so that it can be scanned by devices needing access.

That will work better than you think it might because both iOS and Android devices will recognize that you’re scanning a WiFi password—that information is part of what’s encoded in the QR image—and ask if you want to join the network. You don’t need a special app for your phone or tablet, you just use the camera app as usual. That’s pretty neat.

Marier uses the qrencode library to generate the QR code. His link is to the Debian package but other Linux distributions have packages for it too. The above link has the source if you want to build it yourself but there are a lot of dependencies. If you’re on a Mac you can get the binary from Homebrew.

The iPhone has a nice way of sharing WiFi passwords with other iOS devices but Marier’s method works outside Apple’s ecosystem so you may find it more useful.

UPDATE [2019-12-31 Tue 11:43]: There’s also a nice Emacs interface to qrencode if you want to expand on the idea.

Posted in General | Tagged | Leave a comment

Remote Work Will Become the New Normal

The forward march of remote work continues apace. Despite setbacks like Marissa Mayer of Yahoo! putting an end to their remote work program, researchers continue to gather evidence that remote work is a win for both employers and employees.

Over at Fast Company, Jessica Stevens argues that remote work is here to stay and will become the new norm. Of course, remote work isn’t for everyone and even those amenable will need support from their employer. Like all articles of this sort, Stevens has a list of things that the employer should do to help ensure success. Her list is:

  1. Employers should provide remote workers with the technology and infrastructure they need to do their job remotely in an efficient, low-friction way.
  2. Help the employee achieve “disciplinary excellence” by implementing systems to measure progress and provide feedback.
  3. Provide clear goals and instructions so they know what’s expected from them.

Stevens omits the item that most commenters feel is most important: Provide a robust communication environment so that remote workers know what’s going on in the company, know what other workers are doing, and don’t feel isolated. One could argue, I suppose, that that’s implicit in the three goals she lists but it seems orthogonal to me.

Remote work is becoming so ubiquitous that there’s almost no point in continuing to write about it but as I’ve said before, I’ve been fascinated by the subject for several years. When I first got interested in the subject, remote work was rare and confined to a small set of job types such as journalism. Now it seems to be everywhere and, in the tech sector at least, it’s unusual for a company not to offer some type of remote work program.

Posted in General | Tagged | Leave a comment

Query Replace with Occur

Over at (with-Emacs, Clemens Radermacher has posted a short tutorial on using occur and query-replace across several files. It’s sort of a riff on abo-abo’s post on refactoring multiple files. To a first order approximation, the idea is to use occur to locate the term of interest, put the occur buffer in edit mode, and then use query-replace or your favorite replacement tool to make the actual substitutions.

This works fine if you’re interested in a single buffer but if the text of interest is spread across several buffers, you need to use multi-occur. I can’t ever remember doing this because multi-occur is hard to use. You have to specify each buffer you’re interested in and while you can make this a little easier with multi-occur-in-matching-buffers, it isn’t ideal either.

For me, the most interesting thing about Radermacher’s post is his recommendation to use Nicolas Petton’s noccur. It’s just like occur—actually, it’s a front end to the multi-occur command—but you can ask it to operate on all files in a project or all the files marked in a dired buffer. Noccur will load the requested files into buffers and call multi-occur.

There are plenty of other ways of doing this but Radermacher’s solution works in a seamless way for project files and dired-marked files. It’s definitely worth knowing the technique. Radermacher offers some code snippets to provide a bit of context for your replacement decisions and to solve a couple of other problems. It’s a good post and definitely worth taking the time to read.

Posted in General | Tagged | Leave a comment

Org Mode 9.3.1

Batien writes that he’s released Org 9.3.1. It’s a bug fix so you should probably update if you’re having any problems with Org 9.3. I updated yesterday and haven’t had any problems. Of course, that’s a study of \(n=1\) so you may see different results.

Thanks to Bastien, Nicolas, and all the others for the hard work they do to bring us this essential package and for keeping the development robust and active.

Posted in General | Tagged , | Leave a comment

Implementing Palindrome Predicates

Joe Marshall is a long-time Lisper with an ability to come up with really elegant solutions. Indeed, the second ever Irreal post was about Marshall’s brilliant solution to a problem from SICP. Recently, he recounted a story about a recent phone screen he had in which he was asked to implement a palindrome detector. He wrote both an iterative and a recursive version. He says he gave them the iterative version so they wouldn’t think him an idiot but that he liked the recursive version better because of its simplicity and elegance.

If you think of a palindrome detector as embodying the three rules

  1. The empty string is a palindrome
  2. A string with a single character is a palindrome
  3. If the first and last characters of a string are identical and the substring between them is a palindrome, then the original string is a palindrome

the recursive algorithm writes itself.

Marshall doesn’t show his code so of course I had to try it myself. My initial effort was to bang out an Elisp implementation:

(defun palindromep (string)
(let ((len (length string)))
  (cond
   ((zerop len) t)
   ((= 1 len) t)
   ((not (char-equal (aref string 0) (aref string (1- len)))) nil)
   (t (palindromep (substring string 1 -1))))))

That’s practically a word-for-word rendition of the three rules and it worked well. But then I started thinking that Marshall said the iterative solution would be faster for most compilers. I don’t know what language he used but it almost certainly wasn’t Lisp so I wondered if the iterative version would be faster in a Lisp language. Of course I had to write an iterative version so I could compare them.

My first inclination was to write the iterative version in Elisp too but Elisp isn’t tail recursive so it would be hard to run the recursive version on large inputs. Therefore I decided to start over with Scheme. The recursive version is the same, mutatis mutandis, as the Elisp version.

(define palindrome-r?
  (lambda (string)
    (let ((len (string-length string)))
      (cond
       ((zero? len) #t)
       ((= 1 len) #t)
       ((not (char=? (string-ref string 0) (string-ref string (1- len)))) #f)
       (#t (palindrome-r? (substring string 1 (1- len))))))))

The iterative version is a little more complicated—mostly because of the do loop—but doesn’t seem nearly as elegant as the recursive version.

(define palindrome-i?
  (lambda (string)
    (do ((h 0 (1+ h))
         (t (1- (string-length string)) (1- t))
         (palindrome? #t))
        ((or (not palindrome?) (> h t))
         palindrome?)
      (set! palindrome? (char=? (string-ref string h) (string-ref string t))))))

The real test, though, is their relative speeds. In Scheme with its tail recursion, loops are generally implemented as recursion and you wouldn’t expect much difference. I ran the comparison in Guile Scheme, which has copy-on-modify string behavior so, again, the two versions seem like they should run in about the same time.

Of course, the results were nothing like that. I ran each version 1000 times on a large palindrome (100,000 x’s) with the following

(define str (make-string 100000 #\x))

(define bench
  (lambda (rcnt f)
    (do ((i rcnt (1- i)))
        ((zero? i))
      (f str))))

and here are the results

,time (bench 1000 palindrome-r?)
;; 9.204000s real time, 9.370000s run time.  2.330000s spent in GC.
,time (bench 1000 palindrome-i?)
;; 4.582000s real time, 4.660000s run time.  1.350000s spent in GC.

The recursive version runs almost exactly twice as long so Marshall was correct even in the Lisp case.

None of this is very important, of course, but it was an interesting exercise that reinforced the lesson that it’s really hard to predict run times without benchmarking.

Posted in General | Tagged , , | Leave a comment