A Groups Magic VimGolf in Emacs Challenge

Here’s a simple ViGolf challenge that has a simple solution in Emacs. Given

(a) (abc) (abcd) (123456)

turn it into

___ _____ ______ ________

That is, replace everything in the sexpr with an underscore. This is really easy with Emacs using query-replace-regexp. Here’s a solution in only 8 keystrokes. The best Vim solution is 11, so Emacs definitely wins this one.

Meta+Ctrl+% Invoke query-replace-regexp
\S-Return Replace non-spaces with
_Return Underscores
! For the whole buffer

On the other hand, my experience has been that every time I think I have the best possible solution, one of my way smarter readers shows me a much better way. If you can beat 8 keystrokes, leave a comment and tell us how a real master does it.

Posted in General | Tagged | Leave a comment

Google and Warrants

It’s become fashionable of late to beat up on Google and wonder aloud what happened to their celebrated “Don’t be evil” motto. Google provides a slew of useful services and the price we pay is to have our digital existences vacuumed up and sold to advertisers1.

We here at Irreal delight in being contrarian so I’d like to send a little praise Google’s way. Google has, for some time, published periodic Transparency Reports in which they list government (all governments) requests for user information and how they responded to those requests.

Here in the U.S., we have a constitutionally dubious device known as the ECPA subpoena that is much easier to obtain than the normal search warrant. Google has announced that they will no longer comply with such subpoenas and will, instead, require a warrant. This is a bit of a gutsy move because the ECPA is, after all, the law and by defying the subpoenas, Google is inviting a very one sided battle with the U.S. Department of Justice. In a recent SANS Institute News Bites newsletter2, William Hugh Murray notes

That the government has not hauled Google into court when it pushes
back suggests that, not only does it fear an adverse ruling, it fears
the light of day. Use and abuse of the Internet by government will
clearly get much worse before it gets better. There are now so many
exceptions to the Fourth Amendment that it operates only by accident.

Given what’s at stake and the risks involved I think we all owe Google a word of thanks. So, Google, good on you!

Footnotes:

1 Yes, that’s a little hyperbolic but only a little.

2 SANS NewsBites Vol. 15 Num. 007

Posted in General | Leave a comment

Department of Red Meat

Heh Heh. I know, I know; I’m evil but I couldn’t help myself.

Posted in General | Tagged , , | Leave a comment

Short Stories

This is a collection of short observations that don’t merit a post of their own but that some may nevertheless find interesting.

  • Social Science
    Here, in case you were wondering, is why most rational people consider the term “social science” an oxymoron.
  • Apple Maps
    This past weekend I drove up to Orlando to visit with some family members who were taking in Disney World. There’s no problem finding Disney World, of course, but they were staying at a hotel I had never been to before so I didn’t know how to get there. I used the Maps application on my iPad and was pleasantly surprised at how nice it was. The experience was very similar to dedicated GPS systems that come with some cars. You get the map, of course, but also turn by turn directions and verbal instructions as you approach a waypoint. To be sure, this is in the United States and in a very built-up area but the results, at least for this area, were impressive.
  • Tilde as Home
    Last year, I wrote about why vi uses the hjkl keys to move the cursor. That turned out to be because the ADM-3A terminal had arrows on those keys. Now the Unix & Linux StackExchange tells us why the tilde (~) is often used to represent the user’s home directory on Unix-like systems. It turns out that the answer is the same: The ADM-3A keyboard had tilde and Home on the same key. If you follow the link, you can see the layout of the keyboard as well as a picture of the actual keys. An interesting bit of arcana.
Posted in General | Leave a comment

A Xah Lee Challenge

Over at ergoemacs.org, Xah Lee posses the following challenge: Find a simple and general method to create the following text.

(global-set-key (kbd "<menu> g a") "A")
(global-set-key (kbd "<menu> g b") "B")
(global-set-key (kbd "<menu> g c") "C")
(global-set-key (kbd "<menu> g d") "D")
(global-set-key (kbd "<menu> g e") "E")
(global-set-key (kbd "<menu> g f") "F")
(global-set-key (kbd "<menu> g g") "G")
(global-set-key (kbd "<menu> g h") "H")
(global-set-key (kbd "<menu> g i") "I")
(global-set-key (kbd "<menu> g j") "J")
(global-set-key (kbd "<menu> g k") "K")
(global-set-key (kbd "<menu> g l") "L")
(global-set-key (kbd "<menu> g m") "M")
(global-set-key (kbd "<menu> g n") "N")
(global-set-key (kbd "<menu> g o") "O")
(global-set-key (kbd "<menu> g p") "P")
(global-set-key (kbd "<menu> g q") "Q")
(global-set-key (kbd "<menu> g r") "R")
(global-set-key (kbd "<menu> g s") "S")
(global-set-key (kbd "<menu> g t") "T")
(global-set-key (kbd "<menu> g u") "U")
(global-set-key (kbd "<menu> g v") "V")
(global-set-key (kbd "<menu> g w") "W")
(global-set-key (kbd "<menu> g x") "X")
(global-set-key (kbd "<menu> g y") "Y")
(global-set-key (kbd "<menu> g z") "Z")

As I write this, someone has already contributed a solution using a keyboard macro so I’ll give one in Elisp. The core of the solution is just the three lines

(dotimes (c 26)
  (insert (format "(global-set-key (kbd \"<menu> g %c\") \"%c\")\n"
                  (+ ?a c) (+ ?A c))))

If you’re going to use this more than once, then you should probably turn it into a function like so:

(defun a-to-z ()
  (interactive)
  (dotimes (c 26)
    (insert (format "(global-set-key (kbd \"<menu> g %c\") \"%c\")\n"
                    (+ ?a c) (+ ?A c)))))

Then you can just type 【Meta+xa-to-z whenever you need the text.

If it’s a one-off you can just type the 3 lines into your buffer, execute them with 【Ctrl+x Ctrl+e】 and then delete the Elisp.

If you don’t like having to erase the Elisp or you are going to need the text more than once in the buffer you can type

(with-current-buffer "name-of-working-buffer"
  (dotimes (c 26)
    (insert (format "(global-set-key (kbd \"<menu> g %c\") \"%c\")\n"
                    (+ ?a c) (+ ?A c)))))

in the scratch buffer and execute it with 【Ctrl+x Ctrl+e】 there. It will then put the text in your working buffer.

Posted in Programming | Tagged , | 4 Comments

A Real World VimGolf Challenge

In my CUA Mode Video post, I mentioned that the pointer to the video came from a comment to one of the posts in the Google+ Emacs Community. That post asks for advice on the best way of changing

a[0] = b[0];
a[1] = b[1];
a[2] = b[2];

to

c[0] = d[0];
c[1] = d[1];
c[2] = d[2];

My first thought (and what I’d probably just do if I needed this change) is a query-replace to replace a with c, followed by 【Meta+<】 to return to the top of the buffer and then another query-replace to replace b with d. That’s 13 keystrokes. Not too bad but can we do better?

Here’s a solution in 12 keystrokes using cua-selection-mode.

Ctrl+Return Invoke rectangle mode
Ctrl+2 Ctrl+n Form rectangle of a’s
Meta+f c Fill rectangle with c’s
Ctrl+7 Ctrl+f Move to last b
Ctrl+Return Invoke rectangle mode
Ctrl+2 Ctrl+P Form rectangles of b’s
Meta+f d Fill rectangle with d’s

Using Magnar Sveen’s essential multiple-cursors package I can do it in 9 (8 if I don’t exit multiple-cursors mode) with essentially the same strategy as above but, of course, that’s not using stock Emacs. If you have a clever solution, leave a comment.

Posted in General | Tagged | 6 Comments

CUA Mode Video

Over at the Google+ Emacs Community, Jean-Sébastien Ney (in a comment to this post) gives us a pointer to a very nice video on CUA-mode by Mark Mansour. Actually, the video really deals with the rectangle features of CUA-mode that we discussed recently. If, as I recommended, you put cua-selection-mode in your .emacs or init.el file, you can use all the tricks that Mansour demonstrates without having to invoke CUA-mode as he does.

Mansour shows how rectangle mode can do many of the things that Magnar Sveens wonderful multiple-cursors package does. The video is only 3 and a quarter minutes so it won’t take you long to watch it and it’s well worth the time.

Posted in General | Tagged | Leave a comment

Mickey’s VimGolf 4

Mickey’s getting into VimGolf mode with another solution to a VimGolf Challenge. I was looking at this same challenge for a possible post but Mickey beat me too it and with a very nice strategy. The challenge is to take a multi-line list of words and transpose it. Specifically, take

ultricies, vehicula, felis, sed, auctor, aenean, euismod, semper, quam, dapibus
nibh, consequat, consequat, maecenas, sit, amet, mauris, justo, quis, porttitor
curabitur, pharetra, euismod, orci, sit, amet, ullamcorper, mi, tincidunt, et
vitae, lorem, at, mi, feugiat, convallis, ac, eget, dui, fusce
blandit, iaculis, nulla, sit, amet, dolor, nec, est, ornare, volutpat

and turn it into

ultricies  nibh       curabitur    vitae      blandit
vehicula   consequat  pharetra     lorem      iaculis
felis      consequat  euismod      at         nulla
sed        maecenas   orci         mi         sit
auctor     sit        sit          feugiat    amet
aenean     amet       amet         convallis  dolor
euismod    mauris     ullamcorper  ac         nec
semper     justo      mi           eget       est
quam       quis       tincidunt    dui        ornare
dapibus    porttitor  et           fusce      volutpat

Mickey tends to concentrate more on technique than minimal keystrokes, which makes his solutions more useful outside of the narrow confines of VimGolf in Emacs. Still, it’s nice to see how efficient we can be in keystrokes if only to keep those Vim people in their place. Here, then, is my solution to the problem, which follows Mickey’s general strategy.

It helps to start off in an Org mode buffer because a shortcut key sequence for org-table-convert-region is available. Unfortunately, there is not shortcut for org-table-transpose-table-at-point but we can save a bunch of keystrokes with smex.

Ctrl+x h mark buffer
Ctrl+c | turn region into table
Meta+xo-t-t-t-a-pReturn transpose table
Meta+< beginning of buffer
Ctrl+Meta+% query regexp replace
| \| +|$Return replace |’s and surrounding spaces
Return with nothing
! replace all

That’s 30 keystrokes, which isn’t bad. The best Vim solution was 29 (with the usual rules about not counting saving the buffer) so we’re desperately in need of someone to shave off another stroke if we want to keep the Vimers from getting too smug. Of course someone could complain that smex isn’t part of stock Emacs but it really should be and since every serious Emacs user has it installed, I don’t think it’s breaking the rules—too much—to allow it.

Posted in General | Tagged | 3 Comments

Why People Pirate

Back in the beginning of January, I wrote about iiNet walking out of talks with Hollywood. The talks were Hollywood’s effort to strong arm Australian ISPs into spying on their customers to help “combat piracy.” The most compelling point that iiNet made was that the piracy problem is actually of Hollywood’s own making due to their failure to make their content available to Australians in a timely manner and at reasonable cost.

The Australians have a real beef. They can wait 6 months or more for a movie to released in their market and then expect to pay a premium. At least we here in the United States don’t have that problem. Oh…wait. Take a look at the chart at the link. Of the top 100 movies from 2012, only 7 of them were available on either Netflix or Amazon. On the other hand, 77 of them has been released to DVD.

Here’s a news flash for Hollywood: This is 2013 and people want to stream their movies. And they don’t want to wait 6 months to do it. We’re such whiners. But here’s the thing: whiners or not that’s what people want and they won’t be denied. They’ll just download the movie for free even though most of them would prefer to obtain them legally and pay for them.

Hollywood imagines they can get this genie back in the bottle but as they’re discovering in Europe, the better metaphor is not Aladdin but whack-a-mole. The sad thing is that they could pretty much solve this problem by getting rid of their outdated distribution policies.

Posted in General | Leave a comment

Ebooks and PDF

I’ve written before about the deplorable production values in ebooks: misspellings, poor typography, missing words, terrible spacing, and a general lack of cohesiveness in the finished product. The problem is particularly acute with technical books as Tim Evans-Ariyeh points out in his excellent post What was the matter with PDF? Technical books look, he says, “as if you gave a troubled child a pair of scissors and a complex book and said ‘Hey kid, somehow make this fit a smaller screen.’”

He goes on to say that, yes, there are challenges in producing a single file for many devices of varying sizes but that we’ve had a technology that solves those problems since 1993: PDF. The real problem appears to be with flowing text. Ebook readers don’t really have—or at least don’t emphasize—the notion of pages. They like to flow the text so that it fills the screen at whatever font size the reader has chosen. That works pretty well for novels but is terrible for technical books where the page structure is very often important. I typeset my two technical books myself with Groff and I can tell you that a lot of effort goes into getting that page structure right.

John Wait, the legendary editor/publisher from Pearson Education, popped up in the comments to say that at InformIT they offer epub, MOBI, and PDF formats for their books and that PDF is the most requested format by far. Proprietary ebook readers, of course, want to lock you into whatever DRMed format they’re using and have little interest in providing PDFs. It’s companies like Pearson and O’Reilly that don’t have DRM that are giving technical readers the best experience by providing PDF versions of their books.

If you care about these sort of issues, the comments at the end of Evans-Ariyeh’s post are interesting. They explore some of the problems with PDFs and ebooks in general and are worth a look.

Posted in General | 1 Comment