And now it’s all this http://leancrew.com/all-this I just said what I said and it was wrong. Or was taken wrong. Thu, 23 Nov 2017 21:08:29 +0000 en-US hourly 1 http://wordpress.org/?v=4.0 Last thoughts on modifier keys http://leancrew.com/all-this/2017/11/last-thoughts-on-modifier-keys/ Thu, 23 Nov 2017 21:08:29 +0000 http://leancrew.com/all-this/2017/11/last-thoughts-on-modifier-keys/ ordering Mac modifier keys a few days ago, I was thinking primarily about the proper order of the symbols when writing about a keyboard shortcut, like ⌃⌥⌘P.1. I mentioned parenthetically that this order isn’t always observed when people speak about keyboard shortcuts or when they write the names of the keys out fully, as in “Command-Shift-3 takes a screenshot.”]]> When I wrote the post about ordering Mac modifier keys a few days ago, I was thinking primarily about the proper order of the symbols when writing about a keyboard shortcut, like ⌃⌥⌘P.1. I mentioned parenthetically that this order isn’t always observed when people speak about keyboard shortcuts or when they write the names of the keys out fully, as in “Command-Shift-3 takes a screenshot.”

Jason Snell, in both a post at Six Colors and in conversation with John Siracusa on the lastest episode of Upgrade, took a stand against Apple’s ordering:2

Command is the commander! Command is the monarch of all keys! Command always comes first, in my book.

Siracusa agreed, and so do I. The ⌘ key is, and has always been, the key that signals a keyboard shortcut. While other modifier keys are sometimes used without ⌘—in cursor control and text selection, for example—I can’t think of any Apple applications that don’t use ⌘ to signal a keyboard shortcut for a menu item. And that primacy in shortcuts to menu items is, I think, why Apple puts it last rather than first.

Keyboard shortcuts are always presented right-justified along the right edge of the menu. The most common shortcuts are just ⌘ and a letter, like ⌘N to start a new document, for example. It’s typically the variations on the basic command that get additional modifier keys, like ⌥⌘N to start a new project. If that were presented in a menu as ⌘⌥N, the menu would look wrong because the ⌘ symbols wouldn’t line up.

Here’s the File menu in Safari:

Safari File menu

There are two different New commands and three different Close commands. This, in Apple’s opinion (and mine), wouldn’t be right:

Altered Safari File menu

It’s not just having the ⌘ symbols aligned. The additional modifier symbols go in front because ⌘ is king and must sit next to the N or the W. The importance of the modifier decreases as you move away from the letter.

It should go without saying—but I’ll say it anyway—that the letter (or number or whatever) key is the most important because nothing happens until it’s pressed.

Having said all this, and despite agreeing with Apple’s symbol ordering, my ear for shortcut ordering works just like Jason’s and John’s. The main reason I use keyboard shortcut symbols in my posts instead of words is that I can read ⌥⇧⌘W and not be bothered because I don’t “hear” it as I read the symbols. “Option-Shift-Command-W,” on the other hand, gets sounded out in my head, and it sounds wrong.

I suspect that’s why Apple’s own documentation sometimes gets the order wrong when the modifiers get written out as words. In speaking out the keys, “Command” is natural to put first because it announces that what’s coming is a keyboard shortcut.


  1. Which happens to be the shortcut I use for previewing a blog post locally before publishing it. ↩︎

  2. In the original post, I said I didn’t know where the order was documented. A few people pointed me to both the Human Interface Guidelines and the Style Guide, where Apple gives the proper order explicitly. ↩︎


[If the formatting looks odd in your feed reader, visit the original article]

]]>
My next Mac http://leancrew.com/all-this/2017/11/my-next-mac/ Wed, 22 Nov 2017 22:04:57 +0000 http://leancrew.com/all-this/2017/11/my-next-mac/ Will probably be an iMac. I guess that spoils the suspense, doesn’t it?

My iMac at work is the 27″ Late 2012 model, the one that came out one step before Retina came to the iMac. I don’t regret buying it, as my previous iMac (a 2006 model, I think) was absolutely on its last legs—constantly swapping to hard disk and running hot. I hadn’t meant to wait so long to replace it, but there was a long delay before that 2012 model came out, and I didn’t want to buy something that would be last year’s model almost as soon as I set it up.

My home Mac is the venerable 2010 13″ MacBook Air, the first good Air. In the normal course of things, this would be the Mac I replace next, and I’ve been expecting to do so for a few years now. but…

But Apple never came out with a Retina MacBook Air, choosing instead to go with the MacBook, which I find a little too far on the portable side of the portability/power spectrum. A couple of years ago, I had a crisis when my Air crapped out on me. It seemed wrong to put money into a five-year-old machine, but I wasn’t enthused about any of the MacBooks in the lineup at the time. I didn’t know the just-released 2015 MacBook Pro would turn out to be the best laptop ever made, I didn’t want to spend MacBook Pro money on my home/travel machine.

The $280 logic board upgrade turned out to be a good investment, as I’m now 2½ years into my rejuvenated Air. Yes, it takes a while to wake up when I open the lid. Yes, its 128 GB SSD is tiny. No, it can’t take advantage of many of the iOS integration features that newer Macs can. And no, I don’t think it’s a good idea to install High Sierra on it. But it’s given me 30 months of faithful use, much more than I expected at the time.

The announcement of the Touch Bar last year made me certain I’d be getting a MacBook Pro with it. A software-configurable set of controls seemed perfect for someone who’s always ginning up little scripts. But no one seems to like it, possibly because its configurability isn’t especially open to users. Bummer.

I’ve delayed the decision on my home Mac for such a long time that now my office Mac is long in the tooth, too. Still working fine for most tasks, but just a Core 2 Duo machine that often makes me wait to scroll through long PDFs of scanned engineering and architectural drawings, something I need to do at work quite often. And no Retina.

So it looks like my best bet is to buy a new iMac for work and bring my current office iMac home. This will put the power where I need it the most and will give me extra ooomph here at home. Especially with disk space (3 TB vs. 128 GB) and RAM (24GB vs. 4GB).

It will be weird, though, as I haven’t had a desktop computer here at home in a dozen years. Will I enjoy being tethered to one spot in the house? And what about a travel computer?

Both of these questions are made less pressing by the device I’m typing this on: a 9.7″ iPad Pro. While I agree with Gabe that it is by no means a Mac substitute, it can handle a lot of what I do at home and virtually everything I need to do on the road.1

As for which iMac, I think I’ll settle on a middle-of-the-road 27″ configuration with a 3TB Fusion drive. Sort of the 2017 of what I bought in 2012.


  1. I bought the iPad Pro last year as a sort of experiment to find out how comfortable I’d be working on it. I intend to write a full post about the results of that experiment soon, but in the meantime, you really should read Gabe’s post over at Macdrifter. I’ll probably use his post as a jumping-off point. And there may be a quiz. ↩︎


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Modifier key order http://leancrew.com/all-this/2017/11/modifier-key-order/ Mon, 20 Nov 2017 02:22:59 +0000 http://leancrew.com/all-this/2017/11/modifier-key-order/ proper order for adjectives in English, there’s a proper order for listing the modifier keys in a shortcut.]]> If you write about Mac keyboard shortcuts, as I did yesterday, you should know how to do it right. Just as there’s a proper order for adjectives in English, there’s a proper order for listing the modifier keys in a shortcut.

I haven’t found any documentation for this, but Apple’s preferred order is clear in how they show the modifiers in menus and how they’re displayed in the Keyboard Shortcuts Setting.

Canonical Mac modifier key order

The order is similar to how you see them down at the bottom left of your keyboard.

Modifier keys

Control (⌃), Option (⌥), and Command (⌘) always go in that order. The oddball is the Shift(⇧) key, which sneaks in just in front of Command.

Keyboard Maestro recognizes this standard order and presents its “hot key” shortcut the same way.

Keyboard Maestro hot key field

(When people speak about keyboard shortcuts, it’s not uncommon to put Command first, e.g., “Command-Shift-3 takes a screenshot.” I’ve seen it written out that way, too. Apple is usually pretty careful to use the same order when using words as when using symbols. This page, for example, uses “Shift-Command-3,” to match the ⇧⌘3 you’d see in the Keyboard Shortcut Settings. But even Apple slips up. On the grand Mac keyboard shortcut page, there are a few instances of “Command-Shift” instead of “Shift-Command.”)

The last bit of standard syntax is that the letter key in the shortcut (if there is a letter) is always presented as a capital, even when the Shift key isn’t used. I suspect this was a serious topic of discussion at Bandley 3 back in the early 80s as the Mac was being developed. They got it right. When entering a keyboard shortcut, you’re not typing a letter, you’re pressing a set of physical keys on the keyboard in front of you. The symbols on the letter keys are capitals, so that’s the appropriate way to identify those keys.


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Command-E http://leancrew.com/all-this/2017/11/command-e/ Sun, 19 Nov 2017 02:02:50 +0000 http://leancrew.com/all-this/2017/11/command-e/ Earlier this evening, Merlin tweeted out some advice we should all heed:

Even though I’ve been using a Mac for 32 years (albeit with an 8-year Linux hiatus) there were a few keyboard shortcuts in there I didn’t know about. And, just as important, several that I once knew but had fallen out of the habit of using.

But one of my favorites—and a big convenience when writing code or prose—isn’t on the Mac keyboard shortcut page. I wonder if the folks at Apple have forgotten it.

It has to do with finding text in a document. You know about ⌘F to specify a Find. That usually brings up a window or other control into which you can type (or paste) the text you’re going to be searching for. Often, there are options for controlling how the search will be performed and for replacement text. Here’s the Find window from BBEdit,

BBEdit Find window

here’s the Find window from Pages,

Pages Find window

and here’s TextEdit, which pops up a little Find section in the main window below the ruler,

TextEdit with Find section

You probably also know about ⌘G, which is usually given the menu name Find Next. It repeats the last Find command, allowing you to step through all the occurrences of that text in the document. There are usually other ways to cycle through all the found instances—Pages and TextEdit have arrow buttons you can click on—but ⌘G is the traditional way.1

A common situation, especially when looking through long documents or source code files, is to see a particular string of text and want to find other instances of it. You may, for example, see the definition of a function and want to search out where that function gets called later in the code. One way to do that would be to select the function name, copy it, ⌘F to bring up the text entry field, paste, and then ⌘G your way through the rest of the document.2 But the copy/⌘F/paste dance is a little clumsy.

Which is where ⌘E, which is typically given a menu name like Use Selection for Find, comes in.

BBEdit Search menu

Select the text you want to search for and hit ⌘E. That turns the selection into the search text, and you can go straight to ⌘G to walk through all the other occurrences.

I use ⌘E all the time when searching through code for function and variable names, as in the example above. It also works in Safari, Chrome, Preview, and PDF Expert, so I do similar quick searching on words I come across as I read news articles, blogs, reports, papers, etc.

⌘E works in other well-behaved applications, too, so you should give it a try. Note that “well-behaved applications” excludes MS Word. In Word, ⌘E centers the paragraph of text containing the selection. Of course.

Update Nov 19, 2017 8:40 AM
A couple of things I forgot to include:

First, ⌘E in the Finder has, somewhat ironically, no relationship to finding. It ejects or unmounts the selected disk, assuming there is a selected disk. This shortcut is listed on Apple’s Mac shortcut page (which is why I was going to mention it), and a couple of people reminded me of it after the post was published. I guess I forgot about it because it’s a command I never use; I eject by right-clicking and selecting Eject from the menu that pops up.

Second, editors and word processors on iOS have not inherited this useful shortcut from the Mac. There is, of course, no ⌘ key on the software keyboard, but many of the traditional Mac shortcuts that use ⌘, ⌥, and ⇧ for moving the cursor and selecting text do work on iOS when you use an external keyboard. ⌘F and ⌘G (and its backward cousin, ⇧⌘G) often work in iOS, too, but ⌘E didn’t make the cut. Too bad.

Keyboard shortcuts in iOS Notes


  1. I believe ⌘G was originally used as the shortcut for Go To Page… in MacWrite, but it’s been Find Next for ages. 

  2. Yes, source code editors in general, and BBEdit in particular, have other ways to find all the instances of a string of text, and those ways may be more appropriate in some situations. But stepping your way through each instance in turn is often the best way to see the string in full context. 


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Converting fractions to decimal values http://leancrew.com/all-this/2017/11/converting-fractions-to-decimal-values/ Mon, 13 Nov 2017 04:35:39 +0000 http://leancrew.com/all-this/2017/11/converting-fractions-to-decimal-values/ Recently, I’ve been getting Excel spreadsheets from clients that contain measurements in inches and/or fractions of an inch. In some cases, the cells with these measurements actually contain numbers but are displayed as fractions using one of the many formatting options Excel has.

Excel cell formatting options

In these cases, it’s easy for me to change the formatting to a standard decimal representation before exporting the sheet as a CSV file.

Often, though, the measurements are entered as text. This is done by prefixing the data with a single quote mark, e.g.,

'2 5/16

or maybe

'2-5/16

These need to be converted into a decimal representation before exporting to CSV, so Pandas will recognize them as numbers rather than strings.1

To handle this situation, I created a Keyboard Maestro called Floatize. To use Floatize, I

  • Select the column of data I want to convert.
  • Copy it to the clipboard.
  • Run Floatize, which converts the clipboard from a fractional representation to decimal.
  • Paste the result back into the column.

Here’s the macro:

Floatize Keyboard Maestro macro

It takes the clipboard, sends it to a script as standard input, and then puts the output back into the clipboard. Here’s the Python script it runs:

python:
 1:  #!/usr/bin/env python
 2:  
 3:  from fractions import Fraction
 4:  import re
 5:  import sys
 6:  
 7:  def floatize(s):  
 8:    if s in ['', 'n/a', 'none']:
 9:      return ''
10:    else:
11:      try:
12:        num = float(s)
13:      except ValueError:
14:        t = re.sub(r'(.*\d) *- *(\d.*)', r'\1 \2', s)
15:        if t[0] == '-':
16:          num = -float(sum(Fraction(x) for x in t[1:].split(None, 1)))
17:        else:
18:          num = float(sum(Fraction(x) for x in t.split(None, 1)))
19:      return "{:f}".format(num)
20:    
21:  for line in sys.stdin.read().splitlines():
22:    item = line.strip().lower()
23:    print floatize(item)

The bulk of the fraction parsing is done by the fractions module in either Line 16 or Line 18. The rest of the script is an attempt to manipulate the oddball types of data I get into a format that fractions understands. Here’s what it can handle:

  • Blank, n/a or none entries get turned into an empty string (Lines 8–9). Note that entries are converted to lower case in Line 22, before being passed to the floatize function, so this handles N/A and None, too.
  • Entries already in decimal format get converted to a float (Line 12) and then output in decimal format (Line 19). This is basically a pass-through.
  • Entries with a dash between the whole and fractional parts get the dash removed (Line 14).
  • Negative entries (Line 15) have their whole and fractional parts added together with the sign reversed (Line 16), and then output in decimal format (Line 19).
  • Positive entries have their whole and fractional parts added together (Line 18), and then output in decimal format (Line 19).
  • Entries that don’t look like any of the above cause an error.

The macro works perfectly in Numbers and BBEdit, but not in Excel. For some reason, nothing happens to the clipboard if I run the Floatize macro while Excel is the active application. I can, however, copy the column of fractions, activate another app, run Floatize, switch back to Excel and paste the converted clipboard. Another example of Excel not acting like a proper Mac app and another reason I move data out of Excel as quickly as I can.

Despite its inability to work inside Excel, this macro has been very handy over the past couple of weeks. I’ve used it to clean up several data sets that were loaded with fractions.

By the way, I will block anyone who tweets that I wouldn’t have this problem if I used the metric system.

Update Nov 13, 2017 10:04 PM  The Twitter consensus is my problem in using this macro in Excel stems from Excel’s clipboard dumbassery. It apparently uses a private clipboard instead of the system clipboard until you bring another application to the front. Hence the macro’s inability to convert the clipboard unless I switched away from Excel.

Jimmy Hartington suggested this workaround:

@drdrang Excel does something weird with the clipboard as you noticed.
Try this. Copy in Excel. Press Escape. Run the macro.
By pressing Escape I think Excel stops messing with the clipboard.
Jimmy Hartington (@jimmyhartington) Nov 12 2017 11:06 PM

This works perfectly and pointed me in the direction to make a better version of the macro, one that does all the copying, converting, and pasting:

New Floatize Keyboard Maestro macro

Note the conditional action that simulates the pressing of the Escape key only if Excel is the front application. This is necessary because Escape causes Numbers to deselect the column, which screws up the paste action at the end of the macro.

With this macro I can now select the column that needs converting and just press ⌃⌥⌘F to do the conversion in a single step. Thanks, Jimmy!


  1. There are probably ways to get Pandas to do the conversion as it imports the data, but I feel more comfortable—more in control—if I do it ahead of time. ↩︎


[If the formatting looks odd in your feed reader, visit the original article]

]]>
A modest proposal http://leancrew.com/all-this/2017/11/a-modest-proposal/ Tue, 07 Nov 2017 03:27:11 +0000 http://leancrew.com/all-this/2017/11/a-modest-proposal/ on my mind, I’d like to make a small complaint and suggestion to the folks at MacStories: some of your quarterly graphs could use a little scrubbing; they’d be much easier on the eyes if they were cleaned up a bit.]]> With Apple sales and graphing on my mind, I’d like to make a small complaint and suggestion to the folks at MacStories: some of your quarterly graphs could use a little scrubbing; they’d be much easier on the eyes if they were cleaned up a bit.

I’m talking about the ones that look like this:

MacStories unit sales graph

My complaint is with the clutter along the x-axis. That uniform gray mass of text detracts from the data above it. And although putting a label at each quarter seems to provide more information to the reader, the reader actually gets less out of it because it’s too hard to read. The axis would be improved if it had just yearly Q1 labels. Maybe even one label every other year. Fewer labels would mean they could be turned back horizontal, which would be easier to read and would give more vertical space for the data.

I suspect every data point is labeled because that’s the way Numbers wants to do it, and MacStories’ automated system for generating these graphs follows the Numbers defaults. But if you were making these graphs by hand, you’d never label the x-axis this way. An automated system shouldn’t, either.

On the Mac, Numbers has a way to skip labels on the x-axis by selecting Custom Category Intervals from the Category Labels popup menu and then choosing how often to put the labels.

Mac Numbers axis options

Sadly, I can’t find that option in the iOS version. Maybe it’s tucked away in a less obvious place.

iOS Numbers axis options

Personally, I’m not a fan of either version of Numbers when it comes to making graphs because I like way more control than they give. But Numbers (like most graphing programs and libraries) can make nice graphs if you’re willing to break away from its defaults.

I don’t really want to pick on MacStories. Their graphs are as good as, if not better than, what you typically find in blogs and news sites. Most graphs, unfortunately, are based on the default settings of the software that made them, and come out looking a little clumsy.

I read MacStories because it has stylish writing. I’d like its graphs to be just as stylish.

Update Nov 7, 2017 8:55 PM
I was informed on Twitter by two authoritative sources (this one and this one) that the MacStories graphs are made with Excel, not Numbers. I haven’t used Excel for graphing since the mid-90s, but even then it had more customization options than Numbers has now. So I’m crossing my fingers for cleaner x-axes in January’s graphs.


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Apple sales graphs and the iPhone 7 http://leancrew.com/all-this/2017/11/apple-sales-graphs-and-the-iphone-7/ Mon, 06 Nov 2017 02:53:19 +0000 http://leancrew.com/all-this/2017/11/apple-sales-graphs-and-the-iphone-7/ sales and revenue figures, which means a boatload of graphs from all your fave rave Apple-oriented bloggers. I’m a few days late, as usual, despite having long ago written scripts to generate these graphs.]]> Last week Apple released its 2017 Q4 (which everyone else’s calendar says is 2017 Q3) sales and revenue figures, which means a boatload of graphs from all your fave rave Apple-oriented bloggers. I’m a few days late, as usual, despite having long ago written scripts to generate these graphs.

I don’t make as many graphs as everyone else, partly because I’m lazy, but mainly because don’t care about revenue. My concern is the popularity of the devices I use, not how expensive they are. I want third-party developers to keep writing apps for them, and that means there has to be a market for them out there.

Here’s the summary graph, with the sales figures for the three main Apple products. The dots are the quarterly sales and the lines are the four-quarter moving averages.

Apple sales

The iPhone dominates the scale of this graphs, so it’s helpful to also see the iPad and Mac on their own graphs.

iPad sales

Mac sales

The good news is the second straight quarter of year-over-year increase in iPad sales after its long, well-documented slide since 2013. Additional good news is the Mac’s slow but consistent rise over the past year—four straight quarters of year-over-year sales increases. Imagine how much better the figures would be if people really liked the Touch Bar.

I think its fair to say, though, that the iPhone 7 was something of a dud. It had a good start, but its non-intro quarters had almost exactly the same sales as the 6S had. Look at the final three quarters of each.

Apple sales annotated

As I’ve argued before, the iPhone 6S sales looked lackluster only in comparison to the gangbusters popularity of the iPhone 6. If one ignored the year of the 6, the 6S’s sales were more or less on the same upward trend as the previous three editions. The iPhone 7 was on that same trend for its first quarter but went dead flat after that.

Apple’s report in January will be very interesting.


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Another one-off Keyboard Maestro macro http://leancrew.com/all-this/2017/11/another-one-off-keyboard-maestro-macro/ Fri, 03 Nov 2017 02:02:41 +0000 http://leancrew.com/all-this/2017/11/another-one-off-keyboard-maestro-macro/ Do you use Keyboard Maestro (or AppleScript or whatever) for one-time, throwaway macros as often as you should? I know I don’t, but I did put one together a couple of days ago and used a feature I’d never tried before.

I had one of those recalcitrant PDFs that I often get from clients. This one was 25–30 pages long, each an E-sized floor plan drawing for a building. The drawings were all black-and-white, but the PDF had color annotations added. I needed to add my own annotations to most of the pages, but something about the format of the file made it very cumbersome to work with. I tried Preview, PDF Expert, and PDfpen Pro, and they all were glacially slow when panning, zooming, and switching pages.

So I broke the file up into individual pages using PDFtk:

pdftk drawings.pdf burst

The single-page files didn’t make me wait for the spinning beach ball, so I was able to add my annotations quickly in PDF Expert. Then came an impasse.

I wanted to email the drawings with my annotations back to the client and to some other parties, but they were too big to fit in an email. I could use multiple emails, but that’s a recipe for losing some of the files. I could use a Dropbox link, but I had a sense that one of the other parties wouldn’t understand how that worked. What seemed best was to convert the files to JPEGs at the lowest legible resolution, zip them together, and send the zipped file in a single email.1

My normal practice would be to use sips for this, because I can issue a single command to convert any number of files. But I soon learned that sips doesn’t handle annotations properly when converting the format of a file from PDF to JPEG. In my brief testing, I found that neither my annotations or the ones that came from the client were visible in the converted JPEGs.

Preview, though, can export a PDF as a JPEG with the annotations intact and visible. Which presumably means that sips and Preview are using different code bases for the conversion. Whatever.

The problem with using Preview is I’d have to convert every file by hand. Not the most burdensome job I’ve ever had, but one that’s boring and susceptible to error. Enter Keyboard Maestro.

Here’s the macro that exports the current file in Preview to a JPEG and closes it:

Convert to JPEG macro

You’ll note there’s no step for setting the resolution for the exported file. That’s because once it’s set, it doesn’t change from one export to the next.

I didn’t try to have the macro open each PDF in turn, because I didn’t trust myself to do that right. I just opened all of them and then ran the macro by pressing ⌃⌥⌘J repeatedly. The macro closed each file after exporting it, leaving the next window ready to be operated on.

The new (for me) thing with this macro was the “and drag to” part at the bottom of the third step. That’s what moved the popup menu selection from PDF up to JPEG.

Preview export sheet

I figured out how much to drag by taking a screenshot like the one above and using a selection in Acorn to measure the vertical distance from the center of PDF to the center of JPEG. No trial and error.

With 25–30 files to convert, it’s possible I did save time with this macro. But the main reason I made it was to avoid the tedium and the likelihood of error on my part. These are not independent—I’m far more prone to make errors when the task is repetitive and doesn’t maintain my attention.


  1. No, a Dropbox link is really no more complicated than a zip file, but zip files are more familiar to more people. And although zipping JPEGs doesn’t make them smaller, it does package them up in a way that naive Windows users are usually comfortable with. It would be lovely if I always worked with people whose computer skills were trustworthy, but that’s not the world I live in. ↩︎


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Binomial baseball http://leancrew.com/all-this/2017/10/binomial-baseball/ Mon, 30 Oct 2017 18:14:47 +0000 http://leancrew.com/all-this/2017/10/binomial-baseball/ While reading a recap of last night’s World Series games, I saw this statistic: of the 65 Series that have had a sixth game, the team with the 3–2 lead has won the Series 43 times. This was, I think, intended to show us that the Astros have a strong chance to beat out the Dodgers for the title. And they do. But not as strong as you might expect.

If the teams were evenly balanced and each game independent of the others, we would expect the team with the 3–2 lead to win 75% of the time. 50% of the time they’d win the sixth game and the Series would be over; 25% of the time (50% of the other 50%) they’d win in the seventh game. So the leading team “should” have won the Series 48 or 49 times out of 65, not 43 times.

Is this 5 or 6 game difference meaningful? For that we need to do some calculations using the binomial distribution. Python’s SciPy set of libraries has a subsection of statistical modules, including one for binomial distribution calculations. We can import it this way:

python:
from scipy.stats import binom

Let’s start by figuring out the probability that the leading team would win 43 times in 65 trials. With a 75% probability of winning the Series in each trial, the probability of 43 Series wins in 65 chances is calculated through

python:
binom.pmf(43, 65, .75)

where the pmf function gets its name from the standard abbreviation for “probability mass function.” The answer is 0.029 or just under 3%. This makes it seem very unlikely that our assumption of 50–50 games would lead to only 43 Series wins for the leading team.

But that isn’t the way these sorts of calculations are normally done. If we want to find out if a seemingly out-of-whack result is “statistically significant,” we should look at the probability of results that are at least as far away from our expectations as the actual result was. In our case, that means looking not only at the probability of 43 Series wins out of 65 chances, but also 42 wins, 41 wins, and so on. We then add up all of these “at least as weird” probabilities.

The usual terminology for this sort of summation is “cumulative distribution function,” and the binom module has a function for it:

python:
binom.cdf(43, 65, .75)

The result is 0.0695, or about 7%. Another way of looking at this is that if our assumption of 50–50 games were correct, there’s a 93% chance that the leading team would win the Series more than 43 times in 65 chances.

In hypothesis testing, the value 0.0695 is called the p-value, and it’s common in many fields to consider a result statistically significant if its p-value is less than 0.05. Using that criterion, we would not take the difference between our “null hypothesis” of 50–50 games and the World Series history as statistically significant.1

But it’s something for Dodgers fans to cling to.


  1. Yes, I’ve been a little breezy here with my definition of null and alternate hypotheses and one-sided vs. two-sided rejection areas, but it’s just baseball. ↩︎


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Judas http://leancrew.com/all-this/2017/10/judas/ Sat, 28 Oct 2017 14:33:47 +0000 http://leancrew.com/all-this/2017/10/judas/ Shadows in the Night and Fallen Angels, were strong clues that I was going to be seeing a Bob Dylan infected by the Great American Songbook.]]> I can’t say I wasn’t warned. The concert’s promotional artwork (especially those fonts) and the previous two albums, Shadows in the Night and Fallen Angels, were strong clues that I was going to be seeing a Bob Dylan infected by the Great American Songbook.

Dylan concert promo

So yes, we got “Melancholy Mood” and “Autumn Leaves” and “The September of My Years” with Bob crooning into a big microphone and holding its stand at a jaunty angle. But that’s not what I disliked about the concert. In fact, those songs were done pretty well, and Dylan’s voice sounded better than any previous concert I’ve been to. It was what he did to his own songs that was frustrating.

No one in his right mind goes to a Dylan concert expecting to hear his classics played or sung the way they were done originally. But the treatment they’re given is always interesting and usually fun. Not this time. Apart from “It Ain’t Me, Babe” and “Highway 61 Revisited,” the Dylan songs suffered from arrangements that were, I guess, meant to match the style of the non-Dylan songs. Under these conditions, you can’t expect the songs to rock, but you can expect them to swing. And the band just didn’t swing.

There was a sameness to Charlie Sexton’s guitar work throughout the night. Despite changing instruments several times, his sound was constrained and repetitive. But when a band doesn’t swing, it’s mainly because of the rhythm section. These are talented musicians who can play in any style, so if they didn’t find a groove it must have been because Bob didn’t want them to.

As a result, he lost the audience. Many left early and those who hung in there stayed glued to their seats until the encores. Can you imagine a Dylan audience not standing to “Tangled Up in Blue”?

The optimist in me notes that Dylan never sticks with anything for long, and after two albums of standards he may be ready for the next thing. I hope he comes back to the notion that that it’s his songs, and the blues and country/folk they came out of, that are truly the Great American Songbook and gives them the treatment they deserve.


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Icons http://leancrew.com/all-this/2017/10/icons/ Fri, 27 Oct 2017 01:39:06 +0000 http://leancrew.com/all-this/2017/10/icons/ Brett Terpstra’s iTunesIcon Automator app, which just got an update.]]> I have some code sitting around here somewhere for extracting the images (app icons, book covers, album art, etc.) from the various iTunes and App Stores. But I think it’ll be easier to use Brett Terpstra’s iTunesIcon Automator app, which just got an update.

Apart from its appeal to my laziness, Brett’s little app has a cool icon that I took an instant liking to.

iTunesIcon icon

If you work around industrial and construction equipment, Brett’s icon should bring a smile of familiarity. It’s highly reminiscent of the hands in safety signs and decals that are in dire straits.

Safety symbols

Images from SafetySign.com

I’m sure your fingers are safe when using iTunesIcon.


[If the formatting looks odd in your feed reader, visit the original article]

]]>
Feed reading http://leancrew.com/all-this/2017/10/feed-reading/ Mon, 23 Oct 2017 00:10:42 +0000 http://leancrew.com/all-this/2017/10/feed-reading/ a nice article today on how he uses Feedbin to handle his reading on the web. If you follow Gabe—and if not, why don’t you?—it will not surprise you to learn that he’s formidably organized. I don’t see myself following in his footsteps, but it’s always useful to learn how smart people do things. His article also reminded me that I’ve been meaning to write about my feed reading setup.]]> Gabe Weatherhead has a nice article today on how he uses Feedbin to handle his reading on the web. If you follow Gabe—and if not, why don’t you?—it will not surprise you to learn that he’s formidably organized. I don’t see myself following in his footsteps, but it’s always useful to learn how smart people do things. His article also reminded me that I’ve been meaning to write about my feed reading setup.

A couple of years ago, I let my subscription to Feed Wrangler lapse and started using a homemade, web-based RSS reading system. The heart of the system is still the script described in this post, but with a some changes as I thought of better ways of doing things.

The biggest change came in the past few months. Initially, I created a single static web page with all of today’s articles from the feeds I subscribe to. A cron task updated the page a few times an hour throughout the day. In this system, “today” was defined as “from 10:00 pm last night until now,” and the page would grow in size from morning to night.

The advantage of this temporal arrangement from a programming point of view was that I didn’t have to write any code to keep track of whether I’d already read an article or not, and there were no external dependencies. If it was published “today,” it got on the page.

The disadvantage was from the reading point of view. As I visited the page throughout the day, it became more and more filled with article I’d already read. This wasn’t as terrible as you might think. The articles were arranged in reverse chronological order by publication time, so the ones I’d read were typically at the bottom of the page. I say “typically” because some feeds—XKCD comes to mind—are very bad at providing accurate publication times and their articles would sometimes end up at the bottom despite being recently published.

Eliminating the reading disadvantage meant keeping track of what I’d read and showing only what I hadn’t—eliminating the programming advantage. I decided to keep track of read articles in an SQLite database and to add items to that database through a button placed at the bottom of each article on my RSS page.

RSS buttons

This meant

  1. Building a database that would uniquely identify every article. This was pretty simple. Each record has just two fields: the name of the website and the unique article ID (which is often just the article’s URL but is sometimes a long alphanumeric string generated by the site’s blogging software).
  2. Altering the existing script that builds the RSS page to filter out feed items that are in the database. Because Python has an SQLite module as part of its standard library and the syntax of SQL commands is straightforward, this wasn’t as tricky as I thought it would be. In fact, the new code is easier to read than the time-based filtering code I removed.
  3. Writing a server script (basically just a CGI script) to add an article to the database when given the blog name and article ID via the POST method. It’s been a while since I last wrote a CGI script, but it was like riding a bicycle.
  4. Adding some JavaScript with XMLHttpRequest to the RSS page to call the server script when a button is pressed. This took the most time, mainly because everyone in the world (except me) knows how to do AJAX now, and finding references written at an appropriately low level was harder than I expected. I found this Stack Overflow discussion helpful.

So now I usually tap the Mark as read button when I get to the end of an article. If it’s a long article that I want to read later, I don’t mark it as read, and it’ll be there the next time I bring up the RSS page.

Fearing I’d forget how to use XMLHttpRequest, I quickly included another form at the end of each article for adding that article to my Pinboard account. I didn’t bother adding labels to the text field, because I’m the only one who uses this and I know the field is for tags. I did, however, include some DOM stuff to make it obvious when I’d marked an article as read or added it to Pinboard.

RSS buttons marked

What I like about this system is how portable and (I hope) future-proof it is. I’ve been reluctant to sign on with Feedbin or Feedly or BazQux or any of the other Google Reader replacements because I worry they’ll write a Medium post and disappear with my subscription list and whatever organization scheme I’ve created. My system can run on any web server with Python, SQLite, and a cgi-bin directory. I think that’ll mean “any server, anywhere” for a very long time.


[If the formatting looks odd in your feed reader, visit the original article]

]]>