Zamansky 65: Live Python

Mike Zamansky has another video up in his Using Emacs Series. This time the video is about the live-py-plugin. The link takes you to the master GitHub repository that has code for Emacs, PyCharm, and Sublime Text. There’s a tutorial by the author for using it with Emacs here.

The idea is that as you type Python statements, the results are shown in another window. What gets shown can be quite complex. For instance, the code

for i in range(5):
    print(i+1)

will show the result for each value of i. That’s not too surprising but

def factorial (n):
    if (n==1):
        return 1
    else:
        return n*factorial(n-1)

factorial(5)    

will show you the results of factorial(5), factorial(4),⋯, factorial(1) so it’s a nice way of seeing what your code is doing. Zamansky shows the factorial example and a slightly more complex case of the first example so you can see the live-py results in action. It’s a nice package and worth taking a look at if you’re a Python programmer.

The video is comparatively short—about 8 and a half minutes—so you should be able to fit it in easily.

Posted in General | Tagged | Leave a comment

Today is a Palindrome

Today’s date, 02022020, is a palindrome. Palindromic dates happen all the time but today is special. So special that it’s unique. First of all, today is a palindromic date everywhere. Because of the silly date format that either the U.S. or Europeans use (take your choice), it’s almost always the case that a date that’s palindromic in the U.S. is not palindromic in Europe and vice versa. Dates that work for both are very rare, and today is one of them. The last time it happened was 909 years ago.

But as Steve Jobs used to say, “One more thing.” Today is also a palindromic split in that it’s the 33 day of the year and there are 333 days left. A day that is both a universal palindromic date and a palindromic split is unique: there’s only one and today is it.

Here’s a video by Matt Parker, the Stand-up Mathematician, that explains all this in more detail:

Posted in General | Tagged | Leave a comment

Keeping a Table Header Fixed While Scrolling

Bastien Guerry tweeted about a really awesome new Org-mode feature:

A little further down in the thread, Guerry notes that, “As of this morning, it’s now called M-x org-table-header-line-mode RET” so if you’re living on the edge, use that name instead.

He doesn’t say when it will be officially released but since it’s in Master the next release will probably have it. This isn’t, of course, a huge deal but it does eliminate one annoying aspect of working with tables. Now you can lock the header in place and be able see what each column means. Very nice.

Posted in General | Tagged , | Leave a comment

Spacemacs for Writers

Frank Jonen has an interesting GitHub repository to help non-technical people use Spacemacs for writing. Jonen says that his interest in using Emacs for writing and the resulting repository were inspired by Jax Dixit’s talk for the New York Emacs Meetup on Emacs for writers.

As you all know, I’m always interested in the way non-technical people use Emacs so of course I had to check it out. The previous examples of Emacs-for-writers that I’ve written about all involved using vanilla Emacs so this instance is noteworthy for advocating Spacemacs.

The repository consists mainly of Jonen’s .spacemacs configuration file and a README that’s part inspiration and part installation guide. The installation segment covers installing Emacs, Spacemacs, and Jonen’s configuration.

I don’t know if Spacemacs is a good choice for a new user—not a Vim immigrant, where it’s obviously a good choice—but, say, a Word immigrant. Irreal is fortunate in having some passionate Spacemacs users as readers so perhaps one of them can weigh in on whether Spacemacs is the optimal choice for a new, non-technical user. Regardless, it’s a choice that’s working for Jonen and may work for other writers looking to escape the yoke of Word and its evil siblings. If you’re a writer who would like to experience the joy of text-based editing that doesn’t insist you do things its way, take a look at Jonen’s README. Perhaps you’ll be inspired.

Posted in General | Tagged | Leave a comment

A Test for the Iron Law

If you’ve been around Irreal for a while, you know about the Iron Law of Data Collection. Briefly, the law says that anytime data is collected

  1. No matter the rationale and promises about the data collection and the purposes to which it will be put, it will invariably find new uses as interested parties demand access to it.
  2. Eventually, the data will be abused.

Usually when I write about the Iron Law it’s after the fact: the data has been collected and the mission creep and abuse have already begun. This time, the London Metropolitan Police has provided us with an opportunity to test the law ab initio. The Met has announced plans to implement facial recognition cameras on London’s streets as part of a plan to catch serious criminals.

Civil libertarians are not amused but despite their vigorous objections the Met is going ahead with its plans. They claim the system is 70% accurate so, apparently, there’s no reason for alarm. Independent studies of the system, however, found it to be about 19% accurate.

That’s one data point. Here’s another:

The Met has made promises to the mayor of London, Sadiq Khan, after an
independent ethics review raised concerns over its earlier trials of
facial recognition software. The system will not be linked to other
official databases.

That very specific. We will not make this data available to be used with other databases. The Iron Law predicts that of course it will be made available to those other databases eventually and that it will be abused by, say, being used to identify law abiding citizens legally protesting government actions. Time will tell, of course, but I know which way I’m betting.

Posted in General | Tagged | Leave a comment

Finding The Intersection of Two Lists

I recently saw an Emacs Stack Exchange Question on how to find the intersection of two lists. The questioner asked if there was a better way than the obvious solution of looping over both lists looking for matches, a \(O(mn)\) solution for lists of size \(m\) and \(n\). The “best” solution was to use the Elisp function seq-intersection, which accomplishes the task in one function call but that under the covers loops over both loops giving it \(O(nm)\) performance

My first thought when I saw the question was to use a hash table to capture the items in the first list and then check the second list against the hash. That would be a \(O(n+m)\) solution but, of course, the multiplicative constants would be much bigger for \(O(n+m)\) than for \(O(nm)\). My gut feeling was that the hash table solution would be a bit faster but as my experiments with palindrome predicates showed, my gut is not particularly reliable.

The only answer was to run some benchmarks. I wrote a bit a Elisp to generate a couple of random lists and a function to find their intersection using the hash table method. The hash-intersection function is pretty simple. It adds each entry of the first list to a hash table with a value of t. Then it checks each entry in the second list to see if it’s in the hash table.

(defun make-random-list (n)
  (let ((l nil))
    (dotimes (i n l)
      (push (random 1500) l))))

(defconst lst1 (make-random-list 1000))
(defconst lst2 (make-random-list 1000))

(defun hash-intersection (l1 l2)
  (let ((ht (make-hash-table :test #'equal))
        (acc nil))
    (mapc (lambda (x) (puthash x t ht)) l1)
    (mapc (lambda (x) (if (gethash x ht nil)
                          (push x acc)))
          l2)
    acc))

Then I ran benchmarks that called hash-intersection and seq-intersection 100 times on the two lists. The benchmark-run macro reports total running time, the number of garbage collections, and the time taken by garbage collection.

(benchmark-run 100 (hash-intersection lst1 lst2))
0.081114 0 0.0
(benchmark-run 100 (seq-intersection lst1 lst2))
8.2707 0 0.0

As you can see, there was no garbage collection. Surprisingly, the hash-intersection function was about 100 times faster, which is much faster than I expected. I thought there might be garbage collection with the hash table method but there wasn’t—perhaps there would be with larger lists.

Regardless of the garbage collection results, the hash table method certainly takes more memory. Even so, the speed results suggest that for most reasonable inputs, the hash table method is a good choice. With shorts lists of 8 elements, both methods took about a microsecond for a single run so there doesn’t appear to be a penalty for short lists either.

Posted in General | Tagged , | Leave a comment

Org Mode 9.3.2

Bastien writes that Org Mode 9.3.2 has been released. It’s a bug release so no new features but if you are experiencing problems with Org, you should consider upgrading. Even if you aren’t seeing problems, it’s probably a good idea to update.

Correction

In Sunday’s post on Undo Region, I said that selective undo did not appear to work with undo-tree. One of Irreal’s intrepid readers, hjmr, discovered that it did work in older versions of undo-tree and that in the latest version it still works but you have to enable it. I’ve added an update to the Undo Region post that gives the spell for making it work but because there appears to be a lot of interest in selective undo, I wanted to make sure all of Irrealdom knows that you can use it with undo-tree.

Posted in General | Tagged , | Leave a comment

Another Great Example of Recursion

Remember how I told you that Joe Marshall was really good at coming up with elegant examples of recursion? He’s back with another. This time it’s not one he thought up but it’s too good not to share.

Here’s the problem: You have a server that you can query for time-stamped records by specifying a begin and end date. The problem is that the server will return (only) an error if the number of records you request is too large. There’s no way to tell, a priori, how many records exist between any two dates. How do you write the client?

Marshall offers a beautiful recursive solution that solves the problem in 10 lines of—I guess—Java (I’m not a Java maven so I’m not sure). It’s very much worthwhile reading and understanding the example so you can add the trick to your toolkit.

Marshall’s larger point is that often people are afraid of and resist recursive algorithms but they shouldn’t be. It’s not always the right solution but it is for many problems and usually results in a simple and easy-to-understand solution. As Marshall says, one can imagine solving the above problem without recursion but that solution would be more complicated and probably harder to maintain.

I learned to use and appreciate recursion from reading Paul Graham and it’s amazing how often I’ve been able to amaze my colleagues with a nice recursive solution to some problem. If you’re not comfortable with recursion, you should try to fix that.

Posted in General | Tagged | Leave a comment

Undo Region

Here’s an Emacs feature that I—and, apparently, many others—didn’t know about:

That’s a fantastic time and effort saver when you want to undo a change that’s not at the tip of your undo tree.

Sadly, as far as I can tell, it doesn’t work with undo-tree, a package that I’m not willing to give up. For those of you not using undo-tree, you should try this out. It’s built into the Emacs undo system so there’s nothing to install.

According to the Emacs Manual, if you aren’t in Transient Mark mode you will need a prefix argument to undo. If, like most people these days, you are using Transient Mark mode, you won’t need the prefix argument.

Update [2020-01-27 Mon 12:03]: Hjmr reports that it will work with undo-tree if you set undo-tree-enable-undo-in-region to t. I’ve verified that this works so we can have the best of both worlds: undo-tree and selective undo.

Posted in General | Tagged | Leave a comment

Surprise! Online Advertisers Are Breaking The Law

According to a report by Forbrukerradet—which I think is the Norwegian Consumer Council—online advertisers are ignoring the GDPR and continuing to track consumers and build profiles of them. The report, linked above, and the technical addendum are both quite long (193 and 93 pages respectively) and detail how Android apps are continuing to send Advertiser IDs and other personal data—including precise GPS coordinates—to third parties.

One particularly disturbing revelation is that the Grindr app, a dating app for gay, bi, and trans, people was collecting personal and sensitive information from its users and sending it to numerous third parties. The report devotes 39 pages to Grindr and its data sharing.

The report includes a legal analysis that concludes the advertisers are in breach of the GDPR in significant ways. As I’ve said before, the problem is that there’s so much money in adtech and its abuse that rouge companies are making the calculation that it’s worth the risk of cheating and that they’ll just pay the fine if they get caught. And, of course, go right on violating the law. There needs to be harsh individual penalties for people involved not just their companies. Until that happens, expect more of the same.

Posted in General | Tagged , | Leave a comment