Monthly Archives: February 2011

Using Chrome desktop notifications on your own site

Google Chrome has an API to allow websites to use desktop notifications. This is the same thing that Google’s apps (e.g., Gmail) and some Chrome extensions (e.g., TweetDeck) use for message notifications. It’s drop-dead simple to use. Here’s a simple example:

This does two things. First, it requests permission for the website to display notifications. This presents the user with this banner:

Once permission has been obtained, the callback displays the notification like this:

Of course, you will want to use the checkPermission() function to make sure the user clicked “Allow”. If they denied permission, you might have to do something else.

Here is some documentation from the Chromium project about Chrome’s implementation, and here is a more in-depth example.

Using a configuration file for Boto

In Lab 3, we’re doing a lot more with Boto. It’s useful to have a configuration file and put everything there so that AWS keys, SimpleDB domains, and SQS queue names don’t have to be embedded in the source code. In this post, I’ll talk about using a system-wide config file for Boto.

The config file
The config file itself is very simple. It has several sections, each with a heading. Under the headings are key=value pairs. Here is a simple example:

[Credentials]
aws_access_key_id={redacted}
aws_secret_access_key={redacted}

[simpledb]
imagedomain=picture
commentdomain=comment

You could make other sections for S3 and SQS if desired (those will be used more in Lab 4). Finally, put that file in somewhere it can be accessed by the whole system. Mine will go in /etc/boto.cfg.

Using the config file in Python
You can use the ConfigParser module to get the key/value pairs out of the config file and use them. That code might look something like this:

import ConfigParser
config = ConfigParser.ConfigParser()
config.read(["/etc/boto.cfg"])

Now, whenever you need to get a value from the config file, simply call get() on the ConfigParser object, passing it the section and key you want. For example, if I want to get the imagedomain key out of the simpledb section from the example config file above, I would write this:

imagedomain = config.get('simpledb', 'imagedomain')

Conclusion
The advantage of doing it this way is that all your Boto configuration is stored in one location out of the web root where all your scripts can access it. You don’t have to hard-code all that information into the website code itself, making maintenance easier.

Getting more detailed stats on KRL applications with the Ruby gem

A couple months ago, Kynetx released a new version of their Ruby gem, which added support for getting statistics on your apps. A limited version of this facility was available in the old AppBuilder, but the feature was removed when the current AppBuilder rolled out last April.

There is a bare-bones command, krl stats, that will give you a simple run-down of your app’s stats for yesterday. It looks like this:

But if you want to get information in any more depth, you’ll have to learn the somewhat complex krl stats_query syntax. First run krl stats_interface to list all the possibilities. Let’s say for this example that I want to know how many rules were fired per day of the week for the last three months. I would construct a query like this:

krl stats_query -k rules_fired -d day_of_week -r last_three_months

That produces something like this:

I haven’t figured out how to specify multiple KPIs or dimensions, though. For example, I might want a report that gave me both BRSE and rules fired, or perhaps one that correlated the day/month/year with the day of the week. I have an open question on StackOverflow that should hopefully clear that up.

Programming SimpleDB with Python and Boto

Lab 3 for CS 462 requires you to read from and write to SimpleDB. Using Boto in Python makes this pretty easy. Here are some simple examples:

The templates look like this (pretty simple):

First semester as a TA: A midterm report

This semester I’m a TA for Phil Windley’s CS 462. (I’m sure you are aware if you’ve been following my blog for any length of time recently.) This is the first time I’ve ever been a TA. All the other work I have done has been programming, an occupation that requires occasional interaction with team members and clients but is largely isolated and personal. Being a TA has really put me out of my comfort zone in a lot of ways, but it’s been a growing experience.

Phil has me teach the lectures whenever we talk about the class project. There are six labs total, and so far I’ve given two lectures (the next one is tomorrow night). Those have probably been the hardest parts of this job for me. Standing in front of a class of 30 people trying to explain things while appeasing the demo gods and not making a fool of myself is a whole lot different from sitting with someone one-on-one in a cubicle working through his questions. It’s been a nerve-wracking assignment. (Didn’t help that last time I all but lost my voice. Lapel mics to the rescue!)

Another complication is that I’m taking this class for the first time as well. Sometimes I’m not able to answer people’s questions because I simply haven’t had enough experience with Python or with some particular part of the lab that they’re having trouble with. It becomes a delicate dance between telling as much as I know, faking it, and owning up to the fact that I just don’t have all the answers.

The survey

Those are my perceptions of myself, however. I wanted to know what the students thought. So I put together a midterm evaluation survey on Google Docs and sent it to the class mailing list. Only seven people ever responded; whether their responses are at all indicative of the rest of the class I may never know. But the results are worth analyzing anyway.

The survey had ten questions. The first eight had a statement about the me, to which the students could indicate their agreement on a scale of 1-5 (strongly disagree -> strongly agree). The last two questions were free-response, asking what I am doing well and where I can improve.

There were only two questions for which all the responses were 4 or higher (“The TA knows the course material” and “The TA is able to answer my questions about the project”). Two others rated fairly high: one 3 with 4′s and 5′s (“The TA understands the project” and “The TA is responsive on the mailing list”).

What I found interesting were the questions “The TA does a good job explaining the project requirements during the lab review lectures” and “The TA is approachable”. These both elicited rather varied (often less favorable) responses. They both serve to confirm my own impressions that my public speaking and interpersonal skills are somewhat lacking. While this is not surprising to me, it indicates that it is an area that sorely needs improvement.

I’m giving another lecture tomorrow on Lab 3. I’ve spent a lot of time preparing for this one, so hopefully I will improve and be able to explain things better this time. I’m really enjoying this job, and I’m excited to develop and become the best TA I can.

Image Project submission Kynetx app

I wrote a simple Kynetx app today that annotates Flickr and TwitPic with links to submit the image to the CS 462 Image Project website. This is similar to what students will implement in Lab 5. I’m providing a reference implementation right now to make testing the app server in Labs 3 and 4 easier.

The app finds the image and detail URLs for you (which, depending on the site, can be a rather complicated thing). It then takes you to the /submit endpoint on the demo web server so you can fill in the rest of the details and submit the image to the system.

The Flickr version adds an “Add to the Image Project” button to the toolbar right above the image, in the same theme as the rest of the buttons.

The TwitPic version adds an “Add to the Image Project” to the image toolbar that appears when you hover over the image.

This browser extension includes both of those (and it will be updated later when I add a few more sites).

Download the extensions here:

If you’d rather use a bookmarklet, drag this to your bookmarks bar:

462 Image Submitter

Coding in the cloud: SourceKit

There is a project called SourceKit that intrigues me. It’s a Bespin editor inside a Chrome extension that integrates with your Dropbox account.

What’s so cool about this is that it opens a lot of doors for programmers to use web-only devices (like those running Chrome OS) to do programming that would normally have to be done on a full-fledged machine. There are already similar things like Palm Ares (used for writing webOS apps) and of course Kynetx AppBuilder (but there your code runs in the cloud anyway).

Imagine this:

The client. You’re working on a website that runs your scripting language of choice (not a compiled language). Let’s say PHP for sake of argument. You put all those PHP files into a folder on your Dropbox. With the SourceKit extension, you can edit them with just a browser, no command line or IDE necessary.

The server. Your server is set up to sync to Dropbox (perhaps with its own account on a shared folder). It downloads the changes you make immediately when you save the file. You can then go to your website (also from the browser) and test the new code immediately. This might be a better setup for a dev server than a production server, of course, but you could figure out a way to push code to the production server once it is ready.

You could imagine ways of doing this for code that needs to be compiled (e.g., compile on a server and use a browser-based terminal emulator to SSH in). I’d think you could also build a Git client to commit/push code to a Git repo rather than Dropbox. The possibilities are endless.

I’m excited to see where this goes.

Just a note: Bespin was renamed Skywriter and later merged with Ace. But @kirbysayshi on Twitter pointed out to me that kenotron is already working on using Ace. Cool!

Office Hours app: Reporting the next time block

This is the third in a series of three posts about this app. The other pages are here and here.

If you text the CS 462 Office Hours app and get back a response that I’m not currently holding hours, it’d be nice to know when the next time is that I’ll be in. I modified the app using the next() function in Sam’s module to do just that.

This was fairly simple. Here are the important pieces of code. First, the modified SMS rules (rules for voice calls are similar):

This is supported by a function in the global block, similar to Sam’s “verbaldate” function:

What’s next? Perhaps durations: I’m currently holding office hours, but how long will that last (i.e., when does this shift end)? I’d also like to modify the messages to say “today at 3 PM” instead of “Thursday (Feburary 3) at 3 PM”. Lots of good ideas. What do you think?

EDIT: I added durations to the SMS and voice calls, as well as to the class wiki annotation. In addition, we planted site tags there, so everyone sees the schedule now. :)

Extending the Office Hours app using Twilio

This is the second in a series of three posts about this app. The other pages are here and here.

I extended my CS 462 office hours app this morning to include some Twilio features. I used Sam’s auction example heavily, since the Kynetx docs don’t talk about SMS much.

Basically, this app lets you call or text a phone number and find out whether I’m in my office hours.

I started by registering a phone number with Twilio. The number for this app is 801.855.6574. Once I had the number, I added two handlers, one for voice and one for SMS. They look like this:

http://webhooks.kynetxapps.net/t/a163x40.dev/onanswer

http://webhooks.kynetxapps.net/t/a163x40.dev/sms

I’m using the “.dev” extension since I was developing this actively. I might change that for the production app.

The KRL was pretty simple. I just needed two rules: one to handle the “twilio onanswer” event, one to handle the “twilio sms” event. That code looks like this:

I’d like to extend this in a few ways. One will tell you the next time I have office hours if I’m not there right now. Another might be allowing more options through SMS (asking whether I’m there, what the next time slot is, etc.). Other ideas you have?

Using Google Calendar data in a Kynetx app

This is the first in a series of three posts about this app. The other pages are here and here.

Sam Curren wrote today about a Google Calendar module he has created for KRL. It’s pretty awesome; go check it out.

The only thing it does right now is check whether we are currently in a block of time on the calendar with a given name. Sam used that to modify the Kynetx phone system whenever office hours are running. I publish my CS 462 TA office hours to a Google Calendar and wanted to do something with that data as well.

The first round of this app does some simple web augmentation on the CS 462 wiki. Whenever I’m in for my office hours, it add this line to the top of the wiki:

All the app does is use Sam’s module with my own Google Calendar and then run a prepend() on the wiki when an “Office hours” event is currently happening. Here’s the code:

I’d like to make some improvements in the future to use Twilio (something I need to learn for later in the course). Perhaps other things, too. Leave suggestions in the comments!

EDIT: I used site tags to place this on the class wiki. If you go there right now, you’ll see my office hours status!