Tuesday, March 26, 2013

jQuery UI: Tooltips For Selected Text

The jQuery UI tooltip widget can be used to display contextual information about some text that a user has selected. Typically, the tooltip is used to display little tidbits about widgets or data fields in the UI — what does this do, or what does this mean? By default, the tooltip is displayed when the user hovers the mouse pointer over the element in question. But we don't want that behavior in a paragraph of text. Instead, we want the user to highlight the word or phrase they're unsure about. It is then that we lookup in our knowledge base something useful to tell the user, displayed through the tooltip widget.

Friday, March 22, 2013

Python: Dict Comprehension Example

Just like list comprehensions, dictionary comprehensions help the Python programmer quickly construct an alternative structure from something more permanent. The application we're working with probably has a schema, and from that, we can only do so much as we implement new functionality over time. So rather than alter the data model that supports the application, why not create something transient? This is where the comprehension idea is powerful, at very efficiently constructing new data sources. You can use this approach to creating new lists and dictionaries that stick around for the duration of the program, but a more useful use case is in creating a temporary search space.

Wednesday, March 20, 2013

Using jQuery UI Tooltips With Flot

Flot charts work nicely in jQuery projects. Especially since it's targeted for jQuery-based code. These charts can work well in jQuery UI projects too because they're very granular in their configuration values. You can make the charts look like they're seamlessly integrated into your theme. There was, however, one place I was having trouble with until recently — tooltips. I like being able to show the user some more detail when they hover over data points. Flot even provides an example of how to do this using a generic tooltip component, constructed on the fly. I want to show jQuery UI tooltips using the same approach. This is what I came up with.

Sunday, March 17, 2013

Libvirt: Metering Domain Network Traffic

We can use the libvirt API to get network traffic at the interface level. So to meter the network traffic at the domain level, we have to find all interfaces the domain is using, and aggregate the traffic stats. This isn't too difficult — we just have to query the running domains, and query their XML descriptions individually in order to find the interfaces we need. One challenge we might face, using this approach, is the fact that any two interfaces could be using different networks. For example, let's say that we only want network traffic on the default network? Here is an example of how to generate this network traffic in Python. We're using the collections and the etree modules.

Friday, March 15, 2013

Computing Unions With Lodash and Knockout

It's easy to create observable arrays using Knockout. We can even create computed observables that are based on those arrays. For example, a computed observable might return the last item in the array. This means that any bindings for this computed observable will update any time the array changes. Specifically, the last item in the array. Where the observable arrays get interesting are when there are several of them, and you have a computed observable based on each array. Say, for example, we have several arrays that store programming language names, based on category. There may be some overlap between arrays since many languages are multi-faceted. This is where we can utilize Lodash in out computed observables.

Thursday, March 14, 2013

Connecting To PostgreSQL With Shove

PostgreSQL is far from a basic key-value data store. Instead, you're typically using it for robust web applications that store mountains of data and perform sophisticated, high-speed, high-volume queries. So why would you want to use it as a key-value store, relational databases are supposed to have schemas. Of course they are, but maybe you already have PosgreSQL deployed in your development and production environments and don't feel like installing more database back-ends. You also don't feel like designing a new schema to support persisting values in a smaller application you're writing. This is where Shove is handy.

Wednesday, March 13, 2013

jQuery UI: Preserving Sortables

The sortable interaction widget let's the user arrange a list of items. Which is great, except for when you want to preserve the order of those items. As soon as you reload the page, the order is gone. That is, of course, unless you're storing the order as part of the application somewhere. But if you just want to create a sortable that preserves the order using the cookie plugin, here is how you can do that. This is my basic sortable list.