Posts Tagged ‘simplenote’

New Metra schedule for Simplenote

As I mentioned last November, I have plain text versions of the Metra commuter rail schedule between Chicago and Naperville (where I live) saved in Simplenote. Metra made some changes to the schedule this week, so I updated and decided to make the files available in a GitHub repository.

On the iPhone, the schedules look like this:

Because Simplenote uses Helvetica, a proportional font, and doesn’t have adjustable tab stops (even if it did, there’s no tab key on the iPhone for entering them), the columns don’t line up perfectly, but they look OK. Until the iPhone gets a decent monospaced font, this will have to do.

There are six schedule files in the repository:

  1. Eastbound Monday through Friday
  2. Eastbound Saturday
  3. Eastbound Sunday
  4. Westbound Monday through Friday
  5. Westbound Saturday
  6. Westbound Sunday

Also in the repository is a Python script, metra.py, that I wrote to reformat the schedule times from the way they’re presented on the Metra web page.

I copy the schedule times from the box and paste them into a text editor. Generally, I get something that looks like this,

  08:40  10:40  12:40  02:40  04:40  06:40  08:40  10:40  12:40
Naperville  09:37  11:37  01:37  03:37  05:37  07:37  09:37  11:37  01:37

which some extra stuff at the beginning of each line that needs to be deleted to make it look like this:

08:40  10:40  12:40  02:40  04:40  06:40  08:40  10:40  12:40
09:37  11:37  01:37  03:37  05:37  07:37  09:37  11:37  01:37

Then I copy those lines and execute

pbpaste | python metra.py | pbcopy

which puts the reformatted schedule,

  8:40a            9:37a
10:40a          11:37a
12:40p            1:37p
  2:40p            3:37p
  4:40p            5:37p
  6:40p            7:37p
  8:40p            9:37p
10:40p          11:37p
12:40a            1:37a

onto the clipboard. It looks weird here, but that’s because you’re seeing it in a monospaced font, not Helvetica. Finally, I paste the times into the Simplenote webapp and do some minor editing. This usually consists of

Here’s metra.py:

 1:  #!/usr/bin/python
 2:  
 3:  import re
 4:  import sys
 5:  
 6:  # Collect the two rows of data.
 7:  start = sys.stdin.readline().split()
 8:  stop = sys.stdin.readline().split()
 9:  
10:  # Change leading zeros to two spaces.
11:  start = [re.sub(r'^0', '  ', s) for s in start]
12:  stop = [re.sub(r'^0', '  ', s) for s in stop]
13:  
14:  # Print the data as two columns, using a simple heuristic for am/pm.
15:  ap = 'a'
16:  for i in range(0, len(start)):
17:    if start[i][0:2] == '12':
18:      if ap == 'a':
19:        ap = 'p'
20:      else:
21:        ap = 'a'
22:    
23:    print ' %s%s          %s%s' % (start[i], ap, stop[i], ap)

The AM/PM test is in Lines 17-21. This works pretty well for the Naperville-Chicago schedule and would probably be OK for other schedules, too. I thought about writing a routine that would work in every case, but it just wasn’t worth the effort. With this simple test, I only had to change a few as and ps.

If you’re a Simplenote user who lives in Naperville, the schedule files are pretty handy as is. If you’re a Simplenote user who lives in another town on the Chicago-Aurora line, or on another Metra line entirely, you can use metra.py to create your own Simplenote files.

If you’re not a Simplenote user, you should give it a try. It may be that Jesse Grosjean’s Dropbox-syncing suite of programs will end up working more smoothly, but until that happens, Simplenote is leading the pack.


Lipoproteins and Simplenote

Has this ever happened to you? You’re at a party and head into the kitchen for a snack. The room is filled with hot babes who surround you and…ask you about your cholesterol numbers. If it hasn’t, that’s probably because you haven’t reached middle age.

Cholesterol is slowly turning into a standard topic of conversation in my social group. The husbands are reaching the age where their doctors are telling them to alter their diets or take medication, and the wives are acting as enforcers. It’s common knowledge among this group that I’m using a statin drug (Simvastatin, which is the generic version of Zocor), so I often get asked about its effects and side effects.

Until recently, my cholesterol numbers were on a page in my daily planner, scribbled down while a nurse dictated them to me over the phone after my last test. This was not a very convenient place, so I typed them up in Simplenote. Now that they’re on my iPhone—and backed up on the web—I can whip out my numbers any time, anywhere. Impresses the hell out of the chicks.

At the end of the note with my test results, I added these tables with the current American Heart Association cholesterol guidelines1 and formatted them to fit nicely on a Simplenote page.

Here’s the text of the guidelines.

Total                       Category
< 200                       Desirable
200 - 239                   Borderline high
≥ 240                       High

Triglycerides            Category
< 150                        Normal
150 - 199                  Borderline high
200 - 499                  High
≥ 500                        Very high

HDL                       Category
≥ 60                        High; Optimal;
                                helps to lower
                                risk of heart
                                disease
< 40 in men and      Low; considered
< 50 in women          a risk factor
                                for heart disease

LDL                        Category
< 100                       Optimal
100 - 129                 Near optimal
130 - 159                 Borderline high
160 - 189                 High
≥ 190                       Very high

It looks crappy in a monospaced font, but lines up pretty well in Helvetica on the iPhone.

As you see, it includes the guidelines for total cholesterol, triglycerides, HDL, and LDL. Nobody seems to care about VLDL; it’s the Zeppo Marx of cholesterol.

Feel free to copy this info and take it with you to your next party. You’ll be a big hit with the MILFs.


  1. I used the tables at WebMD because their formatting made them easy to cut and paste into Simplenote. The numbers at the American Heart Association are the same. 


Exploring the Simplenote API

I’ve been meaning to work with the Simplenote API ever since it was announced, thinking it would be a good way to keep my plain-text todo lists1 synced between my computers and my iPhone. I haven’t done any syncing yet, but I have written a utility script that will get me started.

There are, as you may know, already several ways to sync your Simplenotes. Most of them, unfortunately, are tied to special note-taking apps that I don’t want install. One, Fletcher Penney’s SimplenoteSync, is more general, but works by syncing all the notes to a set of files in a single directory on your local computer. I’m looking for something a little more fine-grained than that—a way of syncing individual notes to individual files that can be anywhere on my computer.

As a first step, I wrote the following script, simplenote-index, which gathers and prints out information for all the notes on the Simplenote server.

 1:  #!/usr/bin/python
 2:  
 3:  from urllib import urlopen        # standard Python library
 4:  from base64 import b64encode      # standard Python library
 5:  import simplejson                 # http://code.google.com/p/simplejson/
 6:  
 7:  # Login credentials.
 8:  email = 'someone@example.com'
 9:  password = 'seekret'
10:  
11:  # Get my authorization token for later calls.
12:  loginURL = 'https://simple-note.appspot.com/api/login'
13:  creds = b64encode('email=%s&password=%s' % (email, password))
14:  login = urlopen(loginURL, creds)
15:  token = login.readline().rstrip()
16:  login.close()
17:  
18:  # Get the note index.
19:  indexURL = 'https://simple-note.appspot.com/api/index?auth=%s&email=%s' % (token, email)
20:  index = urlopen(indexURL)
21:  noteList = simplejson.load(index)
22:  
23:  # Print the first line of each note along with its key.
24:  baseURL = 'https://simple-note.appspot.com/api/note?key=%s&auth=%s&email=%s'
25:  for i in noteList:
26:    noteURL = baseURL % (i['key'], token, email)
27:    title = urlopen(noteURL).readline().decode('utf-8').rstrip()[:40]
28:    print '''Title:    %s
29:  Key:      %s
30:  Modified: %s
31:  Deleted:  %s
32:  ''' % (title, i['key'], i['modify'], i['deleted'])

I think the comments explain it pretty well; there’s not much to it. It logs in, gets an authorization token, then collects the information on each of your notes on the server. Here’s the sort of output to expect:

Title:    Hardware store
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRiF5BsM
Modified: 2009-09-08 00:24:13
Deleted:  False

Title:    Metra Eastbound Mon-Fri
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRij5h4M
Modified: 2010-01-01 17:51:59
Deleted:  False

Title:    Metra Eastbound Saturday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjC3h4M
Modified: 2010-01-01 17:52:33
Deleted:  False

Title:    Metra Eastbound Sunday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRi35h4M
Modified: 2010-01-01 17:52:46
Deleted:  False

Title:    Metra Westbound Mon-Fri
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRik5h4M
Modified: 2010-01-01 17:53:05
Deleted:  False

Title:    Metra Westbound Saturday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjL3h4M
Modified: 2010-01-01 17:53:20
Deleted:  False

Title:    Metra Westbound Sunday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjT3h4M
Modified: 2010-01-01 17:53:37
Deleted:  False

Title:    Swimming City Times 2009
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRiG5BsM
Modified: 2010-01-01 17:54:33
Deleted:  False

Title:    Swimming Meet Event Order
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRiH5BsM
Modified: 2010-01-01 17:54:59
Deleted:  False

Title:    Weight
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRiTii8M
Modified: 2010-01-20 12:35:52.611425
Deleted:  False

Like Simplenote itself, the script treats the first line of each note as its title (the script prints only the first 40 characters of the title so the formatting doesn’t get screwed up). The important thing for the work I intend to do later are the keys. These are character strings that uniquely identify each note and are essential for scripts that read and write notes. The goal of simplenote-index is to give me those keys so I can hard-wire them into my syncing scripts.

With lots of notes, simplenote-index will give lots of output. Grep is a great way to filter the output down to a reasonable level. For example,

simplenote-index | grep -i -A 3 metra

will give me just the notes with the local train schedule

Title:    Metra Eastbound Mon-Fri
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRij5h4M
Modified: 2010-01-01 17:51:59
Deleted:  False
--
Title:    Metra Eastbound Saturday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjC3h4M
Modified: 2010-01-01 17:52:33
Deleted:  False
--
Title:    Metra Eastbound Sunday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRi35h4M
Modified: 2010-01-01 17:52:46
Deleted:  False
--
Title:    Metra Westbound Mon-Fri
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRik5h4M
Modified: 2010-01-01 17:53:05
Deleted:  False
--
Title:    Metra Westbound Saturday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjL3h4M
Modified: 2010-01-01 17:53:20
Deleted:  False
--
Title:    Metra Westbound Sunday
Key:      agtzaW1wbGUtbm90ZXIMCxIETm90ZRjT3h4M
Modified: 2010-01-01 17:53:37
Deleted:  False

The -i option to grep makes the search case-insensitive, and the -A 3 option prints not only the line containing the search string, but the three lines after it as well.

With this easy one under my belt, I can start working on the more complicated syncing scripts.


  1. No, I don’t use OmniFocus anymore. It was just too much work for the good I got out of it. I’m back to my TextMate-based LGTD system, which I’ve updated a bit and really should do a short post on. 


Simple thanks

Like many people, I first learned of Simplenote through John Gruber’s Daring Fireball post from last summer. I bought the app and liked it from the beginning, even though it had some user interface problems. Using Simplenote paid off yesterday, when I became one of the WhySimplenote contest winners. (Twitter links to these two posts were my entries.)

Winners got a $30 iTunes gift card, which I’ll put to use immediately, and an upgrade to Premium service, which may give me the kick in the pants I need to start work on the syncing script I’ve had in mind ever since the Simplenote API came out. Thanks, Cloud Factory!

My favorite part of the winners announcement was the descriptions of what the other winners were doing with Simplenote. I was particularly taken with Andrew’s entry:

In my college share room, there’s five of us, but it’s my job to get the groceries. Each of us have access to the online component of Simplenote.

Whenever someone remembers something we/they need from the shops (often while daydreaming in lectures), they just type it onto the web app from their laptop.

Then, when I’m at the shops, I just take out my iPhone to look at the collaborative shopping list that’s been generated over the week. I never forget to get anything since I have a list, everyone has everything they need for the week, and there’s minimal stress since everyone can do it in their own time - not when I’m going out the door shouting to ask whether anyone needs anything.

Works great.

This is something I never would have thought of, but it fits Simplenote perfectly. Makes me sure there are more clever uses that I’m missing.


Simplenote, TextExpander, and the scale

Losing weight was not going to be one of my New Year’s resolutions. I just wanted to keep myself from gaining weight over the winter when I can’t ride my bike to and from work. But when I got on the scale a few weeks ago and found myself grazing the 200-pound mark, I knew that I’d already failed at keeping my weight steady and needed to start losing.

There are as many weight loss strategies as there are dieters. My plan is to simply think more carefully about what and how much I eat, and let the scale tell me how well I’m doing. I know that many people are dead set against weighing themselves every day; their theory being that your day-to-day weight fluctuation is too noisy to be a good measure of your progress. But for me, going a few days between weighings is just a license to lie to myself about my intake. I’m going to weigh myself every day and record it to keep myself honest.

I will not, as a general rule, be making the results public. I won’t be putting my weight up in the sidebar of the blog, nor will I set up a Twitter account for my weight as Leo Laporte has.1 This is not about shaming myself into losing; it’s about me keeping score for myself.

I’ll be using my iPhone to keep track of my weight. This is not just some nerdy love of technology, the phone is my most practical recording device. I keep my phone in the bathroom overnight to have it ready when I get dressed in the morning, so it’s already right where the scale is. And, like my car keys, my phone is something I have to pick up and pocket every morning. If I’m going to establish a habit of recording my weight, doing it on the iPhone seems like the easiest way to do it.

I’m sure there are dozens of iPhone apps that will help me track my weight. They’ll probably also graph it, calculate my BMI, and generate an autoregressive integrated moving average model. But I don’t want a new app, I just want to enter the date and weight as efficiently as I can. So I’ve decided to record my daily weight in Simplenote, an app that

  1. launches quickly,
  2. I’m familiar with, and
  3. can be streamlined with TextExpander.

Here’s what my note looks like so far.

I have to put three spaces between the date and the weight, otherwise the iPhone will interpret each line as a phone number and will turn it into a link—underlined and in blue.

I’m typing in the weight exactly as it’s displayed on my scale. It weighs to the nearest half pound, so eventually I’ll have some values that end with “.5” instead of “.0.”

I enter the date quickly via this TextExpander snippet:

The abbreviation is meant to indicate “date stamp”—I put a “z” at the end because “ds” is a combination that can appear in real words. I have TextExpander set to ignore the case of the abbreviation, so “Dsz” (which is what I’ll get at the beginning of the line because of the iPhone’s auto-capitalization) works the same as “dsz.”

The content uses the standard strftime format. Using two digits for the months, days, and years ensures vertical alignment.

There will, no doubt, come a time when I’ll want to graph my weight or do some sort of regression analysis. That’s when Simplenote’s automatic syncing will come in handy. I’ll copy the data from my Simplenote web page, paste it into a local text file or spreadsheet, and analyze to my heart’s content. For now I’m happy just to get into the daily routine of recording my weight.


  1. I know he’s an internet celebrity and all, but doesn’t it strike you as odd that Leo’s scale has almost 1500 followers?