New Feature – Right Now

THE FEATURE
I spent the day adding in a new feature to the site called “Right Now.” The feature is now ready and you can start using it in two ways. First if you press the link in the top menu titled “Right Now”, (duh) a message will pup up with the most recent Tweet posted to twitter that contains the word “feel.” go try it, but be careful, it can be a bit addicting. I’ll wait here…Did you press it more than once? Was it funny? Inspirational? Sad? I could press that thing all day long, but then again I’m fascinated by cultural and social interactions among primates.

The second way you can use this feature is with the input field at the top of the right side panel. You’ll notice a button below it called “Right Now.” I guess that’s a pretty big clue. The default value for the input field is evil (after all, I am the malignant genius), but you can type any single word your heart desires. Press the button and it will return the most recent posting containing that word. When you’re done just press the close button.

[Right Now] is a feature I’ve been planning from the beginning. The idea for it came from two different sources. First I’ve always had an affinity for the music video to the song “Right Now” by Van Halen. If you’re not familiar with it, throughout the song they flash captions about things that are supposed to be happening right now. For example, “Right now someone is crying over a lost love.” The second is a site called We Feel Fine. My idea was to combine the two. Quick one offs that show up and then are gone. No tracking. No metrics. Think of it like passing a stranger on a rainy night and hearing what they are thinking at the moment. You keep walking to reach your destination and get out of the rain. There’s no turning back. Once you pass by it’s gone. A fleeting glimpse into a stranger. Sometimes sad, sometimes funny, with just a touch of the intimate. Such is life.

THE TECHNOLOGY
I went around a bit about where to get the data from. Originally I wanted to use blog posts, but that got into issues such as: What search engines have API’s; Do I search just titles or whole posts; How do I get just the piece I want; etc. In my quest I stumbled upon the Twitter Search API. It was simple, and produced either an ATOM feed or JSON. There was no issue with what to display since the title and the post are one and the same. Also the very nature of Twitter seemed to go with the philosophy I was implementing. Tiny bits of random thoughts.

With the source selected the next question to answer was how to implement. I knew I wanted to display this information from the main menu, it should take a small amount of real estate (no page redirects), and that if it wasn’t active it should disappear. I settled on a [div] tag set to an absolute location on the page. A JavaScript activates and deactivates the text of the post. I pretty much knew this is what I wanted from the start, but here are a few options I thought about and rejected.

  • Reuse the real estate right below the site title. There is plenty of space there and when not in use it would pretty much disappear.
  • Popup a new window. In the end I didn’t feel it was very elegant.
  • Throw it on the top of the right panel. When active it would adjust everything down. Again not very elegant.
  • Page redirect. As I mentioned I really didn’t like this idea, but when I was thinking I might have to display an entire blog post I had to consider it.

With the data source and display mechanisms selected it was just a matter of hooking it up. While this is a relatively straight forward feature there were a few issues to deal with.

First, postback or AJAX. This was a no brainer. With a small amount of data to get and a web API to get at it, AJAX was the hands down winner.

Next, what framework to use. I thought about using the ASP.NET AJAX framework that’s a part of ASP.NET 3.5 as well as jscript since M$ has decided to support it in a future release of the framework. In the end I decided to use my own framework. My reasons are as follows. 1) I already have my own light framework. I’ve been doing this for a while and have my own scripts for AJAX from the days when we didn’t have all of the choices developers do now. 2) There was no algorithmic reason to interact with .NET. All I needed to do was pull data from a third party. 3) Finally, and this is probably the biggest reason, the other frameworks are monolithic and way heavier than I needed. All the code I needed was probably about 30 lines total, and most of that is error handling and validation.

Lastly, since I was going to be calling across domains I needed to be able to handle that fact that most browsers would deny the request due to security reasons. My answer to this was a local proxy. My AJAX code would call a local proxy and then the proxy could call out to Twitter. Now you might be thinking that this goes against the second item in the previous paragraph. Notice how I was careful to say there was no “algorithmic” reason to interact with .NET. To be honest at this point I almost went back to ASP.NET AJAX. The overhead still kept me from it though. So for the proxy instead of using WCF (Even though I’m a big fan), or a web service, I decided to create an ashx file instead. I may change this at some point, but it seemed to be the easiest way to implement what I needed. Remember our agile principles, functioning code first, refactor for performance later. There are really only two points of note about the proxy which follow here:

  • The return type is [text/plain]. I basically return the innerHTML of the display div.
  • Caching is turned off. Otherwise you’ll get the same results every time. Here is the line of code to do so.
    ** context.Response.CacheControl = “NO-CACHE”;

CONCLUSION

This really didn’t take very long to implement. Hopefully you have a good understanding of the process I went through to develop this feature. I haven’t posted any of the code as that is really not the purpose. As I talk about the features of the site I will always talk more indirectly about the architectural considerations that go into making my decisions rather than focusing on code implementation. I’m always happy to answer questions about implementation, but there are literally thousands of blogs that talk about lines of code. IMHO precious few talk you through the software design.

In closing, I love this feature even if no one else does. In fact I just went out and pinged it. “i’m at complete peace with my feelings now. i don’t feel angry or mad or really that upset anymore. what a nice feeling.” Welcome to someone’s inner thoughts.

Site Update 1

Just did a quick update to the site. Added a new feature, “Right Now.” See the following post that talks about the feature. I also updated the colors. Made it a bit darker. I think it looks much cleaner stylistically.

Bug: There is a problem with the site when viewed in IE8. If you switch to compatibility mode it will look fine. I’ll be looking to fix it with the next site update.