Git-R-Done

I’ve been a long-time fan of using Subversion for source code version control, but recently I’ve been turned onto using Git, which is the version control system used by huge projects like the Linux Kernel, Ruby on Rails, Merb, Samba, VLC, and a lot more. It was designed by Linus Torvalds so it really has some geek street cred.

Why is it so cool? Git is distributed, for one thing. That means that while you may have a central location for your repository, each client clones the repository on their system. So if you lose a machine you don’t lose all your history for the project.

Being distributed like that makes it fast, because looking up history is done locally instead of over the network, so you gain a lot of performance. It has been shown to be very fast and scalable by a significant amount.

Branching, tagging, and merging are a lot easier in Git because they are treated as core concepts. Every working directory of a Git repository is in itself a branch. Handling those branches is something Git excels at and keeps track of merging the changes from different branches with ease, preserving the history of who did what a lot better than subversion does.

You can see more comparisons and contrasts between Git and Subversion on the Git Wiki.

Another (personal) reason I like Git is because of a certain tool: Github. Github is a repository host that acts almost like a social network: you can track projects you are interested in to see the latest activity as well as giving you the ability to maintain your own projects. It is a sweet little setup. If you are into development at all you might take a look.

I have decided to move my Guilder project to Github, and so far I love it. My endorsements, they are ringing!

Includes and dependencies in Javascript

For a while now I have been wrestling with a way to easily manage dependencies in Javascript.I absolutely hate having a mess of script tags in my documents, especially on a dynamic page that only uses maybe one or two of those scripts.

So when I started using jQuery, I was delighted to find that I could write an easy method to include files on the fly using Ajax and synchronous loading and execution of Javascript files. This gives us the ability to utilize lazy-loading to load scripts as they are needed and not clutter up things or waste resources if a particular Javascript is not needed.

It is easy to define a method like this (utilizing a class so as not to pollute the main Javascript namespace):

SLAGGLE = function() {};
SLAGGLE.include = function(filename) {
    $.ajaxSetup( { async: false } );
    $.getScript(filename);
    $.ajaxSetup( { async: true });
};

This uses jQuery’s getScript method to load a script, but first sets global Ajax configurations to load it synchronously so we can use it right away. So now if I want to load a script on the fly, I can do so with this:

SLAGGLE.include('/path/to/js/script.js');

You can even go a lot further and create a method to translate a package heirarchy like what Java uses into a path structure and load that instead.

I’ve been using this method for a while, but this morning I stumbled across this: using.js

using.js gives stronger dependency management to Javascript by allowing you to declare potential dependencies beforehand, and load them on the fly. The upside to doing this is that not only do you get lazy-loading, but the using.js script will only load a particular dependency only once, which cuts down on overhead quite a bit. It’s real easy to use, too. Just register your dependency like this:

using.register("jquery", "/path/to/jquery-1.2.3.js");

or even multiple dependencies:

using.register("yui-datatable",
    "/path/to/yui/script1.js",
    "/path/to/yui/script2.js"
);

Then later, when you need to make use of the dependency, you can do the following:

using("jquery");
// Use jQuery features
$("document").ready(function() {});
using("yui-datatable");
// Use YUI features, etc...

The using.js script really adds a lot of power to your Javascript coding. It has the potential to make your code much more efficient if you rely on a large number of external dependencies. Give it a try and let me know what you think!

Introducing Guilder

I’m announcing a fun part-time project I am starting called Guilder: The World of Warcraft Guild Management System. The project has just started so there isn’t any code yet, but it is a serious effort I am undertaking to both solve some problems of guild management and to learn more and more about Ruby on Rails.

Yes, the code will be Ruby on Rails. Why not Grails like I have been fond of? Well, mainly personal reasons. After spending time with both platforms, I really feel like the best fit for the web is Rails. Grails is quite derivative and doesn’t have as large a community behind it, plus personally I feel it has more elegance to it. So back to Rails I come, and find a familiar friend with open arms.

Guilder will be licensed under the MIT License, an OSI-approved open source license. Why did I choose the MIT license over something like the GNU GPL? The MIT license is very flexible and not as restrictive as some of the other open source licenses out there. I can link my code to commercial libraries, people can fork the code and sell it, and basically do whatever. I dig that type of openness.

Progress will probably be slow on this because like I said it is a part-time endeavor, but it is there and I will be working on it. If you are interested in helping, let me know.

Other ideas for web applications

I’m tossing around more ideas for web applications, just to see if there is anything I can really latch onto as a project to hone my ruby skills. One idea that came up arises from a need my World of Warcraft guild has for guild management. It would be awesome to be able to manage and maintain the following items in one application:

  • An updated roster, periodically synced from Blizzard’s Armory website
  • A forum for communication
  • A calendar for scheduling raids
  • An application with ability to manage what classes are needed for recruitment
  • Integration with WowJutsu for guild rankings
  • Integration with Wowhead for item links
  • Server status polling

That’s just a few use cases that I can think of off the top of my head, and really the list could be expanded upon to make it attractive to guilds/clans for a variety of games. Right now people have to spend money on services to provide this sort of thing for them, having an open source guild management system they can put on whatever webhost they want (as long as it supports Rails) would be awesome. I might consider this and start hacking away on it.

Giving up on dynamic languages

Faithful readers, the time has come for me to give up on dynamic languages all together. Utility, speed, innovation all leads to maintenance headaches down the road so it is time for me to pick up something tried and true. I talked with a good friend of mine, a Dr. Sloof Lirpa, head of the CS department at the University of Oklahoma, and he suggested something that blew my mind.

Yes, I am going to program solely in COBOL.

COBOL has been around for ages and has been time-tested in the enterprise. That’s what is important, right? Why change when COBOL worked just fine in business for our fathers?

But I can’t forget years of innovation that has happened since the advent of COBOL in the business. So to bring a bit of modern innovation to the world of COBOL, I found a great framework for developing applications: COBOL on Cogs. This will be a great way to develop code and make it enterprisey enough to land the Big Bucks!

Who is with me in this venture?

Ruby Hackery

I’ve had an idea for a quick one-off project that I can do easily with Ruby and deploy to my VPS server without much fuss. It involves looking at my friends and followers on Twitter, and showing me a list of people who follow me but I do not yet follow. I would implement it by using Net::HTTP to fetch the data and REXML to parse the XML feed (I could use json, but I am an XML guy and I totally love the REXML library now that I know how to use it effectively).

The idea is to help find people who are interesting in my Twitter social neighborhood that might be good to befriend. The problem with looking at just the unrequited followers is that a lot of those people are twitter spammers–people wanting me to follow them and click on their links. What an abuse!

So my idea is to look at my current friends, and get their friends list. Then I can compile a single list of say the top 10 people who show up on a majority of my friends’ lists that are not currently on mine. I can then show both lists along with their profile image, current status, and a link to their profile. Then I can choose to friend them or not. Each time I add a friend I would get better results!

I’d also like to take it a step further and find brand new people. I could try something with Twitter’s tracking feature where you get notified when someone posts a status update based on a certain keyword, but that gets spammy really quick and isn’t always the best way to find someone with similar interests. I’ll have to think about this particular problem for a while.

The only problem I see with this option is fetching the data for each user. The more friends lists I pull, the longer it takes, and the closer I come to exceeding Twitter’s rate limit. Ideally I could fetch all of my friend’s friends in one call, but right now as the API stands I would have to make one call per friends list. This means it will be hard to aggregate this data into something useful for this purpose. It’s just a small engineering problem that I’m sure I will resolve, even if I have to ask the Twitter guys for help or suggestions.

Steps Toward Social Convergence

I’m reading more and more about initiatives that are moving towards what I have been calling “social convergence”. The way I see it, social convergence is aggregating the assets from various online social mediums, and providing many views into that data. The views could potentially be a single page, or many. The important thing is that the assets have a relationship with each other.

But what are the assets? An asset could be a blog post, a tweet from twitter, an event shared in Pownce, an image uploaded in Flickr, a Facebook status update, and so on. You get the idea. It’s any content created on any social networking website.

Assets are more than that, though. Assets should include your identity: your image avatar (if any), your profile, and most importantly your friends. Your friends are what make social networks social, and not just a database of your own thoughts. It is vitally important that those carry on to different sources.

Consider how frustrating it is right now. I create an account on Twitter and make a bunch of friends . Now I create an account on Flickr or Digg and a majority of those people are on that service too. But now I have to remember to look them up, add them to my friend’s list, and hope they sign on and approve me as a friend for the millionth time.

Robert Scoble talked about this very same thing in a blog post on data portability:

When a new social network comes along (say your company turns one on this morning) I’d love it if it noticed that 15 of my friends who join up there are also on Twitter, etc. Why is that important? Because if there were some way to bind these social networks together they could do a lot more for you. For instance, I know that Scott Beale is on almost all of my social networks listed above. Why don’t the systems know that?

Thinking about this problem has made me realize that the problem of social convergence is a lot larger than just aggregating data feeds from various services into one location. At that point, it is just data. It isn’t meaningful and nor does it have any real context outside of the person the data is being aggregated for. To be really useful, all assets, especially friend data, needs to be propagated and shared from one participating service to the next.

One big issue I see is the question of authority. Who takes the lead on maintaining this data? Should we go the full-on Data Portability route and use OpenID along with other services? And at that point do you really know who controls your credentials and friend assets? And what happens if that central source is compromised? Having a single source of this data makes it very valuable to malicious people.

Maybe there is a good compromise that can meet security and privacy concerns while at the same time allowing our social networking converge to actually happen. Maybe authentication and authorization can be left in the hands of the individual service providers and each of those services can utilize a service to share the assets. But even doing that doesn’t address Scoble’s concerns about what happens when your authentication information (like an e-mail address) changes.

This is a difficult problem, and the person to come up with an elegant solution to converging our data in a secure and easy fashion will make quite a name for himself.

Thoughts of Grails and blog software

I’ve been thinking about Grails again. There’s a very easy-to-use Grails plugin for creating RSS feeds (and Atom, and a lot more) for your application. I was surprised at just how easy it was to start from scratch and create an RSS feed from your existing domain model.

Seeing how easy using that plugin is, it made me want to revisit the idea of rebuilding this weblog as a complete Grails webapp instead of relying on Wordpress for everything. Nothing against Wordpress at all–it is an excellent blogging tool–but there’s something to be said about rolling your own and getting it to work. Call it a pride thing, or even just plain and simple hubris.

I’d have to consider a host of features that I currently rely on Wordpress to implement for me: posts (obviously), categories, tags, comments, spam filtering, RPC for remote posting via ScribeFire, RSS feeds for posts and comments, integration with Twitter, easy-to-use design templates, and so on. The list is huge when you look at it.

At the same time, if I write my own blog software, I want it to be full yet not over-flowing with options that it turns people off. I need to think about what a blogger needs from blog software and start from there. I can build up a set of basic requirements and start there. For instance, I’m wanting to aggregate a lot of my current points of presence on the web. It’d be nice to be able to go to one place and be able to update all locations, such as Twitter, Facebook, and LinkedIn. Should I include support for RDF? OpenSocial? True restful web services for publication?

It’s a lot to think on.

Inform: Writing Interactive Fiction Games

If you have been a computer gamer for any large length of time, you probably have stumbled across the genre of games noted as “interactive fiction”. Games such as the ever-popular Zork are text-based (meaning you have to use your imagination, kiddies). Usually you are given a bit of exposition, a description of your current scenery, and then you are prompted with a command line.

The commands you issue are pretty much natural language. For example, if you see that there is a trophy inside of a trophy case and you want to get it, you might issue the following commands:

open case
get trophy

Recently I have discovered that there is a large semi-underground pool of people still developing these type of games, even amidst the surge of 3D shooters and MMORPGs. And some of the development environments are astonishingly descriptive and easy to use.

As I started browsing the world of interactive fiction, it didn’t take long for me to stumble across Inform, which is a design system for games. The latest version (Inform 7) utilizes a domain-specific language (DSL) that allows you to create a game in plain English. The syntax is so fluid that you only need a basic set of documentation to get going and you can intuit a lot of the commands that are available. Even so, the documentation and examples provided in the system are incredibly verbose, detailed, and helpful.

Inform is an object-oriented language to some extents. The base object is a “thing” and you can create “things” to populate your game world with. Here is an example I came up with:

[code]Heat is a kind of value. The heats are cold, cool, room temperature, and warm.

A beverage is a kind of thing. A beverage can be openable or unopenable. A beverage is always edible and openable. A beverage has heat. A beverage is usually cold. A beverage can be full, partly drained, or empty. A beverage is usually full.[/code]

First off I define what is basically a set of values (like an Enumeration in Java) to describe heat. Then I construct a beverage object by saying it is “a kind of thing”. Then I assign attributes to it, such as making it a container, making it edible, giving it a heat attribute, etc.

You can also create methods for your beverage, such as handling drinking the beverage:

[code]Instead of drinking a beverage when a beverage is empty:
say “There is no more! You drank it all!”

Instead of drinking a beverage: if the beverage is partly drained, change the beverage condition to empty; if the beverage is full, change the beverage condition to partly drained; say “You drink a long draught. Refreshing!”[/code]

This uses the phrase “instead of” to override the default behavior for a thing whenever the player tries to issue the “drink” action. With this in place, you can drink a beverage until it is empty, then you will be told “There is no more! You drank it all!”

With a beverage object in hand, you can now easily “instantiate” a beverage it by saying simply:

The Mug of Ale is a beverage.

To see the expresiveness of this language, here is a complete example:

[code]”Example” by “Tim Gourley”.

The story headline is “This is an interactive example”.

Part 1 - Objects

Chapter 1 - Definition of some basic objects

Heat is a kind of value. The heats are cold, cool, room temperature, and warm.

A beverage is a kind of thing. A beverage can be openable or unopenable. A beverage is always edible and openable. A beverage has heat. A beverage is usually cold. A beverage can be full, partly drained, or empty. A beverage is usually full.

Instead of drinking a beverage when a beverage is empty:
say “There is no more! You drank it all!”

Instead of drinking a beverage: if the beverage is partly drained, change the beverage condition to empty; if the beverage is full, change the beverage condition to partly drained; say “You drink a long draught. Refreshing!”

After printing the name of a beverage: say ” ([beverage condition])”

Before printing the name of a beverage (called the drink):
say “[heat of the drink] “

Part 2 - The Game World

Chapter 1 - Inside The Tavern

The Tavern is a room. “Before you is a bustling tavern with people going to and fro. The atmosphere reminds you of home and you are quite at ease. Apparently, there are no exits so you must remain here forever.”

The Mug of Ale is in the Tavern. The Mug of Ale is a beverage.[/code]

Now I can compile this code in Inform 7, which will produce “Z-machine” code and can be run with any interpreter, such as the frotz interpreter. Here is what the game looks like when run:

Example
This is an interactive example by Tim Gourley
Release 1 / Serial number 070806 / Inform 7 build
4U65 (I6/v6.31 lib 6/11N) SD

Tavern
Before you is a bustling tavern with people going to
and fro. The atmosphere reminds you of home and
you are quite at ease. Apparently, there are no exits
so you must remain here forever.

You can see a cold Mug of Ale (full) here.

>get mug
Taken.

>drink mug
You drink a long draught. Refreshing!

>drink mug
You drink a long draught. Refreshing!

>drink mug
There is no more! You drank it all!

>

Very interesting, wouldn’t you say?

World of Warcraft and RESTful web services

REST web services are a pretty popular topic right now and a lot of people are seeing how easy it is to take advantage of them as opposed to other technologies such as SOAP. REST web services are the heart of the web: using HTTP to send messages back and forth without any additional messaging layers like SOAP envelopes. Instead you use the verbs present in the URI and the already existing HTTP methods (GET, POST, PUT, and DELETE).

Most of the web services you can find on the web can be considered nearly-RESTful or REST-like (or GETful as Scott Davis likes to call them). Why is this? Its because they have latched on to the GET method to provide data, but they haven’t even considered touching the other methods. This is a perfectly fine and valid approach; a lot of the time you are just wanting to get data for some purpose (like a Mashup with Google Maps or something) instead of updating data.

Did you know that REST-like web services are all around you? Would it be surprising to know that video-game giant Blizzard has provided such a service (whether they know it or not)? Recently Blizzard created the Armory tool for their mega-hit game World of Warcraft. It allows you to search for character data across their realms and see data such as items, professions, skill levels, reputation, and so on for every character in the game. It is a powerful tool if you ask me.

For example, look at the Armory profile for Bratta, my main character. You can see all sorts of statistics like the fact that I need to get off my butt and get some better gear. The site itself is a very pretty Web 2.0 site using a lot of cool technologies. The interesting part, however, is that the page itself is just an XML file that uses an XSL to transform the data into the HTML we see on the site.

What does this mean? We make a request with some verbs in the URI (r for the realm, n for the character name in the case of character-sheet.xml) and you get back XML containing the relevant data. It’s just a web service!

In fact, the XML you get (before the magical pixies sprinkle the XSLT all over it) looks something like this:


<page>
<characterInfo>
<character name="Bratta" race="Gnome" class="Warlock" level="70"> />
<characterTab>
<professions>
<skill name="Enchanting" value="176" max="225" />
<skill name="Tailoring" value="365" max="375" />
</professions>
</characterTab>
</characterInfo>
</page>

Yes, that is dramatically over-simplified, but you get the picture. We just have raw data from the web service, which means if we are clever enough we can use this to our benefit and capture this data in our own applications.

So let’s pretend we are interested in obtaining information on the primary professions of a character. We could easily build up a Groovy script to harvest that information.

Let’s define our URL. The URL needs to be encoded properly, so spaces need to be translated to +.

def characterUrl = "http://www.armory.worldofwarcraft.com/character-sheet.xml?r=Dark+Iron&n=Bratta"

Now let’s open a connection to the website. Normally we could skip this step and use XmlParser().parse(url) but in this case we are forced to change the User-Agent, because the Armory is doing a bit of browser detection.

// Use the User-Agent from a recent version of Firefox
def userAgent = “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4″
URLConnection uc = new URL(characterUrl).openConnection()
uc.setRequestProperty(”User-Agent”, userAgent)

Now that we have a connection, let’s parse the XML. In Groovy this becomes one line of code:

def characterXml = new XmlParser().parseText(uc.inputStream.text)

We can now walk the DOM and get our skills. Normally you’d have to worry about child nodes, node types, and other such craziness, but with the magic of groovy, you can walk the DOM as if each element were properties of a parent object:

def skills = characterXml.characterInfo.characterTab.professions.skill

That returns us a list of our skill tags inside the profession element (see the XML example above). Now we can iterate over the skills and get the data using GPath (Groovy’s version of XPath):

skills.each { skill ->
def skillName = skill.’@name’ // The ‘@’ denotes an attribute of the element
def skillLevel = skill.’@value’
def skillMax = skill.’@max’
println “Bratta has profession $skillName at skill level $skillLevel/$skillMax”
}

And that’s all there is to it! Ideally you would want to add the profession to some sort of a bean object and add each bean object onto a list and return the list, but you get the idea.

From here you can see how easy it is to get this information. There are many ways you could go from here. You could query the guild-info.xml to get the names of all the members of your guild, then get the professions for each of those members and store that info in your own XML document or a database. Then you could build a web interface for your guild to query that data to find out who has a particular profession. The possibilities are limitless!