Tasker

As most of you know, I live in the Apple ecosystem so I was a bit jealous when I read this post by Ben Simon. Simon has an Android phone and therefore has access to the excellent Tasker app. One of its nice features is the ability to script tasks, something that I haven’t seen in the Apple App Store1.

Simon has a great story illustrating how useful an app like Tasker can be. Simon was out for a run when he realized that he was going to be late to meet his wife so he stopped to text her that he was running late. As he finished his run he thought that this was a task that really should be automated. He built a script that would text his wife every 5 minutes with his location (obtained from the phone’s GPS) so she would know where he was and could see on a map how long it would Take Him To Get to wherever she was. Of course, no one wants to get a text every 5 minutes so he added a couple of controls to turn it on and off. Now when he’s running late he turns it on and the application automatically keeps his wife up to date on his whereabouts.

It’s a simple, scratch-my-itch type of application and reminded me of what many of us do with Emacs: add a small bit of code to make our life a little easier. It made me wish that Tasker ran on my phone but not enough to make me give up my iPhone.

Footnotes:

1 That’s probably because of Apple’s (almost) universal prohibition of interpretive systems.

Posted in General | Tagged , | 4 Comments

An Elisp Mystery

Over at the Emacs Reddit, wadcann posts a nice idea. The problem is to have abbreviations that touch their surrounding text. The canonical example is punctuation like the em-dash:

Many national security professionals—those in the CIA, NSA, and similar...

You can’t (conveniently) use the normal abbreviation expansion mechanisms here because they expect the symbol to be delimited from the rest of the text by white space.

Wadcann solves that problem with a bit of Elisp. His post is short so you should take a look before continuing. I liked his idea but thought that the Elisp could be cleaned up a bit. Suppose, as Wadcann does, that you use /--- as the abbreviation for the em-dash. The idea is to search backwards to the slash, mark it as the beginning of the abbreviation, return to the original position to mark the end of the abbreviation, and call expand-abbrev to expand it.

That seemed simple enough. Here’s my first attempt:

(global-set-key (kbd "M-\"")
                (lambda ()
                  (interactive)
                  (let ((pt (point)))
                    (when (search-backward "/" nil t)
                      (abbrev-prefix-mark t)
                      (goto-char pt)
                      (expand-abbrev)))))

It didn’t work. After adding some debugging statements, I discovered that the (goto pt) placed the point at one character short of where it should. When I fixed that up, everything worked just fine:

(global-set-key (kbd "M-\"")
                (lambda ()
                  (interactive)
                  (let ((pt (1+ (point))))
                    (when (search-backward "/" nil t)
                      (abbrev-prefix-mark t)
                      (goto-char pt)
                      (expand-abbrev)))))

The problem was I couldn’t figure out why the first solution wasn’t correct. Even though the second solution worked it was really just treating the symptoms, not the problem. So I rewrote it using markers instead.

(global-set-key (kbd "M-\"")
                (lambda ()
                  (interactive)
                  (let ((pt (point-marker)))
                    (when (search-backward "/" nil t)
                      (abbrev-prefix-mark t)
                      (goto-char pt)
                      (expand-abbrev))
                    (set-marker pt nil))))

I don’t like this solution as much because you have to deactivate the marker at the end. Still, at least this solution made sense. I checked the appropriate Emacs code and as far as I can see, the first solution does pretty much what the third one does.

Does anyone understand what’s happening here? I have two working solutions so now it’s just a matter of an annoying anomaly that I don’t understand. If you’ve got a clue, please leave a comment.

Posted in Programming | Tagged , | 2 Comments

Keeping Your Data Safe From the NSA

After another week of seemingly never ending revelations about government snooping into our phone calls and Web activities—you guys in Europe can stop snickering; you aren’t immune either—many of us are wondering how we can regain a modicum of privacy. Realistically, if the NSA, GCHQ, or your particular country’s alphabet agency decide you are of interest for some reason there is probably little you can do. But if you’re an “ordinary” citizen, there may be some hope.

Why care? After all, “you have nothing to hide.” Of course, Irreal readers surely know better than that. In the U.S., particularly, everyone is a criminal with something to hide as Alex Tabarrok explains. Again, those of you in Europe have reason for concern too as Corrie Doctorow demonstrates in his recent Guardian article. On the downside, taking steps to protect yourself might make you pop up on some spook’s radar. On the other hand, if large numbers of us start encrypting everything maybe we can overload their systems. It will certainly be more effective than 【Meta+xspook.

So what can you do? MSN Money has a helpful article on how to secure your communications. The article covers your phone, credit cards, Dropbox, social network, and Web browsing. You probably shouldn’t consider it the last word on these matters but it does serve as a good starting point with suggestions for apps to help you claw back some privacy.

Posted in General | Tagged | 1 Comment

Speculative Problems

Jean-Philippe Paradis tweeted the perfect answer to those who complain about “problems” with Lisp syntax. The tweet was apparently provoked by this post from John Cook that, while discussing symbols in programming languages, remarked that “Lisp’s typographical monotony makes it hard to skim for landmarks.” Paradis’ tweet makes the point that supposed problems with s-expressions are speculative in that they tend to disappear once one becomes familiar with the syntax.

I’m with Paradis on this. Certainly Lisp has fewer symbols than APL and arguably fewer than Perl but I don’t find it anymore typographically monotonous than, say, C, C++, Python or most of the other mainstream languages. I certainly don’t have any more problem scanning it than I do the others. I think Paradis is exactly right: once you use it for a little while, the syntax or lack of it just disappears into the background.

What do the rest of you find? Do you think Lisp is typographically monotonous? If so, does that make it hard to scan for you? I don’t think so but Cook, who is not a stranger to Lisp, seems to believe it is. Share your experience in the comments.

Posted in General | Tagged , | 7 Comments

Lisp Hackers

For some time Vsevolod Dyomkin has been running interviews with Lisp hackers on his blog, Lisp, The Universe and Everything. Irreal has featured many of these in the past. Now Dyomkin has gathered those interviews and assembled them into a book.

The book is available for free from Leanpub. If you enjoyed the interviews or if you missed some of them, you will want to get a copy. As usual, Leanpub makes the book available as PDF, EPUB, and MOBI. You can also read it on-line if you’d rather. As I said, the book is free so there’s no reason not to get a copy if you have any interest at all. We all owe Dyomkin a word of thanks for his efforts and his generosity in making it available for free.

Posted in Programming | Tagged , | Leave a comment

My Solution to the Last Elisp Challenge

The challenge was to convert the output from dstat so that all the bytes values (some of which are given as kilobytes or megabytes) to just bytes. Thus, 2k would become 2048 and 3M would become 3145728. Similarly, dstat outputs bytes with a B suffix so 123B would become 123.

Here’s my code:

(defun to-bytes ()
  (interactive)
  (while (search-forward-regexp "\\([0-9]+\\)\\(B\\|k\\|M\\)")
    (let ((val   (string-to-number (match-string 1)))
          (units (match-string 2)))
      (cond
       ((string= units "B") (replace-match "\\1"))
       ((string= units "k") (replace-match (format "%d" (* 1024 val))))
       ((string= units "M") (replace-match (format "%d" (* 1048576 val))))))))

It makes only one pass through the data so it’s reasonably efficient. Nothing earth shattering but it gives us a chance to keep our Elisp skills sharp.

Posted in Programming | Tagged , | Leave a comment

The Hipsters and the Designer

Editorial note: I wrote this a few weeks ago (before WWDC) but didn’t publish it because it seemed a bit ranty. Now Apple has revealed iOS 7 and its icons and the hipsters are still yak yak yaking about them. How about we wait until iOS 7 is released and we all have a chance to use it and experience the new look and behavior for ourselves? I predict that when we do, most people will be just fine with it. As for me, I’m just happy that the faux leather is gone.

Most everyone who knows who Jony Ive is agree that he is an absolute master of the design arts. Even the anti-fan boys admit that few can bear the comparison. It’s strange, then, that the hipsters over at Wired are offering Ive advice on what he should do. It’s really more offensive than that; the article is entitled It’s Not About New Icons: What Jony Ive Needs to Do for Apple’s iOS. Really? Have you looked at the Wired site lately? They’re the last ones who should be offering design advice.

Actually, the whole article is premised on the idea that Ive is simply going to get rid of the skeuomorphism favored by Steve Jobs and Scott Forstall but that that’s not enough. The problem is that no one (outside of Apple) actually knows what the design will look like. Wired’s Mike Senese admits this and then goes right on assuming the premise is true. Like many, I’m not a fan of faux leather calendars so I hope it is true but also like everyone else, I don’t know.

Then there’s Maggie Hendrie who appears to think that design isn’t that important (odd given that she’s Chair of Interaction Design at Pasadena, CA’s Art Center). Ben Thompson over at Stratechery notes with amusement that Hendrie thinks Apple is missing the boat by not being more like Microsoft and Nintendo. She says that, “The very fact that we’re talking about who’s going to design the icons, who’s going to design the applications and the operating system is a little bit of a concern.” Of course, Apple isn’t talking about that. She and Wired are.

I’m sorry that the hipsters are bored by, say, the iPhone 5 but you know what? Actual users seem to like it just fine. Just as they’ll doubtlessly like iOS 7. That remains to be seen, of course, but maybe we should wait to see what it actually looks like before we declare it and Apple dead.

Posted in General | Tagged | Leave a comment

Quickutil

Robert Smith and Eitarow Fukamachi have started a really interesting new project: Quickutil. The idea is to do for small Lisp utilities what Quicklisp does for Lisp libraries. Smith explains it all on his SYMBO1ICS IDEAS blog but the TL;DR is that while the Alexandria project collects Lisp utilities, the project likes to thoroughly vet each utility resulting in very slow uptake and problem resolution. Quickutil is meant to help ameliorate this problem by providing a place to collect these utilities in a timely manner, perhaps while the Alexandria project is doing its vetting. The project is still in beta at this point but looks to be off to a good start.

Lispers, of course, love to write small utilities so you might think that there won’t be much demand for this sort of service but I believe there will be for a couple of reasons. First, programmers are often under deadline pressure (and sometimes just lazy, of course) and will often find the service useful. Second, nobody knows about everything and sometimes you need a utility that implements an algorithm that you don’t know the details of. For example, you might need to check the primality of large integers but not know much about the Miller-Rabin algorithm or the other usual methods. In those cases, it’s a huge win to have the utility there ready to use.

In any event, I’m excited about the project and am looking forward to seeing how it works out.

Posted in General | Tagged , | Leave a comment

European Lisp Symposium

Here are links to the talks from the European Lisp Symposium from this June. There were some technical problems but most of the talks were captured. These are audio links and in some cases the accompanying slides (as PDFs). If you couldn’t be there, here’s your chance to get in on the action.

Posted in General | Tagged , | Leave a comment

Regular Expressions and Emacs Lisp

Over at What keramida said…, Giorgos Keramidas poses an interesting problem. Given the following output from dstat, get rid of the B, k, and M suffixes by converting them into bytes.

----system---- ----total-cpu-usage---- --net/eth0- -dsk/total- sda-
     time     |usr sys idl wai hiq siq| recv  send| read  writ|util
16-05 08:36:15|  2   3  96   0   0   0|  66B  178B|   0     0 |   0
16-05 08:36:16| 42  14  37   0   0   7|  92M 1268k|   0     0 |   0
16-05 08:36:17| 45  11  36   0   0   7|  76M 1135k|   0     0 |   0
16-05 08:36:18| 27  55   8   0   0  11|  67M  754k|   0    99M|79.6
16-05 08:36:19| 29  41  16   5   0  10| 113M 2079k|4096B   63M|59.6
16-05 08:36:20| 28  48  12   4   0   8|  58M  397k|   0    95M|76.0
16-05 08:36:21| 38  37  14   1   0  10| 114M 2620k|4096B   52M|23.2
16-05 08:36:22| 37  54   0   1   0   8|  76M 1506k|8192B   76M|33.6

Keramidas also wants to do a bit of reformatting of the table, which we’ll ignore for this post. He does the conversion with three invocations of replace-regexp but given that he titles his post Powerful Regular Expressions Combined with Lisp in Emacs, I thought it would be an interesting challenge to write some Elisp to get rid of those suffixes and convert the entries into bytes.

Obviously, for a one-off task, Keramidas’ solution is the best but if this is something that has to be done regularly a bit of Elisp is just what’s needed. My solution is a Lisp function that converts the table with a single call. Leave your solution in the comments and I’ll post mine in a few days.

Posted in Programming | Tagged , | 3 Comments