Home Learning Day Two : Terminal Velocity

Mark Ng'ang'a
3 min readNov 1, 2016

--

Blue Pill or Red Pill?

Today wasn’t such a difficult day. I dare say today was a good day. A good day for science. After the havoc that the Car Class wrecked on me yesterday, anything would have been better really. That’s saying a lot. I am clearly still traumatised by that experience.

Moving on. Where was I? Yes, day two. We had a couple of labs today, not too difficult but not trivial in any sense:

  1. Word Count — Some pretty advanced string manipulation required here to count occurrences of a word in a string of text. Sounds easy, right? Not until you realise you have to consider i18n, numbers, and also punctuation marks as “words”
  2. Max and Min Number — Given two lists, return elements that are not present in both. This had lots of other rules that I won’t get into right now

The third task today was titled HTTP & Web and just the title had me all tingly with excitement. Wait, it gets even better.

[Write] a simple command line [terminal] application that consumes a Public API using a HTTP client library

That was the brief. You can see why I was excited right? No? I’ll tell you either way. I love the terminal. I live there, I drop into a shell and call out “Honey, I’m home!!”. I’m getting ahead of myself.

I immediately got to work finding an API to play with. After a couple of minutes on this little site called Google, I found it. I found wordnik.com and it was perfect. I was in love. I was going to build an application that looked up the meaning (and pronunciation) of any word you threw at it. Now, if only I knew the first thing about Python HTTP libraries.

Back to that little site I went and also to another little known one they call stackoverflow (You probably haven’t heard of it) Insert hipster tone here. After dabbling with a couple of the libraries, I settled on the requests library partly because it had this warning on the homepage:

Warning: Recreational use of other HTTP libraries may result in dangerous side-effects, including: security vulnerabilities, verbose code, reinventing the wheel, constantly reading documentation, depression, headaches, or even death.

I wasn’t about to risk death. I had to use this library. You understand, right? It’s not you, it’s me. With that settled, I proceeded to read the docs. All the docs on that library. Very well written if you ask me and easy to understand too. I was on my merry way hacking away on my keyboard in no time. I might have gone a bit overboard with the code feeding off the excitement.

“But Mark, where can I find this application you wrote?” Good question, Margaret. I pushed the code to GitHub here (shameless self promotion):

Feel free to fork me and make any improvements.

What did I learn today?

  1. Some strings are more equal than others
  2. Python might be even better than Shell on the terminal
  3. Python offers so many tools to help you get things done. I love the ecosystem (yes, I am aware that is the second time I have used the word “love”. Thank you, Sherlock)

Tomorrow is that last day of the home learning sessions. I’ve had a glimpse of the tasks and one in particular looks threatening.

Check back tomorrow and I’ll let you know how it went.

--

--