Gamepads.js v0.2 Released

After becoming a bit frustrated with the current HTML 5 gamepad/controller support and libraries, I decided I needed to make something that worked well for what I was doing.  What I have put together so far, I just released as Gamepads.js.  It is still pretty early in development and rough around the edges, but is to a point now where I have started dogfooding the project.  Right now it works only in Chrome, which I am fine with as it is the only browser that in my opinion truly supports gamepads at the moment.  Next up is Firefox support, which is the only other browser that even attempts support at this point.

A Game in 13 Kilobytes

Back in September, I submitted an entry for the js13kGames competition. This is a new competition that reminds us that the internet is best when it does not take that much time to load something. It definitely was a chore, but also a great learning experience.

I created At Sea. It is a fishing game (of sorts) where you are thrust into the ocean and must survive to fish another day. It was a great concept that I would like to revisit someday. Having finished 8th out of the 61 entries maybe I was starting to get onto something. The version that is on my website is actually a bit larger than the original 13 kilobyte entry, but also plays in more browsers. If you are curious and are not using Internet Explorer, you can also check out the original contest entry of At Sea. Source code is available on my GitHub repository for the project.

Yahoo API OAuth in C# for Desktop/Mobile

Yahoo has a pretty great API for their Fantasy Sports (Football, Baseball, etc.) services all behind HTTP endpoints authenticated via OAuth. The Yahoo API has great examples to show how to connect with a PHP web application to their APIs, but not much for mobile and desktop applications. Luckily, the OAuth specification goes into enough detail use the out-of-band (oob) configuration. The other snag was finding an OAuth library that just got out of the way. In my opinion, this is just using the built-in support for OAuth that comes with Hammock.

The Yahoo OAuth documentation states that whatever browser the request authorization is shown it also have an address bar, so the user knows that they are at the Yahoo site. This means the application really should spin up a new web browser and display the web page and not show it in an embedded web browser control. The user will then have to copy-and-paste the code back into your application.

Parse HTML with CSS selectors using Fizzler and FizzlerEx

When I am parsing HTML documents, I try my best to make use of CSS selectors to grab the content that I want. It is not always possible depending on language support, but it is much more friendlier than using XPath, which I tend to only use once every couple of months. I recently started playing around with a .NET library that accomplishes this called Fizzler, which piggy backs off the HtmlAgilityPack library. While it has great selector support, it hasn’t been updated since 2009. Luckily there is a fork of it called FizzlerEx, which has picked up the slack adding selectors like “:not(foo)” and “:contains(‘text’)”.

A great example of how this makes your life easier (especially if you are still parsing HTML with regular expressions) is by taking a look at parsing the rather nasty Discovery Channel TV listings. To grab the show name and time information the following simple LINQ is all that is needed.

Programmatically Shelve Your TFS Pending Changes

There’s a great TFS Auto Shelve Visual Studio tool that will magically autoshelve your pending changes every X minutes. It’s very handy, but what if you wanted to extend it with more features? Here’s a little code snippet to help you get started that will shelve your pending changes for a specific workspace.

using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

var tfsUrl = "http://myserver:8080/whatever";
string userName = "MyName";
string workspaceName = "MyWorkspace";

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

var workspace = vcs.GetWorkspace(
    workspaceName,              // workspaceName
    userName);                  // workspaceOwner

// Query for Latest Pending Changes
var pendingSets = vcs.QueryPendingSets(
    new[] { "$/" },             // items
    RecursionType.Full,         // recursion
    workspaceName,              // queryWorkspaceName
    userName);                  // queryUserName
var latestPendingChanges = pendingSets.First().PendingChanges;

if (latestPendingChanges.Length > 0)
    // Create and Save a Shelve set
    var shelveset = new Shelveset(
        "My Shelveset",             // shelveset name
        workspace.OwnerName);       // shelveset owner
        shelveset,                  // shelveset
        latestPendingChanges,       // changes
        ShelvingOptions.Replace);   // options

Remember that you may need to add the name of your project collection as a folder to the end of your TFS url.

Tips for a Good Programming Presentation

Twin Cities Code Camp was this weekend and I was lucky enough to attend on Sunday.  It was great, but there are a few things that people really should do before they ever give a presentation.

  1. Reset your IDE back to “factory defaults” and disable all add-ons.  This includes themes and colors.  There is nothing worse than trying to read a color scheme that does not play well with a projector.
  2. Have at least a few PowerPoint slides… always.  Purchase a clicker.
  3. Give your monitor a reasonable resolution and ensure your font size is set appropriately.  Avoid zooming in excessively due to your failure to comply with this rule.
  4. Do not live code.  Unless it’s very, very tiny snippets.  It’s not fun watching people type away, and you will make mistakes.  Use snippets if you want the illusion of building out the system.
  5. Run through it at least once in final form as it will be presented to everyone who attends.

Using CouchDB with .NET Beginner’s Guide – Part 1

Why CouchDB and Cloudant?

After playing around with a little project that required a lot of “document” retrieval from a database, I decided to try one of the hosted NoSQL options that are out there.  I decided to try Cloudant, a cloud-based CouchDB host that has add-ons for both Heroku and AppHarbor.

Why Cloudant?  I was looking for something in the cloud, free and not constrained by too much of a size issue.  The choice between MongoDB and CouchDB came down to what would be less of a hassle. Cloudant is officially supported by AppHarbor, so that was my ultimate choice.  At this point, you should create yourself a free Cloudant account.

Interacting with the Database

It is very easy to interact with the database as CouchDB is REST based, so standard HTTP calls can be made to perform CRUD operations.  Divan is a popular .NET wrapper that will be used instead of hand crafting the calls to the CouchDB server. To get started, a reference to the Divan project will be needed in the website project.

  1. From Visual Studio 2010, choose “File” -> “Add” -> “Existing Project” from the menu bar.
  2. In the “Add Existing Project” dialog box navigate to the location of the Divan “src” folder and open Divan.csproj.
  3. Upgrade the Divan project to .NET Framework 4.0 by right-clicking on the Divan project in Solution Explorer and choosing Properties.  From here change the “Application” tab’s “Target Framework” option from .NET Framework 3.5 to .NET Framework 4.0.
  4. Remove the Newtonsoft.Json reference under the “References” folder because we will need to upgrade the Json.NET reference from .NET 3.5 to .NET 4.0, so both our website project and Divan project are in sync. (This won’t be that important until Part 2)
  5. Using either the internet or NuGet to reference Json.NET 4.0.x (or later).
    • In NuGet, this can be done by right-clicking on “References” and selecting “Manage NuGet Packages”.
    • Select the “Online” tab and search for “Json.NET”.
    • Once “Json.NET” is located. Select it from the list and click the “Install” button.
  6. Finally, right-click the website’s “References” and under “Projects” add the Divan project.

With project setup complete, it is now time to create and query a Cloudant database. In order to do this, a CouchServer object will be created to store the server connection information and perform a call to create/get a database.  For this example, the trivial example of a database called “people” that stores “firstName” and “lastName” will be used. Ensure that the Divan namespace is resolved in the file that you are creating this code (right-click “Resolve” on the squiggly lines under CouchServer).

CouchServer server = new CouchServer("", 5984, "INSERTUSERNAME", "INSERTPASSWORD");
ICouchDatabase database = server.GetDatabase("people");

In the above example, remember to insert your username and password.  After digging in Cloudant’s FAQ, it can be found that Cloudant runs their servers on port 5984. The final interesting thing to note with the above code sample is that the GetDatabase call will create the database if a database with that name is not found on the server.

With the database in hand, it is time to create a document on the server and call it a day.  CouchDB is Json based. Creation of documents can be done by specifying an object to be serialized or hand supplying the Json. For simplicity, the latter will be done.

ICouchDocument doc1 = database.CreateDocument("{\"firstName\": \"Scott\", \"lastName\": \"Heckel\"}");
ICouchDocument doc2 = database.GetDocument(doc1.Id);

All CouchDB documents have Id and Rev(ision) properties.  These properties are used to identify specific documents. While the Id was supplied directly in the Json, CouchDB provided the Id for the document automatically. With the help of that Id, the program is able to retrieve the document that was just created.

A great start! Part 2 will show how to improve the code by creating custom objects that implement ICouchDocument.

Netduino Morse Code

It has been five months since I last got to tinker with my Netduino.  I have not purchased any new shields or accessories, but I wanted to get back on the horse.  I figured the easiest way to toy with it would be to go to the ever trusty Morse code project that has been done already to death already.  I took a fluent-like take on the project and posted the code to my GitHub under “NetDuino-MorseCode”.  It’s small, simple and works.

Your Language… Sucks!

After careful research, I have discovered that PHP is quite possibly the worst language ever (* based on the smallest of small sampling sizes). Using the scientific query of “X sucks”, I tabulated which language has the most hits on Google.

Chart showing that PHP is the worst language ever!

If this isn’t definitive proof, I don’t know what is.  In case you were wondering, “erlang sucks” racks up a whopping 59,100 hits.

MIX PlayOn Script Released

A little over a week ago, I released my second PlayOn script.  This time it is a PlayOn script for Microsoft’s MIX conference.  It provides a look into the future of the web and all related technologies.  The script currently supports MIX 2010 videos; however, I will be adding in support for the back-catalog soon.  As always, the script comes with auto-update support out of the box.  In case you still are wondering what MIX is, I will leave you with my script’s description.

Discover the next web with presentations from Microsoft’s MIX conference. MIX is a gathering of developers, designers, UX experts and business professionals creating the most innovative and profitable consumer sites on the web. Sessions range from technical, code-based topics to expert advice on content strategy, usability and design.