Twitter Weekly Updates for 2011-02-20

Custom Magic the Gathering Cards

For a friend’s birthday in 2004, we made him Magic the Gathering cards. I got a lot of help from an online forum, misetings.com, which I think became misetings.net and now http://forums.goodgamery.com/. I made an entry back in 2004 about the birthday, and recently updated the link to the cards. The trickiest thing was finding a good template (and modifying it) and spending time to edit some of the more complicated pictures. The flavor text and card abilities were really fun to write.

Dominos-Style Game

My wife loves PopCap’s game Alchemy. It’s a dominoes-like game, where you match up alchemic symbols and various colors. The object of the game is to turn each board-square from lead to gold. I have been wanting to try out the limejs game library, which is based on Google’s Closure compiler, so I decided to write a quick implementation of the game. You can find the source on Github.

You can try out the game online. To play, place pieces adjacent to other pieces which match in symbol or color. A placed piece must match all the pieces adjacent to it. A wild card piece, denoted with the ‘*’ symbol, matches all pieces. Filling a row or column with pieces will mark the corresponding spaces as cleared. The object of the game is to get each space marked as cleared.

Edit (20100214 11:00 PM): Added win condition and box showing how many spaces cleared.
Edit (20100215 11:00 PM): Added leveling. The board starts small with few pieces and keeps getting bigger with each round.

Adding comments to spreadsheets with POI

I was just recently working on a project using NPOI, the .NET equivalent of POI, which is a great library for writing Microsoft Office documents. I was using HSSF, it’s spreadsheet library (Horrible Spreadsheet Format according to Google), and attempting to add Comments to cells.

At first I thought it wasn’t working at all. Then I noticed there was a single cell that had the little red marker that tells you there is a comment. After a little debugging, I realized that this was the last comment added, and guessed that I was doing something to clear the comments I created with each loop iteration.

The block of code that creates comments is something like:

HSSFCell cell //...
// ...
HSSFPatriarch patr = sheet.CreateDrawingPatriarch(); // should only be called once
HSSFComment hssfComment = (HSSFComment) patr.CreateCellComment(
    new HSSFClientAnchor(0, 0, 0, 0,
    cell.ColumnIndex, cell.RowIndex, // start cell index (for size)
    cell.ColumnIndex+4, cell.RowIndex+6) // end cell index (for size)
    );
hssfComment.String = new HSSFRichTextString("Comment text");
cell.CellComment = hssfComment;

Unfortunately I had been creating the drawing patriarch in each loop. I didn’t realize it should be a top-level container for the comments. So make sure to not re-create the drawing patriarch.

Weird Sammy + jQuery on IE error

Here’s a post that might help problems with Sammy routes, callbacks, and event handlers using jQuery, especially the “live” function.

I have an input form with submit buttons like:

<form>
<input type="submit" name="what" value="SomeCommand" />
<input type="submit" name="what" value="DifferentCommand" />
</form>

This didn’t play well with Sammy, as it doesn’t load the value of what into it’s params hash. So, I did a work around like:

  // hack to allow sammy to access the 'what' param
  $('form input[type=submit]').live('click', function(){
    var submit = $(this),
      form = submit.parents('form');
    form.find('input[name=what][type=hidden]').val(submit.val());
  });

I’m not sure why I originally chose to use “live.” It could’ve been that I was building DOM dynamically using jquery-tmpl. In Firefox and Chrome, this worked as expected. In IE, the Sammy route handler would fire before the click handler above! So, I changed the code to use the non-live version.

  $('form input[type=submit]').click(function(){ // changed
    ...
  });

Twitter Weekly Updates for 2011-01-23

Twitter Weekly Updates for 2011-01-16

Innovation Tournament

This week I was in San Francisco participating in a Wharton class about innovation. We had a week to sort through various ideas for web products and create a prototype. I worked on two projects. One is a lottery site, with a simple demo available. I got to use the Youtube API for playing a video and then performing some action upon completion. It was  a little clunky to get setup, but afterwards worked flawlessly.

The other was an idea for a social dashboard for restaurants to keep them up to date with the latest reviews on sites like FourSquare and Yelp. I worked with a great programmer named Sean, who worked mostly on integrating the 3rd-party APIs. It was a Rails app that we pushed to Heroku.