Monday, October 27, 2008

I haven't written about jQuery yet.

I realized that while I've had jQuery listed as an interest of mine for all this time I still haven't written about it. Shame on me.

One of the coolest things about jQuery, aside from the fact that it is generally kind enough to stay out of your way and let you write YOUR javascript the way you want to with just a bit of help from it (unlike some other JS libraries *cough*prototype*cough*), is the rather robust extensibility. It's almost trivial to write your own plugins for jQuery, which other people can then simply include and use like it was any part of the library. You can even override or extend existing jQuery functionality if you wanted to.

On a recent project I had to add functionality to a page to create a dynamic list of filters for some log information, which was presented on a table. The filters had different types, some were time/date fields, some were plain text, and some you could pick from a preset list of values.

Some of my favorite programming features and APIs are the kind where you can setup a large list of parameters, instantiate an object or call a method and let 'er rip. Plugins, especially jQuery plugins, really lend themselves to this sort of programming.

I ended up using this approach to write my filter feature, eventually realizing I could turn it into a jQuery plugin without too much effort.

Here is a link to my actual .js file for the plugin-ized version. And here is a basic example of how to use it.

$(document).ready(function() {
{filters:[{value: 'state', name: 'Status', type: [[0,'Open'],[1,'Closed']]},
{value: 'customer', name: 'Customer', type: 'text'},
{value: 'opened', name: 'Date Opened', type: 'datepicker'},
The code above is used by the plugin to create the HTML to display the initial form, which consists of 3 buttons and a single drop down list. The dropdown list is constructed using the value and name attributes, where value is the and name is the pretty name. It's probably easiest if value corresponded to the name of a database field somewhere, for ease of writing the backend.
When an option is selected from the original dropdown, the script looks at the type in that filters array to decide what to add. The types of "text" and "datepicker" both create text fields, but the datepicker has a special event attached to it to popup the jQuery datepicker and let you pick a range of dates. The only other option right now is to set an array like "[[0,'Open'],[1,'Closed']]", each internal tuple (python terminology), consists of a value and a name. The plugin uses these to make another dropdown list using those tuples.

Right now creating your own types involves adding a new elseif to the code, but it'd be pretty easy to add a hook to write new type handling functions.

Anyway, I finally wrote about jQuery. Even if I suck at writing.

--PXA, apologizes for this mess.

Monday, October 20, 2008

Sound the alarms

So I was walking to my car after work today and saw something VERY curious. On the corner of RIT's building 77 (The admissions/financial aid/co-op office building) there was what looked like a glow stick, duct taped to the side of a pillar.

Seriously? It wasn't glowing, and wasn't as green as they usually are. What I'm wondering is what paranoid idiot will call some sort of terrorism warning in on it. (Boston, anyone?)...I stood around for like 3 minutes looking at it...but I was thinking about if taking it.



Sunday, October 19, 2008

Spreading the wealth

So on my recent trip I spent a few hours (like 9) trapped in Chicago's O'Hare airport. And at one point received a phone call from a good friend of mine who I had tapped to tend bar in my absence at Steak and Whiskey night last night. The woman next to me at the bar had a son who was a bartender and was interested when I started talking about a drink recipe.

At Steak & Whiskey 2 we created a drink which was tremendously popular called "Stand back! I'm about to try science!". Science was created through use of the scientific method.
Hypothesis: Irish Cream and Amaretto curdle.
Evidence: several shots with these 2 ingredients were curdling in the glasses.
Experiment: Mix the 2 ingredients in equal portions.
Conclusion: Not only do they not curdle, they are delicious together.

It occurred to me that by telling her the story so that she could tell her son, this drink could suddenly start being made in a remote corner of the country - Far from Rochester.

Why not the world?
Now I call on the power of the internet to spread the good word of this drink.

Go forth and get blasted!

Thursday, October 2, 2008

I <3 Launchy!

It's no big secret that Launchy is one of the best programs ever to be written for Windows.
For those unfamiliar, Launchy is an open source keystroke launcher for Windows. Effectively a clone of the incredibly useful OS X tool Quicksilver. Launchy binds to a global shortcut key combination (defaults to alt+space) and then indexes the links in your start menu as well as others, allowing you to simply begin typing the name of the program you'd like to run and then hitting enter when you've given Launchy enough to work with. Launchy also learns what your common shortcuts are, so the first time you need to launch Firefox, you'll probably need to type almost the whole thing. However, after a few weeks you'll be able to launch Firefox by typing "f" into Launchy.

I have previously made the statement the Executor was better because it allows custom keywords to be set in the application so you can configure it to...say, run Internet Explorer when you type "turdpile" :D. However, as cool as it was, it took so freaking long to display the window I couldn't deal with it.

But this isn't the reason I bring it up today. I wanted to make note of the fact that Launchy has recently released a Linux version, bringing the power of keystrokes to the GNU desktop.

Launchy provides a .deb package for Linux distributions whose package management is based on dpkg or apt-get. They also provide a source tarball which can be used to build just about anywhere else. My preferred Linux is Gentoo. Some say this is because I like to suffer. Gentoo's package management system is based on ebuild files which are a set of instructions for retrieving source, patching, configuring, and compiling. To this end I decided to install Launchy on Gentoo legitimately, using an ebuild and an overlay.

Included in this zip file is a folder which can be unzipped into your portage overlay and installed using emerge. If you do use it, you should note:
The Launchy portion itself depends on qt4, while the calcy plugin requires Boost. Since Launchy can be built without calcy, I have set this in the ebuild as a USE flag. If you would like calcy, make sure to add 'calcy' to your USE flags before emerging launchy.

As an interesting note, with any luck you may not have to go through the trouble of creating an overlay for this as the ebuilds and associated patches have been submitted to Gentoo's bugzilla to be added to portage. (YAY!)

The bug can be found here.
Vote for me!

P.S.: My good friend, Sam, has offered me some of his bandwidth and hosting space. I will be hosting all future packages and patches on his server. Check out his stuff at He does webdesign and also makes sweet little desktop enhancement applications like Jango Desktop.

That is all.