Twitter Weekly Updates for 2011-03-13

Posted in Twitter on March 13th, 2011 by Jamie – Be the first to comment

Twitter Weekly Updates for 2011-03-06

Posted in Twitter on March 6th, 2011 by Jamie – Be the first to comment

SQL Server Stem Words

Posted in Troubleshooting on February 28th, 2011 by Jamie – Be the first to comment

We needed to find related words using the SQL Server FORMSOF function. Although it is used mainly to find related words in bodies of text, we wanted to use it to find related words in a table of just words. Initial approaches focused on finding a SQL Function or table that contained the database of related words. This turned out to be a dead end.

We decided a clever approach would be to iterate through each row of the table, using it to query all the rows. This would create groupings of words that could be used to tie them together, via a common group ID.

Although a better solution may have been to use a indexing engine such as Lucene to generate the correspondences, we were already using SQL Server’s functions.

Twitter Weekly Updates for 2011-02-27

Posted in Twitter on February 27th, 2011 by Jamie – Be the first to comment

Regex Challenge

Posted in Troubleshooting on February 25th, 2011 by Jamie – Be the first to comment

A friend asked for a regex that matches a paragraph that contains only upper-case text inside a nested hierarchy of tags. Some examples:

Matches:


<p class="abcdefg"><a href="1.htm"><span>HELLO THERE</span></a></p>
<p class="c8"><span class="c7">BY ERIC D. JAMES, MD</span></p>
<p style="border:1px solid red">HELLO DARLING</p>

Fail:


<p class="c8"><span class="c7">BY Eric James, MD</span></p>
<p style="border:1px solid red">Hello Darling</p>
<p class="abcdefg"><a href="1.htm"><span>HELLO THeRE</span></a></p>

I came up with the following expression:

/<p[^>]*>(<[^>]*>)*[^a-z<]+(<\/[^p][^>]*>)*<\/p[^>]*>/

It doesn’t handle tags interspersed with text or nested paragraph tags.

Here’s a sample on Rubular.

Twitter Weekly Updates for 2011-02-20

Posted in Twitter on February 20th, 2011 by Jamie – Be the first to comment

Custom Magic the Gathering Cards

Posted in Crafts on February 15th, 2011 by Jamie – Be the first to comment

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

Posted in Libraries on February 14th, 2011 by Jamie – Be the first to comment

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

Posted in Troubleshooting on February 7th, 2011 by Jamie – 1 Comment

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.

Twitter Weekly Updates for 2011-02-06

Posted in Twitter on February 6th, 2011 by Jamie – Be the first to comment

Switch to our mobile site