From Markdown To Pastable Formatted Text In OS X Terminal

By Tuesday, August 4, 2015 0 , , Permalink 2

I use Markdown a lot. I use it right now, to compose this post :-) . It’s my go-to syntax for quick plain text files for notes and such. It’s what I use when I code something that outputs “formatted” text to terminal.

Recently, I wanted to take Markdown output from a script I wrote, and send a nicely formatted version of it by email.

Read on for the solution I eventually came up with, after several iterations, and essential tips from Brett Terpstra, the Markdown Master.


cat | \
  pandoc --from markdown --to html | \
  textutil -convert rtf -stdin -stdout -format html | \
  pbcopy -Prefer rtf

Check Out These Python Podcasts

I recently discovered two new podcasts about Python!

I think both podcasts started about the same time – 3-4 months back. I found out about them a few weeks ago, and managed to catch up on the episode backlog :-) .

Both are based on conversations with people from the industry and Python community.

Talk Python To Me is hosted by Michael Kennedy. At the least, check out the show theme music. Beyond that, I enjoyed the technical depth of the conversations. Especially the episodes about Netflix, Flask, and Docker. The production quality is surprisingly good for a young independent podcast.

Podcast.__init__ is hosted by Tobias Macey and Chris Patti. This show could use some nicer production-fu, as much as I enjoy a whispering guest along a shouting host. Many of the conversations on this show are interesting as well, like the one with the Python guys. Personally, I enjoyed the more technical conversations, compared to the culture-themed ones.

If you’re a Python-enthusiast, definitely look into these podcasts!

Shell Foo: Comparing the Output of Two Commands – Without Temp Files!

You probably know to use the diff file1 file2 command to compare file1 and file2 line by line.

Sometimes you don’t want to compare files, but output of commands. For example, compare sort file1 and sort file2. Or maybe compare grep foo file1 and grep foo file2.

Of course, there’s the obvious way – run the commands, redirect their output to temp files, and compare the temp files:

$ sort file1 >tmpf1
$ sort file2 >tmpf2
$ diff tmpf1 tmpf2
$ rm tmpf*

But, really..? 3 extra commands just for the one command you really wanted?

There must be a better way! This post is about the better way :-) .

Even better, the solution is more general than diff. It allows using the STDOUT of any command as a “file” input for other commands!

Shell-Foo is a series of fun ways to take advantage of the powers of the shell. In the series, I highlight shell one-liners that I found useful or interesting. Most of the entries should work on bash on Linux, OS X and other UNIX-variants. Some probably work with other shells as well. Your mileage may vary.

Feel free to suggest your own Shell-Foo one-liners!

Shell Foo: Subtracting Lists With comm

The comm utility is powerful, yet not well known.

Named after the word “common”, you can use the comm utility to select or reject lines common to two files.

Practically, once I learned about this tool, I use it often to:

  1. Get all lines that exist in both files (“select common” lines).
  2. Find lines that are missing from one file compared to another (“reject common” lines).

Just don’t forget that comm requires that the input files are sorted lexically! That shouldn’t be a problem, since you can always use sort before calling comm. But you do need to remember to do this, otherwise you might get unexpected results (which may or may not happen to me on a regular basis).

Shell-Foo credit for this one: Eyal Fink.

Shell-Foo is a series of fun ways to take advantage of the powers of the shell. In the series, I highlight shell one-liners that I found useful or interesting. Most of the entries should work on bash on Linux, OS X and other UNIX-variants. Some probably work with other shells as well. Your mileage may vary.

Feel free to suggest your own Shell-Foo one-liners!

When Audible Meets Google: Cool or Creepy?

By Saturday, July 4, 2015 0 No tags Permalink 0

Last week, I finished listening to the audio book version of All the Light We Cannot See, by Anthony Doerr.

The book is wonderful, and I warmly recommend it. In the book, we go back and forth between the stories of the blind french girl Marie-Laure, and the orphan german boy Werner, as they grow up with the second world war shaping their lives.

This is not a summary or a review of the book, so I will not go further into describing the story. I would like to show you a random digest email I got from Google+, a few days after finishing the book:

Oh, have I mentioned that a significant part of the story takes places in Saint-Malo?? :-)

Take notice – I used Audible to buy and listen to the audio book, using my Amazon account. I got this Airbnb G+ post from Google+, urging me to explore a place I just “experienced” through a book!

Yes, I understand it was easy for Google to know that I bought the book, because I got the receipt to my Gmail. I’m not surprised that they knew. I’m surprised that they were able to time it so well with when I finished the book. I have many books in my Audible libraries. I don’t listen to all of them immediately after purchasing them…

Anyway, I thought it was cool. I believe many will find this more creepy than cool. I think it’s generally a good thing, if it allows Google to show me things that might interest me, when those things may be relevant for me. What do you think? Cool or creepy?

Happy Leap Second!

By Tuesday, June 30, 2015 0 Permalink 0

Are you ready for tonight’s leap second?

No idea what I’m talking about? tl;dr – once in a while, an extra second is added to synchronize coordinated universal time (UTC) with mean solar time. This is needed because, generally, the Earth’s rotation slows down over time. Leap seconds, unlike leap years, do not occur in regular intervals, because the variation in the Earth’s rotation speed varies irregularly. An example of such irregularities is the 2011 Japan earthquake, that increased the Earth’s rotation speed a bit.

If you’re thinking “what’s an extra second once in a while?”, and “why should anyone care about it?” – feel free to spend that extra second in a productive way 😉

A little extra thought can uncover the potential complexities entailed in such time manipulations.

How do banks and stock markets agree on exchange rates? If you make a deposit and a withdrawal, does the order matter? In a distributed compute cluster, how do compute nodes elect a leader? In cryptographic protocols, how do Alice and Bob verify that Eve isn’t tampering with their connection? How does a control tower in a busy airport is able to coordinate hundreds of incoming landings?

These examples, and many others, all rely on the ability to know the time, have a good estimate about the time on “other sides”, and being able to order events sequentially. Manipulating with time itself, in an irregular way, can cause a lot of chaos… It actually did cause chaos the previous time we experienced a leap second, back in 2012!

This is quite an interesting subject, and I encourage you to go deeper :-) .

If you decide to read just one more thing, let it be Google’s post on the subject, mentioning their elegant “smear window” solution. It’s pretty cool.

Got My Sensibo Kit!

If you follow my blog for a while, you know I’m a big fan of home automation. Especially controlling the A/C from anywhere.

I was excited to learn about the Sensibo Indiegogo campaign last year, and thrilled to receive my Sensibo Kit last week!

The Sensibo kit let’s you control your A/C from anywhere. This is similar the my A/C control project, only done professionally :-) .

The kit includes a small hub that connects to the home router, a tiny pod, and free Android & iOS apps. After setting it up, I can easily control my A/C from the phone app from anywhere, which is so great! Nothing like coming back to a pre-cooled house from the blazing Israeli summer :-) . There’s even IFTTT support, enabling automatic house-pre-cooling whenever I approach home!

How To Use SSH With Multiple GitHub Accounts

All I wanted is to have two GitHub accounts, and use them both from the same computer, using SSH. Is this too much to ask?

I’ve been using my personal GitHub account for some time, and associated my default SSH keys with that account. When I created a work account on GitHub, I expected I’d be able to associate the same SSH keys with the work account, so I can git pull/push as easily.

This proved to be a problem. GitHub does not allow reusing SSH keys across accounts. Here is the message I got when trying to do that:

I managed to overcome this problem by creating new SSH keys for the work account. Read on for the details.

Weekly Review, March 14

By Saturday, March 14, 2015 0 Permalink 0

Today was Pi day, and this year was “super Pi day”. I already mentioned it this morning. I also mentioned Pi day is celebrated as “Aba day” in my family, thanks to my perfect wife. She’s not into the geekiness, but she’s into making it an awesome day! Today included lemon meringue pie for breakfast, Pi-decor and balloons with a bunch of Pi digits floating around the house, pizza-pie for lunch, and some Pi-centric fashion statements :-)

The Weekly Review is a recurring (sort-of-)weekly summary, reviewing highlights from the last week.

Happy Best Pi Day of Our Lifetime!

By Saturday, March 14, 2015 0 Permalink 0

This “Happy Pi Day” post was published on 3.14.15@9:26:53.589 (at my local time, UTC+0200)!

Pi day is also known as “Aba Day” (or Daddy Day) in my family. You’ll see why in a later post… 😉

If I lived in the 16th century, I might have witnessed an ever cooler Pi day, on 3.14.1592@6:53:58.979. But back then I guess it was harder to geek out about it…

An even cooler Pi day will take place on 3.14.15926@5:35:8.979 (yes, I’m loose with the zeros). Only 13,910 years, 364 days, 20 hours, 8 minutes, 15 seconds, and 390 milliseconds to go!

Happy Pi Day!