Garage Door Blues – Part 2

In the previous article, we established the motivation for building a garage door opener using the Raspberry Pi along with a handful of other components. More specifically, we outlined the desired features of the opener, which includes the ability to monitor and control the door through a website. In this installment of the series, we’ll focus on the features and how they can be implemented in the Raspberry Pi. We’ll use a state machine to keep track of the garage door.

The state machine below, described using a classic “stick and bubble” notation, provides a very simple approach to describing the states of the door. Basically, the door is either open, closed or somewhere between.
Continue reading

Garage Door Blues – Part 1

If you’ve looked at my blog posts lately, you’ll see that I haven’t contributed in quite some time. I have an excuse. I had to pack up and move from sunny Southern California to the frozen tundra of St. Louis. The transition to a new job was complicated enough, but having to sell a home (at a severe loss) and then find and move into another house was a real distraction. For the time being, my wife and I are renting, as it just didn’t make sense to buy a new house while trying to sell the old one.

Continue reading

Hollywood on OAuth 2.0

Protocol documents are not necessarily easy to digest. They are often overstuffed with information, making them dry and difficult to understand. While the IETF is a good resource on protocols, their descriptions are often too pedantic and lack a “big picture” perspective. And if you’re like me, you need that big picture perspective before wading into the details.

I’ve been unable to find that big picture on OAuth 2.0, so I decided to write my own big picture, using what little I know about screenplay writing. I thought it would be fun to see how a conversation between three people could help understand the OAuth 2.0 protocol.
Continue reading

Book Review: Three.js Essentials

Review of book, Three.js Essentials by Jos Dirksen
Packt Publishing, July 2014

Three.js Essentials provides a starting point for anyone curious about how to leverage the WebGL standard using the Three.js JavaScript library. The book consists of seven detailed examples with explanations of how they work. Unfortunately, these explanations are light on detail, making the treatment of this subject somewhat superficial.
Continue reading

Provide Line Numbers for Your Code Listings

Have you ever wanted to list your code on a website and automatically number each line? Sure, you can do it manually, but it’s painful to go back and re-number all those lines should you decide to change the code. Also, it’s difficult for your viewers to copy and paste your code without having to back out all those line numbers.

Well, you’ll be glad to know that it’s really easy to implement this automatic line numbering feature. All you need to do is encase your code in <pre> … </pre> tags, and then let JavaScript and CSS do its stuff!
Continue reading

Ruby, Cron and Instagram

Instagram is an effective visual medium to help you keep your marketing effort in high gear. But you need a way to tie it to all your other online social activities so that your followers can get a centralized view. For example, you may want to link your latest four Instagram postings to your blog by offering a picture and a link for each entry on your blog’s landing page.

This article describes how you can use Instagram’s API to capture your latest activity and periodically (e.g.; every 15 minutes) update your website. It uses Ruby to do the hard work, and runs periodically using a Linux cron job.
Continue reading

Avoiding the Ruby Run-On Sentence

The run-on sentence can be defined as two or more independent clauses that have been joined without an accompanying coordinating conjunction. Run-on sentences carry multiple thoughts, which confuses the reader.

So what does this have to do with Ruby? Well, it is this author’s opinion that run-on sentences can be a sign of danger when describing your program objectives. Each objective within your program should be conveyed in as simple terms as possible, without having to glue together lots of disparate thoughts.

Fortunately, this is fairly easy in Ruby, as it really excels in describing complex concepts in a very terse manner, allowing you to express yourself clearly.
Continue reading

Simple Internationalization in Ruby Sinatra

Internationalization is such a long word that people commonly refer to it simply as “i18n”. If it’s not already obvious, the number “18” refers to the number of characters between the “i” and the final “n”. It’s a complicated word, and similarly, internationalization can be a complicated beast to tame in your web pages, assuming you want to appeal to an international audience.

Some people approach the internationalization problem by creating entirely new web pages, which essentially results in a parallel website for each language. I don’t know about the latest version of Drupal, but Drupal 5.0 forced you into this very paradigm. What a nightmare to implement this approach and maintain a parallel website for each language! The situation gets really complicated when you want to link to another page within a different language. You have to go through and change each link for each of your parallel websites. It gets even more complicated if a target page in a specific language is not yet available because it hasn’t been translated yet.
Continue reading

Preserve Context In Your Ajax Calls

Asynchronous Ajax calls can really mess you up. The problem is that the environment within which you execute an Ajax call isn’t the same environment as when you handle the results. This situation occurs because of the nature of asynchronous environments. The browser makes the Ajax call to the server and then continues with its own business. Sometime later, the server responds with the results of the Ajax call, but by that time, the context of the browser’s running thread has changed.

It’s like arriving at the train station after the train has left town.
Continue reading