Alieniloquent


Exposing .NET code in a DLL via C++

December 31, 2006

At my work, we do both Delphi for Win32 and .NET. Most of our .NET coding is in C#, though, so we can’t just cross-compile. We have a number of .NET components that would be nice to use on the Win32 side (such as zip libraries), and we know its supposed to be possible, but none of us have ever gotten into the nitty gritty of actually doing it. Now, programming for Windows isn’t my favorite thing in the world. But, I do love a good technical challenge. Especially one that requires me to dust off a language I haven’t used in a while. This will be the first of a few articles documenting the things I’m learning from doing this.

The strategy that I’ll be using is to write a DLL in C++ that will allow the Delphi code to call into the .NET code. Microsoft’s C++ allows you to mix unmanaged and managed code fairly easily, so it makes for a very good glue layer in situations like this.

So, to start off, let’s make the Visual Studio project for the DLL. I’m using Visual Studio 2005 for this, and I’ll use the C++ CLR template entitled “Class Library.” I’ll give it a name “Example” and hit go. This makes most of the files that you need. Delete the class that it creates (“Class1”) and make a new one like this:

// Example.h
#include <vcclr.h>

#pragma once

using namespace System;

namespace Example {
  public class Example1
  {
  public:

    Example1(const char * name)
      {
        _name = gcnew String(name);
      }

    ~Example1()
      {
      }

    void ShowName();

  private:

    gcroot<String ^> _name;
  };
}

A couple things to note about the above code. The Example1 class is an unmanaged class, but the _name field is a managed object. The gcroot class takes care of telling the garbage collector about the managed string object.

Next, we need to export some DLL functions so that we can call them from Delphi:

// Exports.h
#define DLLAPI extern "C" __declspec(dllexport)
DLLAPI void * Example1Create(const char * name);
DLLAPI void Example1Delete(void * example);
DLLAPI void Example1ShowName(void * example);

The important thing to notice here is the DLLAPI define. You need to put it before each function you want to export. We have to extern the functions as C-style functions so that their names don’t get mangled in the symbol table.

// Exports.cpp
#include "stdafx.h"
#include "Example.h"
#include "Exports.h"

using namespace Example;

#define E1(p) ((Example1 *) p)

DLLAPI void * Example1Create(const char * name)
{
  return new Example1(name);
}

DLLAPI void Example1Delete(void * example)
{
  delete example;
}

DLLAPI void Example1ShowName(void * example)
{
  E1(example)->ShowName();
}

Note the macro defined to do the cast. We only have to do the cast in one place right now, but as you expose more methods on the object, you’ll have to cast for every one. The macro makes it easier.

So to summarize what we have so far. In the DLL we have an unmanaged class which can access the managed classes in .NET. Then we expose functions which can create instances, destroy them, and call methods on them. These return pointers which the caller must manage. The pointers are passed into all of the functions which invoke methods, and those functions cast and then call.

In my next post I’ll show how to consume this DLL from Delphi.

"Movie Reviews: All the King's Men"

September 21, 2006

When I first saw the trailer for this movie, I didn’t think I’d ever see it. The story didn’t seem like the kind I tend to enjoy. But, when a friend of mine offered to give me some free tickets I figured it was worth seeing for free, and it’s a good thing I did. This way I can tell you about how terrible the movie is, and hopefully save you some cash.

The budget for the film was $55 million. A fairly small budget by Hollywood standards, but in the same range as the last three films I saw: The Covenant ($20 million), Snakes on a Plane ($36 million), World Trade Center ($65 million). I liked all of those films, but I didn’t like this one, and I think it really comes down to how the budget was spent.

Two places the producers clearly did not spend their budget was on cinematography or editing. In no fewer than four scenes I saw the head of a boom mic bouncing along the top of the screen, and in one scene I saw the mic and its boom in their entirety. This isn’t like a car in Lord of the Rings. This is just shoddy movie-making.

Another place they clearly did not spend their money was writing. I’m sure that the book this movie was based on was a fine novel. I know there was a real story about Huey Long, whom this story is loosely about. Somehow, though, the writers for this film failed to caputre any real plot. None. None at all.

I think where they spent almost all their money was on casting. The movie had an amazing cast: Sir Anthony Hopkins, Jude Law, Kate Blanchett, Mark Ruffalo, Sean Penn, and James Gandolfini. Those are some big names, and I’m sure they all had nice fat paychecks for their performances. The performances were even decent, although Penn summoned memories of Snatch with his thick, unintelligible accent.

So, if you want to play spot-the-mic, or want to see if you can find the plot, go see this movie. But, if you want to enjoy the two hours you’ll spend watching it, go do something else.

Drawing graphs and automata in LaTeX

September 21, 2006

I am currently enrolled in a class entitled “Automata, Computability, and Formal Languages” at UNO. It’s a neat class. The professor requires us to submit our homework in both hard and soft copies. Naturally, he suggests we use LaTeX to typeset our homework.

Given that this is a class on automata, I end up drawing a lot of state diagrams to represent the machines I have to design for the problems. I wanted a nice way to draw these and put them in to my LaTeX document. The first thing I did was check to see if OmniGraffle exported to EPS, and it did. LaTeX can read EPS, so I was okay if I couldn’t find anything better.

With a solution in hand, I started to look and see if there was anything I could use to typeset these graphs right in the LaTeX source itself. Preferably something designed for drawing finite state-machines, even. What I found was GasTeX. It is a decently cool package.

The following source code from their samples page:

\begin{figure}[H]
  \begin{center}
    \unitlength=4pt
    \begin{picture}(15, 28)(0,-10)
    \gasset{Nw=5,Nh=5,Nmr=2.5,curvedepth=3}
    \thinlines
    \node(A0)(7.5,0){$0$}
    \node[Nmarks=i,iangle=90](A1)(0,13){$1$}
    \node[Nmarks=if,iangle=90,fangle=90](A2)(15,13){$2$}
    \drawloop[loopangle=180](A1){$a$}
    \drawloop[loopangle=0](A2){$b$}
    \drawedge(A1,A2){$a$}
    \drawedge(A2,A1){$b$}
    \drawedge(A2,A0){$a$}
    \gasset{curvedepth=-3}
    \drawedge[ELside=r](A1,A0){$b$}
    \drawloop[loopangle=270](A0){$a, b$}
    \end{picture}
  \end{center}
  \caption{La complétion de l'automate.}
\end{figure}

Generates this graph (which I have scaled down):

Example of GasTeX output

Example of GasTeX output

One note about this snippet, though, is that I did not have to use the center environment to center the figures. Instead I used the \centering directive inside my figure environment, and that worked nicely.

It’s nice to use and it makes pretty graphs. I’ll be using it for the rest of the semester, that’s for sure!

Making Active Directory liveable for Linux

September 14, 2006

So my employer’s network is a Windows network. This isn’t terribly unusual. Our department’s version control server, however, is a Linux box. We didn’t want to have to have more than one password, so back when I set it up, I took the time to figure out how to get it to authenticate to Active Directory for us. It’s really cool, actually. Samba is really awesome.

However, we have had a few problems. The thing is that every so often, our Linux server was being removed from the Windows domain. So then we couldn’t authenticate users, and so we couldn’t check out our source code. Obviously, that causes problems.

It turns out that adding one line to the [global] section of my smb.conf file is what is needed to solve the problem. See, the Windows boxes check in with the Active Directory controller once a day to update their machine ID. My server was not doing this. I’ve found, over time, that there are a lot of options for making Samba play well in a Windows network that aren’t really defaulted like they should be. Below is what I added to make it update like the others.

machine password timeout = 86400 # one day

Another interesting thing, was that despite my not telling it to, Samba was advertising the machine as a domain controller. So I had to add the line below to disable that (despite the docs saying I shouldn’t have to).

domain master = no

In addition to the rest of the configuration for Samba to work with Active Directory, and I think we may finally have it working all the way.

Podcast

September 4, 2006

So I decided to start a pod cast. Check it out: The Agile Mac.

J3Testing 1.0

September 1, 2006

I decided to make my J3TestCase code into an actual framework. This way I don’t have to copy the files each time I want to use the class.

I’ve put up a disk image with binaries and one with source.

The source is worth looking at, especially to see how I made targets to automatically build those disk images.

These replace the old J3TestCase code I had posted, and I’ve removed that tarball. So, sorry if I broke that link. This is a much better way to deploy anyway.

Edited: I am no longer providing the disk images mentioned above, so I’ve removed the hyperlinks.

Quirky Behavior in String#gsub

August 31, 2006

At my office I develop in Delphi. We use Delphi 2006. As far as IDEs go, it’s not that great. For example, when you tell the Delphi 2006 IDE to do a build all (something you’d think developers do quite frequently), it has a very annoying behavior: it eats up scads of memory. In fact when the build all operation completes on our project group, Delphi has laid claim to over 1GB of memory, and it won’t let it go until you quit the application. But, this post isn’t about Delphi or its buggy IDE. It’s about ruby. More specifically, it’s about a quirk (read: bug) in ruby.

The String class in ruby has a method called gsub. This method takes two parameters and each can take two types of object. The first parameter can either be a Regexp or a String, and it represents what is to be replaced. The second can either be a String or a block, and supplies the value with which to replace it. This seems perfectly natural.

Now, if you’ve ever used regular expressions, you probably know about back- references. When you use the grouping operator in a regular expression (e.g. ^a(ab)b$) it stores a numbered back-reference to the matched value of each group. In ruby you can reference these with the special variables $1, $2, and so on. But, if you are passing a string as the replacement, it will only be interpolated once and those back-references won’t be correct. So, what gsub does is let you put in \1 and \2 instead.

That behavior is awesome, and exactly what you want, if you’re matching a regular expression. But if you’re just matching a string literal, there is absolutely no reason to do it. In fact, if all you’re doing is matching a string literal those back-references will all be the empty string.

So, how do I know all this? Well, because Delphi 2006’s build all operation bites, we wrote a ruby script to replace it. This script has to do file-name manipulation and all sorts of other string manipulation in order to get all of the correct compiler options. One of the things it does is replace strings like $(CodeBase) with a path such as c:\svn\trunk. Well, we have separate code bases for our branches, and they have names like c:\svn\2006. You see that \2 there? Yeah, that one, right in the middle of the path. Even though the script was matching a string literal, gsub was replacing back- references. Since the path happened to have a \2 in it, it would end up coming out of gsub as c:\svn006, and that certainly wasn’t right.

Thankfully, there is a simple work around. Instead of providing a string for the replacement, we can provide a block. That block gets called every time and the value that it returns is exactly what gets used as the replacement.

"YAGNI: byte-order conversion explained"

August 30, 2006

In my previous post I talked about this problem I ran into with byte- ordering and tests failing. Brian and Joe both felt that I left them hanging by going into all the technical details of what my problem was and not going into the technical details of why I shouldn’t have used htons to start with. Rather than editing the other post, here’s a new one.

The code that I was using htons in was my SOCKS5 implementation. For those who aren’t familiar with SOCKS5, it is a proxying protocol. The computer connects to the proxy and sends it a hostname and port for the actual connection. The proxy then makes the connection and relays packets for the remainder of the session.

Some of you may be guessing what I was calling htons on already: the port to be serialized. Here are the two offending lines of code:

[buffer append:(0xFF00 & htons(port)) >> 8];
[buffer append:(0x00FF & htons(port))];

That buffer was then, in turn, written out across the socket to the server (or inspected by unit tests). But, since I was extracting each byte individually the byte-order didn’t matter since 0xFF00 will be in the same byte order as port every time.

I hope this explains things a little better.

Regular Periodical Content

August 30, 2006

So I’ve been thinking about starting some sort of periodic content: perhaps a regular themed article here or a podcast. I would like to take advantage of what readers I do have to see what people would like to hear me talk about.

Here are some topics that I’ve thought about doing:

  • Things about programming they don’t teach you in college

  • Agile methods

  • Test-first design

  • Refactoring

  • Cocoa programming

  • Ruby programming

  • Lisp programming

There’s no particular order to those, as I find them all very interesting. It’s possible that I could end up doing a mishmash of all of them.

Please leave a comment with a topic you’d like to hear me talk about!

"YAGNI: byte-order conversion"

August 29, 2006

So I have this project, and it compiles for the Mac on both PPC and i386 architectures. Naturally, I have unit tests for this project.

One of the things that I’ve had to write for this is a simple SOCKS5 implementation (because of issues with Apple’s implementation). As part of this I had to do some manipulation of a port number and get the high and low bytes.

I’ve done this sort of thing before. That’s what htons and friends are for. So naturally, I went ahead and put this in where I thought it mattered and went on my merry way. On my ppc powerbook, my tests all passed.

Yesterday, when I ran the unit tests on my intel mac for the first time, I discovered that a test failed. It was failing because of some byte-order problem. After troubleshooting it, I narrowed it down to the htons calls. It turns out I did not need them.

See the thing is, on a ppc, things are already in network byte-order so htons does absolutely nothing. However, on i386 host byte-order is different from network byte-order. So the reason it worked on ppc was that it was essentially as if I hadn’t done it.

It turns out that the particular thing I was doing didn’t need the conversion to work correctly. I removed it, and everything worked peachy on both machines.

The Grandiloquent Dictionary

August 29, 2006

So I was looking up an actual dictionary definition of “alieniloquent” today. I had one at some time in the past, but it’s a hard word to find in dictionaries, and that’s why I picked it for my domain. I finally found this website, the Grandiloquent Dictionary, and it has my word in it.

alieniloquent : Speaking discursively or straying from one’s point.

So for those of you who were wondering, there you go.

"Linker warning: -bind_at_load"

August 29, 2006

Apple has had Intel machines for about a year. When they came out with the new architecture, they came up with the idea of a universal binary. It is a binary that will run natively on either the PPC or Intel architectures. None of the apps I work on have been compiled as universal binaries until today.

I just got my iMac yesterday, and it’s beautiful. The most interesting thing about it, though, is that it is an Intel machine. So naturally, when I got my projects all set up on it, I finally had to bite the bullet and make things work cross-platform.

That meant I had to recompile some frameworks to be universal binaries themselves. I also had to twiddle some build options. It was all well documented, and easy enough. But then I ran into a weird error that I couldn’t figure out:

/usr/bin/ld: warning suggest use of -bind_at_load, as lazy binding may result in errors or different symbols being used

symbol _atan2f used from dynamic library

/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../libSystem.dylib(floating.o) not from earlier dynamic library /usr/lib/libmx.A.dylib(single module)

After much searching, I finally found an article, and it explained what I needed to do. All I had to do was add -lSystem to my linking flags.

Now all I have to do is fix my one byte-order issue, and the program is all better.

Advertisements

August 25, 2006

Erica has been doing this sort of thing for a while, but I haven’t been into my site enough to really care. Now that I’m doing more with my site, I decided it was time to get on the bandwagon. I’ve added some advertisements over on the far right column, and I’ll see how I feel about it in a month or two. I’ll probably add some Amazon items and maybe other stuff too.

Project Goals

August 24, 2006

Erica posted her creative goals, and I figured I’d do the same.

  • I’m working on a Mac app that will interface with Google Calendar and iCal to help schedule free time. It’ll be ideal for students who want to plan their homework or freelance workers who need to break up their day. Erica’s going to be cutting her Cocoa teeth on this project with me, but I’m doing most of the backend work.

  • There are a couple of Ruby on Rails projects I’d like to play with.

  • I think it is high time I revisit OCFit and get more done there.

  • I want to post more frequently and with some sort of theme. I think it’ll be largely programming focused.

  • I would like to find more speaking engagements.

So those are a few things that I’m looking at doing aside from work and school this semester.

New design

August 23, 2006

Well, it only took me one night. I’ll probably be tweaking for weeks now, but I got the main thrust of theming done.

I really have to compliment the Wordpress guys. Setting up a theme for their system can be as easy or as difficult as the particular designer wants. Their theme system is definitely the way to go for live blog redesigns, though: I could switch back to the other theme with a couple of mouse clicks. Very easy.

Let me know what you think of the design.

Cocoa + Google = Yay!

August 23, 2006

So, I’m going to be writing an app to interface with Google Calendar, so I need to learn how to speak the Google Data APIs. The first part of this is being able to authenticate using their client login protocol.

I figured I’d throw together a simple little Cocoa app that just has text inputs for all the things that need to be sent and then I could do that. I figured once I had the code written, I could extract it out into a class that I could use in my real app.

I spent 30 minutes remembering how to throw the GUI together (I’m a bit rusty).

I spent an hour or so understanding the NSURL API and figuring out how to url encode in Cocoa (it turns out there isn’t anything in the Foundation classes).

I spent another fifteen minutes not understanding why it told me my authentication was bad, despite it being correct, and then realizing I wasn’t actually sending my authentication information (or any part of the request). It only took five minutes to fix it.

I now get a successful response back from Google when I log in using my little login testing application. How cool is that?

Pardon the mess

August 22, 2006

For those who actually read my site at my site, please pardon my mess. I’m redesigning my site, and I have much less regard for how it looks than some, so I’m just going to piddle with it live.

On the up side, if you’re the kind that obsessively refreshes my blog, you can see how I design web pages.

Completely Recovered

August 22, 2006

Between my trash folder and cached copies of my pages on Google, I was able to recover all of the content I had deleted. I took advantage of this opportunity to redesign the site.

I made a new design, and I like this one much better anyway. So, it all ended well in the end.

Oops

August 21, 2006

So I’m in my web directory, doing some stuff, and I notice the twiddle backup files that Emacs leaves when I edit remotely. They bug me. So I did the following command to remove them.

find . -name *.~?~ -print -o -exec rm {} \;

Some of you probably think that’s just greek. But others are cringing just as I did when I saw it remove all of the files in my directory. Sooooo, the other parts of the site are broken until tonight when I can fix them.

A Million Lines, Eighteen Months

August 16, 2006

I just got back to the office after giving a talk to the Omaha SPIN group. It was a report on the experiences we’ve had and the lessons we’ve learned at my current employer over a year and a half of using agile methods.

If you’d like to look at my slides, they’re here.

The 51st State

August 15, 2006

So I was browsing a company’s website today, and out of curiosity I clicked on their map to show where all their locations are. I was expecting to see lots of little dots representing their offices, but what I saw was so much more.

This company has gotten the scoop on all of the major news services. It has a map of the contiguous 51 states.

the Northwest

the Northwest

Here you can see a cutout of the Northwest area of the country. If you look closely you’ll see the new borders between East and West Idaho and East and West Montana. Rumor has it that Idaho has split over whether or not to put a potato on the back of their commemorative quarter, and nobody knows what’s up with Montana.

Florida

Florida

This other section shows the fifty-third, and newest state: Floridabama. Nobody’s quite sure why they formed. They don’t even have their own constitution. Almost all of the land has been sold to development companies to build retirement communities and casinos. That’s right: retirement casinos.

Note: I did not make these images. I have altered them to protect the innocent, but I really did find this while surfing.

Extract Comments

August 15, 2006

So Brian and I were pairing today, and we were refactoring some legacy code. The method we were looking at was over 200 lines long, and it had comments sprinkled throughout to make it semi-readable.

We highlighted a huge block of this method and hit the magic keystrokes to Extract Method using Delphi 2006’s automated refactoring tools. It extracted all of the code just fine, but it also removed some of the comments.

Note that I say some of the comments were removed. Some of them were not. There was no pattern that I could discern as to which comments were removed or which were left alone. It’s almost as if the refactoring tools read the name of the new method, read the content of the comment and said, “Nah, you don’t need the comment any more, the name is enough.”

That’s definitely not the kind of thing I want my computer doing for me. Bad Delphi!

Code Survival

August 15, 2006

While Brian and I were pairing today, we also found an offensive bit of code.

property P: Pointer read FP;

This was a public property on a class. It had no meaningful name, and was of the least-specific type in the system. (I’m prefer dynamic languages, but if you’re going to use a type system, use it.)

Some quick grepping revealed that the property was never used, and deleting it and doing a build all confirmed it. We felt much better.

But, simply deleting it was not enough. We had to find out who had put this terrible code into our codebase. Using svn blame to track back the revisions, we discovered it was put in on revision 3 back in 1996 when the file was first added to Visual Source Safe.

We were no longer very surprised at the naming of the variable. The department’s naming standards were not the same ten years ago. What we were surprised to discover is that the property (well, it was a public field back then) wasn’t ever used in revision 3.

The field had never been used.

You know you have a big ball of mud when a public field named P survives for ten years on a class that is a vital part of your system even though it is never used anywhere in the code.

WordPress 2.0.4

August 14, 2006

I’ve been waffling about trying Typo as my blogging engine. But, I ended up coming to the same conclusion I came last time I switched away from Wordpress.

I don’t care enough about my blog to code for it. So I don’t need to blog with Ruby, because I’m not going to be coding for my blog. So, I’ve done what I should have done a long time ago: I upgraded to the latest version of WordPress.

The posting interface certainly is sexy. It also comes with a plugin for spam filtering out of the box, so I don’t need the one I was using any more. The primary reason I did this, though, is that I’m going to be getting into making a new template for my blog to integrate with the rest of the site, and I wanted to be on the latest version for the templating stuff.

New main page

August 8, 2006

Hey all. I have a story to tell you about Subversion and firewalls, but it will have to wait for tomorrow as I am dead tired.

But, I did want to share with you the fruits of my last thirty minutes or so. I have produced a new main page for www.alieniloquent.com. This is going to grow into place for me to put all sorts of things I want to share with the internet.

I moved my lisp talk materials under a new directory where I will be putting all of my presentation materials.

I also created a place to put code. In there I’ve put J3TestCase: a wrapper arount OCUnit . It makes it behave more like the xUnit frameworks I’m accustomed to, ObjcUnit in particular. Just drop the two files into your project where ever you want, and you can use the class to descend your test cases from.

Migration Complete

July 31, 2006

I’ve completed the migration of my website from the www host to the blog host. Now I’ll be using the namespace under www for hosting other things. I did not put in the fancy 404 handler like I had thought I might. It turns out that just a handful of rewrite rules caught all the links I cared to preserve.

Lisp talk update

July 31, 2006

I was making sure everything was in order for my talk tomorrow for ODYNUG, and I discovered that the venue has changed.

Apparently Cafe Gelato, where ODYNUG has been having its meetings, went out of business. So my talk will be at the Panera at 132nd and Maple.

Intro to Lisp

July 26, 2006

Right now I’m in my hotel room in Minneapolis. I’m here for Agile 2006 because my work sent me. Joe went into how we are all lucky bastards. I may blog more about the conference, but maybe not.

I’ve been spending most of the week writing lisp code. I’m giving a talk next Tuesday (August 1st) at the ODYNUG meeting. It’s an introductory course on lisp. I’ll be covering some history of lisp, a programmer’s guide to the language, and then some practical examples. We’ll even write some code together.

The location and time is at the link above. If you have a laptop with wireless, bring it. There is no projector, but I will be sharing my desktop via VNC. I will also post all of my code up here on my website after the talk.

I suck at the internet

July 17, 2006

Well, don’t I just suck at the internet?

I’m thinking about moving my blog over to Typo but first I needed to delete the 11,000 some odd spam comments that I had. It was too hefty a task to do manually, so I dipped into the database. I, of course, was confident that I could do it safely. So, why would I back up the comment table? Naturally, I did not do it safely and deleted all of my comments instead.

So, I didn’t mean to delete all of your comments on purpose. I’m sorry. But, they’re all gone.

Firefox Extensions

July 17, 2006

I recently decided to throw together simple little Firefox extension. It’s pretty neat how XUL works. However, setting everything up can be a bit disorienting. Fortunately I found a good guide. Between the content on that page, and the content that it links to, I figured out everything I needed to know in order to get my extension working.

URI Changing

July 13, 2006

I have moved my blog. It is now here. Most of you are probably getting to this notice via my old URI. Please update. All you need to do is change “www” to “blog” and you’re set.

I’ve set up a rewrite rule that will redirect from the old URI scheme to the new one. As this is a permanent relocation, that redirect will eventually go away (I want to use the www space for other things). At that point I will probably set up a smart 404 handler that will try to preserve links as best as it can, but please update them anyway.

A Lapse

July 6, 2006

Oops.

My domain was due to expire on July 4th, 2006. Silly me, I got all caught up in the holiday and forgot to do that. So, that’s where my site (and email) have been the last couple of days.

All better now.

"Go: My Renewed Obsession"

June 6, 2006

Lately I haven’t been playing much WoW, but I have been playing a lot of Go. It’s a mentally challenging game, and I can look forward to a lifetime of learning and fun. Jessica is going to be giving me a goban for my birthday, and that has increased my interest in playing the game.

I first started playing go when I was a teenager. I played it on Yahoo! Games. I enjoyed it. I was better at go than I was at chess. But, I got distracted.

The next time I got serious about the game was a couple of years ago. I downloaded a program similar to Goban (the one I use now), and started playing against GnuGo. I also played a little on the KGS.

At that time I found two very awesome resources: Sensei’s Library, and goproblems.com.

Sensei’s Library is a wiki devoted to go. Its maintainers have even gone so far as to create wiki markup that gets formatted as images of go positions (complete with ways to annotate the board). It is an indispensable resource for any go player.

Goproblems.com is a site full of exercises. People upload scenarios designed to teach and then one can work through all of the exercises using a Java applet. The site has time trials at different ranks from 30 kyu all the way to 6 dan. I have learned a lot from the exercises here.

Naturally, when I started playing again, I started frequenting these sites again. I noticed a banner on one of them for the Go Teaching Ladder. This is a phenomenal resource. Weaker players can record their games in SGF and then submit them for a review by stronger players. Most of the reviewers are at least 15kyu or stronger, and some of them are very good teachers. The best part is that all of the reviews are available for download. So, one can go download an SGF and watch somebody else’s game along with comments by a stronger player as to what would have worked better.

I read a half-dozen games last night, and it has already improved my 9x9 game significantly, and now I don’t feel like a chump when I play 19x19 (a full- sized board). I’m sure I could have read it somewhere else, but there’s something powerful about reading the proverbs and strategies in the comments of an actual game. It puts the proverbs in context.

I’m sure I will be blogging more about go in the future. It’s not pink, but it is my obsession.

Bad Boy Scout

May 18, 2006

I know I haven’t been posting, and it’s mostly been because I’ve been busy. Sometimes, it was because I just didn’t know what I wanted to post. Regardless, I haven’t been keeping up with any form of my blogging resolution for over a month.

This last week has been a really intense week, and has given me something worth coming out of my blogging cocoon for: love. I want to write about it and share it with the people who read my blog. If you’re just here for the technical stuff, you should probably skip this post.

A few months back, Erica was surfing around on OkCupid and found a couple of really cool people. They happened to be a couple and they happened to be here in Omaha. We all went out for dinner and realized that we all had a lot in common. We got together a couple more times after that, and decided to get together on a regular basis for a Mage game once the semester was over.

The more we’ve hung out with Jessica and Michael, the more we’ve realized we have in common. The four of us share so many references and pseudo-inside jokes it’s just not funny. Beyond that we have many of the same quirks and hobbies. It is really uncanny how similar we all are.

Last Thursday Jessica invited us out to karaoke at her bar, and Erica and I went. We all had a blast. Friday night Jessica came over and we all just hung out. Saturday we went out to karaoke again, and we ended up having a slumber party at the Bibliotesla. In fact, out of the days since last Thursday, we’ve all hung out on every one of them except Tuesday, and we all chatted online that night. It’s been very intense.

Now, what relevance does this have? Why am I blogging about it? Well, like I said, this post is about love. Some of you may know, and the rest of you will find out now: I am polyamorous. For those of you who don’t want to follow the link, it essentially means that I do not restrict myself to having only one loving relationship at a time. For the longest time, I have only had one, but I have always been open to the idea of more.

I’ve always been of the belief that the relationships that last are the ones you aren’t looking for. Erica and I just happened. We weren’t planned. We both got swept up in a whirlwind and fell for each other hard. We were married within one year of meeting each other, and we’re working on our sixth year of marriage now. This week is reminding me of the beginning of the summer during which she and I met.

Jessica and I have so much in common, it’s ridiculous. Before I met Erica, I never thought I’d find somebody that had as much in common with me as she does. After I met her, I was convinced the feat was unrepeatable. I was wrong, and I’ve never been happier to be wrong about anything. What’s more, Michael and I also have ridiculous amounts of things in common (and Erica shares many things with both of them too). It is really as if we found copies of us that are sufficiently different so as to be interesting and engaging.

The motto of the Boy Scouts is “Be Prepared.” I totally wasn’t prepared for any of this. I had just thought that we had found awesome friends and gaming buddies. All of this ran me over like a freight train filled with anvils, but I wouldn’t have it any other way.

Violin Siren

April 15, 2006

So we were at Jonesy’s Dinner Den on Maple eating our food (which was very good) and watching the five o’clock news on their TV. The weather guy was going on about the possible tornado cells that were west of Omaha and moving easterly. In the background KVNO was playing some classical music.

That’s when we heard the sirens. Everybody paused and looked up at everybody else, and then the woodwinds kicked in. They weren’t sirens after all, just violins. It was a tense second, and then everybody laughed.

Revisionist Goals

March 21, 2006

I’ve been doing Atkins since Thursday. I’m past the energy slump and back to normal. It takes a little more effort to be as lazy as I like to about cooking and also do this diet, but the new grill helps. Mmm, steak.

The sleeping goal, not so much. The first week I managed. Since then I have not. I am still shooting for 0500, but I have not been succeeding for various reasons. Most of them have to do with the fact that when I get up at 0500, there’s nothing I can think of that sounds better than crawling back into bed. I’m awake, sure. I’m not tired. But, the siren song of my sheets is calling to me.

The diet is providing some motivation to get up earlier: breakfast. I like to start the day with at least four pieces of bacon and two eggs. That takes some time to cook right, and so I need to give myself that time. That means I can’t snooze until the last minute and get a sandwich at McDonalds any more. So, I’m working on it.

Blogging hasn’t happened every day. Sometimes I’ve forgotten. Sometimes I’ve procrastinated it until I fall asleep. Sometimes I haven’t had anything I felt I could squeeze a blog post out of. But, I’m falling short of my every-day goal.

I am, however, a believer in adjusting goals to be realistic. I do this at my job all of the time. When we realize that a software task is impossible, we figure out how to make it possible and still get as much value as we can. Blogging daily probably isn’t impossible, just improbable. The value I wanted to get out of it was to write regularly. Based on that fact, I’m going to scale back to blogging a minimum of three times a week, and more if I feel moved to.

DVDs and World of Warcraft

March 17, 2006

That is what I’ve been doing the last few days. I’ve been watching DVDs and playing WoW, and clearly not blogging. What’s more, I’ve had a few ideas for blog posts (although, I can’t remember exactly what they were now). Ah, well, I’ll live. Just not my best week for the blogging goal. I’ll do better.

We rented North Country. I can’t say that I recommend it. Other than that I’ve been busy watching Season 4 of Gilmore Girls, and that I can definitely recommend. It’s one of my favorite shows (no, I don’t watch it on TV, just on DVD, like most television shows I watch). Season 5 is sitting on my shelf just itching to be played.

Tuesday I did my first instance in WoW with a pick-up group. It went rather well. I had a blast, and I am looking forward to doing it again. I haven’t been playing a lot lately, but all of the sudden I felt like it, and I had some fun. So I’ve been doing some of that the last couple of nights (since I don’t have classes this week).

Tonight I expect to be more of the same, I’ll probably finish Season 4 and maybe run an instance.

When I Grow Up, I Want To Be A Fireman

March 13, 2006

Life is full of tough decisions. It is, in fact, itself a series of decisions, and many of them are tough. So far, I’ve had a mix of them. The funny thing is, I made a lot of decisions that are hard for most people with ease.

I dropped out of college. I got married, and have remained blissfully so. I picked up all of my earthly posessions and moved a state away to seek out better fortune. I left a steady job for a new, better, shinier job, and then did it again three months later (and have been in that position for the last two years). I just bought a house six months ago.

I read. I know that many people stress out and toil over those kinds of decisions, and all of them have just come to me. When I needed to make a decision, I just did it. Yeah, it was stressful, but the right choice came to me. But now, I’m sitting here in my house and I’m thinking about the future. I’ve got everything (mostly) planned out through my graduation, which will be in Spring of 2010. That’s right, boys and girls, I have another six semesters after this one before I graduate (wow, it’s into the single digits at least).

I’m not sure what I want to do after I finish school. I’m already employed, and as much as I love my job, I don’t want to work there forever. I want to start a business, but hell if I know what. I’ve considered graduate school, but I frequently reconsider (and then reconsider reconsidering). When I get my degree in four years, I’ll be done with the part of my life that’s been planned.

A few years ago, that would have seemed like forever (indeed, I remember thinking just that), but now that seems like it will be just around the corner. I feel unprepared. I wish I could find that resolve that I had as a young child when I said I wanted to be an astronaut, and then a fireman, and then a chemist, and then and then and then.

I’m sure I’ll decide when the time comes, but it’s this waiting that’s killing me.

Grills and Receptacles, part Deux

March 12, 2006

Two weekends in a row this has been the topic du jour. It’s like grilling and electrical work go together. Like chocolate and mint, or swearing and hockey.

This afternoon I had the house to myself for a blessed hour and a half. I took that golden opportunity to shut all the power off in the house and install my new circuit, and it worked! Well, after a little coaxing. Once the breaker was installed and I turned the power back on, I discovered I had miswired one of the receptacles. They are all GFCI receptacles, so they just wouldn’t reset the right way. A little work and I got it all taken care of. So I’ve got more power in my basement and the server migration is ready for phase two: getting the nice internet pipe in the basement.

Today also illustrated for me just how nice having a natural gas grill out on the deck is. I can go out there, fire it up and throw down some food any time I want. If it’s smoky, the main floor of the house won’t get filled, and all of the food has that delicious flame-licked taste. I made burgers, salmon, and garlic bread on the grill today. I’m of the opinion that most everything is better when cooked over actual fire.

The Abstract Concept of Abstraction

March 11, 2006

So, last weekend, we bought a grill. Yesterday we got the gas line installed in our house so that we could use the grill. Naturally, I was planning on having steaks for dinner.

Long about 0930, I get a call from Erica while I’m at work. “Hey honey, I know you’re excited about grilling. I’m excited about hanging out with my friends. Can I have some of my physics-major friends over?” I figured, sure, why not? They’re my friends too. The more the merrier.

Well, there were more. I ended up cooking for twelve people. Pleasantly, my grill has plenty of room to cook on. I cooked steaks for most people, chicken breasts for a couple, burgers for a couple and lots of veggies (bell peppers, squash, tomatoes, zucchini, and onions). It was all really very good.

Party continued. Margaritas were had. We burned the chiminea again, and I ended up watching the fire burn down while everybody else played Outburst. I enjoyed that. Then we all played charades until midnight when I went to bed. I assume the party continued after that, but I’m not sure how long because despite their volume, I was out cold in five minutes.

So, that’s why there was no blogging yesterday. I spent from about 1700 - 0000 entertaining. It was fun, though. Expect more bloggy goodness from me today.

Watching the flames

March 9, 2006

When we bought this house, we made sure to ask for the cast-iron chiminea that the previous owners had. They let us have it (along with a lot of other stuff). That was back in September. We were very excited because it was still the right season to burn the chiminea, but we never did.

Tonight we had company over and since the weather was nice enough (I look at the weather widget and see it’s only 4 degrees above freezing, I guess I have a weird definition of nice enough) we decided to eat out on the deck and start up a fire. The wood was wet, although imperceptibly so, as it had been in the chiminea since the aborted attempt at burning back in early November. But, after a bit of work, I got a nice fire going.

Three hours later, I’ve finally come in from the deck to go to bed. It was enjoyable watching the fire burn down. I forgot how much I enjoy watching the flames dance back and forth. Watch the glow of the wood as it sits there and smolders. The smell of the smoke from good wood. The (little bit of) radiant heat. It reminded me of my Boy Scout days just a little.

We’ll be burning a lot this spring.

"Inexplicable Key-Chord #572"

March 8, 2006

There’s a plugin for the Delphi IDE called GExperts. This plugin provides a metric ton of addons. The one that we use it for here at my office is Grep. In most ways it is superior to Delphi’s find-in-files functionality. There are two key-chords associated with grep: Alt-Shift-S to bring up the search screen and Alt-Ctrl-R to bring up the search results.

That’s great. The problem is, I do one way more than the other. So I remember the correct bucky bits for grepping, but I frequently forget the correct ones for bringing up the search results.

Naturally, I will try Alt-Shift-R before Alt-Ctrl-R, figuring the bucky bits would be the same. And for two years, nothing has ever happened. Then one day last week, I’m sitting on an assignment statement like this:

Foo := Bar;

I hit Alt-Shift-R and all of the sudden I’ve got this:

Bar := Foo;

“Whisky tango foxtrot,” I say, and hit again. It flips again. I try it on this:

Result := Foo(Bar);

And I get:

Foo(Bar) := Result;

Thanks, GExperts.

Now, I couldn’t for the life of me figure out why anybody would want this feature. Until I read the documentation. It will also flip the direction of a for loop. That is actually neat and cool.

Awesome Concert

March 7, 2006

Ben was fantastic. This is actually the first time I’ve seen him play with anything resembling a band: a drummer and a bass player. Although I didn’t know he was going to have a band, it was a pleasant surprise. The previous three shows I’ve been to, he’s been solo. There are definitely some songs that were much better with the added guys, especially because of the extra vocals that Ben just can’t do on his own. That said, I still like him a lot on his own.

I’ll let Erica post a set list because she knows all the titles. He did play his staple gig songs: Army, Philosophy, and Not The Same. He also did a cover of Dr. Dre’s Bitches Ain’t Shit, which was hilarious. He informed us all that he no longer Rocks This Bitch, nor does he Rock Out With His Cock Out, and he did it in the form of a folk song.

Amusingly, he seemed to be up on the whole purchase of the Ranchbowl and planned Wal-Mart conversion. In his words, “I’ve played Wal-Mart now.”

Ben continues to be my favorite concert performer, and about the only act I’ll always go see if I can. In fact, if I didn’t have an exam on Thursday, I’d go see him again at the show in Des Moines.

A To Do List

March 7, 2006

This will be the first of two posts today, as I forgot to post yesterday. Following in Erica’s footsteps, here is my to do list.

Before Spring Break:

  • Graph Theory homework (due Thursday).

  • Analysis homework (due Thursday).

  • Review analysis material for exam on Thursday.

  • Review graph theory material for quiz on Thursday.

  • Work.

  • Ben Folds concert.

During Spring Break:

  • Install the circuit I built.

  • Narrow down the topic for my Graph Theory paper.

  • Read the material for that paper.

  • Write that paper.

  • Prepare material for a Mage game that I may or may not run in the future.

  • Crochet a few rows on my afghan.

  • Sleep, and get up at 0500 every day.

  • Blog every day.

Of Grills and Receptacles

March 5, 2006

I got a lot done this weekend. Getting up at five in the morning really has a lot to be said for it. I really got a lot done.

Tyler and I are planning to set up our servers in my basement, but there wasn’t any power for it. So, I’ve been planning to put in a circuit for a while. But, every weekend would come along and I would sleep in and I wouldn’t go get the hardware. So, I’d put it off again. Yesterday I finally went to Lowes, and I got all of the stuff I needed.

Naturally, I ended up going back to Lowes today as I was wiring together the receptacles (that’s the fancy electrician’s word for an outlet), so that I could get a couple of things I hadn’t bought on the first trip. This time I brought Erica with me.

When I take Erica to stores she can’t help but look around. She has to look at everything in the store. This time it was grills. Now, I can get behind that. I like grills. I want a grill. So, well, I bought one. It was an adventure getting it home, but now it’s back on my deck. We just have to get MUD to come out and install the gas hookup for it, and then I’ll be grilling all the time.

I’ve got the wiring project mostly done. All I have left to do is mount the board with the receptacles on the wall and then install the breaker in the load center (fancy word for a breaker box). Assuming I can follow instructions, I should have four shiny new outlets in my basement.

On Roleplaying

March 4, 2006

I’m a gamer. Mostly old-fashioned, pencil-and-paper, roleplaying games. I do play World of Warcraft, but my favorites are table-top RPGs.

I’ve played a lot of different games: AD&D, d20 D&D, Vampire, Werewolf, Changeling, Mage, Hunter, GURPS, 7th Sea, Shadowrun, Cyberpunk: 2020, Call of Cthulu, and some homebrew systems. Each has a different style. Each has a different mixture of rolling dice and playing roles. Sometimes these two facets are called roll-playing and role-playing.

I’ll be honest, I prefer role-playing to the alternative. If I wanted to sit around and throw pieces of plastic the whole time, I wouldn’t need to come up with worlds and stories. Don’t get me wrong, I think dice have a place in a game, but I don’t think they should be at the forefront. Consequently, I don’t like games that are heavy on combat. It doesn’t matter which system you play in, combat is inevitably the least role-playing you do in a session.

So of the games I’ve played, I tend to prefer the White Wolf World of Darkness games, my favorite being Mage (2nd Edition, in particular). It is very story heavy, and that’s what I like. The game is all about playing characters and solving problems. Sure, there’s combat, but it’s all very plot- driven. You don’t do a dungeon crawl in mage, you infiltrate the Syndicate front’s corporate headquarters to get the vitally important documents that explain the wave of mysterious drug-related deaths in the local area.

My regular gaming group wasn’t getting into Mage. Erica and I suggested that we play D&D. She and I knew that we could attempt to make D&D fun for us (by making interesting characters and roleplaying them). We’ve played a couple of sessions as of tonight and, well, the game is about what D&D usually is: a lot of rolling.

I’m trying to have fun, but between throwing down dice and looking up rules, I can’t say that there’s much room for it.

Crochet Fun

March 3, 2006

Erica started crocheting again. She’s pretty excited about her projects. I am too. She’s really starting to make some nice things. Aside from the hats, she’s working on an afghan pattern that came on the yarn we bought at Wal-Mart it’s really neat.

I’ve known how to crochet since I was ten or so. Back then I pretty much just made hot pads and trivets. Lots of squares. But, it was fun and I felt crafty. Then, a few years back, when Erica and I both had phone jobs in Colorado, we both decided to crochet scarves for each other. We never finished them, but it was really fun. We’d be sitting there crocheting while we did internet tech support. It’s soothing.

So, seeing Erica get all excited about making pretty things out of yarn, I decided I should pick up a project too. Naturally, I decided to start big: 36 square feet of afghan. I’m using a nice double-crochet chevron pattern and it’s looking quite nice. Right now it’s about six feet by eleven inches. I’ve only got 61 inches to go before it’s square. I should have it done by the time fall rolls around.

I really enjoy crochet because it’s something I can do that requires skill but not a lot of thinking. When I come home from work and class, my brain can sometimes get pretty fried. So having an activity that I can do that is effectively brainless but that still lets me make pretty things, is awesome.

I’ll be sure to get Erica to post pictures of my afghan when it’s done.

A Post Should Go Here

March 2, 2006

It’s not until I set the goal to write a blog post every day that I realized I don’t always have a topic to write about. Were I to have a topic, this post would have been about it. Instead, you get this placeholder post where I talk about the post I would have written.

Let me introduce you to the post I would have written. It is about a very deep, interesting, and intellectual topic. In this post I give the topic a brief survey and offer some witty insights and humorous anecdotes. I conclude the post with a thoughtful one-liner.

Tomorrow I’ll make a list of topics.

On Primitives

March 1, 2006

Blaine has a post about how strings are so frequently abused in object models. We heap extra meaning onto a string when we really should make a class. The reason we should make a new class is that each class represents a concept in our domain, and we can add behaviours and data to each class. You’ll be hard pressed to do that with a string. So, to stay agile it’s better to make new classes for new concepts.

In Delphi, there’s a similarly abused syntax trick. It looks like this:

type TMyEnum = (meOne, meTwo, meThree);
const MyEnumStrings: array[TMyEnum] of string = ('First', 'Second', 'Third');

Then, wherever you want to get a string associated with one of the enum tokens, you can just index into that constant array using the enum value.

This trick isn’t limited to arrays of strings, either. You could have arrays of integers, doubles, characters, or even objects, and you can make as many of these arrays as possible. So if you have some setting and there’s ten values that change with that setting, then you could have the setting be an enumeration and have ten constant arrays indexed on that.

In a world of procedural programming, that’s a neat trick, and it can help a lot. But Delphi shed it’s procedural shackles years ago, and now it has the power of objects to help it out. Sadly, many programmers are tied to Delphi’s procedural roots, and can’t get away from this enumeration-indexed array trick.

What’s so bad about the trick? For starters, you’re making global data. Sure, it’s constant data, but it’s global, which makes finding where the data is coming from that much harder for somebody new to the code (or somebody reading it months after they wrote it). Secondly, in order to vary behavior based on the enumeration, you have to have gnarly conditionals that branch based on the type code. This makes methods longer and harder to understand and follow. Lastly, it makes the types more resistant to change, especially if they’re serialized as integers: any change in order will change the ordinal (integer) value of the same enumerated value.

What’s the alternative? Make a class. You can easily make a class that represents the type code, and you can make subclasses for each type. The class can have methods for each of the constant arrays and the subclasses can implement them to return the proper ordering. If there’s behavior specific to one type you can put it on this class hierarchy and polymorphically switch out behaviors, instead of making gnarly conditionals. Moreover, there’s no inherent ordering from one class to the next, so you can completely control how things are serialized and compared.

As Joshua Kerievsky says in his book Refactoring to Patterns, so many developers have an obsession with using language primitives such as strings, integers, or enumerations. Whether that’s because they think that it’s too much work to make a class, or it’ll take too many CPU cycles, or it’ll eat up too much memory, it doesn’t matter. The obsession with primitives is unhealthy and it leads to spaghetti code that is hard to refactor.

We must resist the temptation and make supple, agile code. That means we must make classes.

Missed a day already

March 1, 2006

I set a goal for myself to blog every day, and I don’t even manage to do three days in a row. That’s embarrassing.

Yesterday was a busy one. I went to work at 0730, as usual, and worked on some fun stuff until 1200, and then I came home. I ate some leftovers and tried to take a short nap. It only lasted 15 minutes. I did manage to doze off a little, as I recall having some dreams, but I think that I was a little awake at the same time.

Then I ran off to South Campus for my graph theory class. I got my first exam back: 94%, yay! Class was interesting. We spent most of the time talking about some algorithms I already knew, but then we started talking about matching, and that should prove to be interesting. That class got out at 1445.

After class I drove up to North Campus to hang with the physics TAs and piddle around on my computer. I looked at my budget (it’s still mostly blank) and my bank balance, and then I started a new programming project.

My next class was at 1730. Analysis is a fun class. I like the instructor, and I like the topic. I didn’t think I’d like doing seemingly inane proofs of stuff that Just Makes Sense, but it actually is fun (for me). We talked about subsequences and then we talked about monotone sequences and the Monotone Convergence Theorem.

After class, Erica and I grabbed a bite to eat and came home to take a real nap. This one lasted 45 minutes or so. I got up from the nap, and was still tired, so I just went back to bed.

My alarm went off this morning at 0455 and then again at 0503 and 0505 (There’s two alarms, and it only waits 8 minutes). I was up and ready to go after the second one. I hopped in the shower, and that’s when I realized that I’d completely spaced blogging last night.

Consider this yesterday’s post. I’ll post again later today.

Okay, so maybe not so drastic

February 27, 2006

Having made my declaration of goals yesterday, I did some thinking. I’m really looking forward to my dietary changes. I’m also really looking forward to the regular blogging.

As she always does, Erica found me some reading about polyphasic sleep. Now keep in mind, she’s the one that seeded the idea in my head to start with. Upon reading these articles, I am still incredibly curious to see how it would be. However, I think that it will be more practical for me to simply work on being an early riser and perhaps take a nap in the afternoon: biphasic sleep.

I’m going to replace the polynapping goal with a different one, and I’ll start it the same day: get up at 5AM every morning.

Now, there are a number of things that will contribute to this goal. First, I’m giving up caffeine. This is part of the Atkins diet, but it certainly won’t harm my sleep habits. In fact, I started going caffeine-free today, since I know I can do it whenever I choose (I’ve done it before, caffeine is always a conscious choice). I’m certainly feeling a little more weary tonight than I would had I had my coffee and cola today, but I will go to bed sooner and feel rested in the morning.

I might revisit the polynapping again sometime in the future when I’m self- employed (that’s a goal of mine, you know).

My Belated New Year's Resolution

February 26, 2006

Most people make their new year’s resolutions around January 1. This year I decided to see how things would shape up first, so now it’s nearly the end of February, and I’m finally getting around to setting some goals. (Actually, I just now set some goals, and I’ve decided to call them new year’s resolutions, but it’s all in how we frame it.)

One of those goals is to blog every day. No matter what. So, in the spirit of achieving that goal, I’m going to blog about it. Right now.

For the last few months, in many areas of my life, I’ve felt like I’m a kid playing at being a grown-up. Now, honestly, I think most people expect somebody who is 23 to be like that in most of these areas: personal finance, housework, time management, etc. But, I’ve never been normal. I’ve been married for five years and I just bought a house, clearly I’m out of the nest. I just feel like there’s a lot of skills I ought to have that I don’t. There’s a lot of things I feel that I ought to be doing that I’m not, and I know that I’m the only thing standing in my way.

There’s a lot of areas that I think I can improve and grow in, but there’s three that I’ve selected to start with, and I’ll tell you, I decided to start with a bang. The three areas I’m going to start working on are my blog, my diet, and my sleep.

My first goal is to look back on my archives at the end of 2006 and see one post for every day of the year between now and then, that’s 307 more posts after this one. This goal is to help me build some self-discipline. I expect to be blogging about my work on my other goals, but who knows?

My second goal is to get back onto the Atkins diet. For those of you who read my blog a few years back, you’ll recall that I had a lot of success with that diet. The fact is, I’ve never felt better than when I was on that diet. I had more energy. I slept better. I had more focus. I felt healthier. The weight loss was just frosting on the cake of feeling altogether better. I want to feel that way again.

I am going to start the diet again next Saturday, March 4th, and Erica is going to do it with me. Nate even said he’d go low-carb. During this coming week, we’re eating as many of the carby things we have in our pantry so as not to just waste the money we spent on them. On Saturday we’ll kick it off. Last time we (successfully) went Atkins, we gave away an entire grocery-shopping trip’s worth of groceries to my sister-in-law. We might do something crazy like that again.

The third goal is to adapt to polyphasic sleep. I almost wrote “or prove to myself that it’s not for me,” but I’m not going to give myself that option. It is for me, and I’m going to make it happen. I have an exam in my analysis class on March 9, but after that I don’t have class for an entire week. I’m going to have a full night’s rest on Wednesday night into Thursday, but then I’m going to start my napping schedule after I get up that morning. I should be plenty rested for the exam, and I should be through the worst of the adaptation by the time my next class rolls around. That also places the days which most people seem to have the most trouble with either on weekend days, or days that are very short for me at work. It’s a medium-risk, high-reward move for me, and I like those.

Those are my three goals. I am going to attain all three.

Unit Testing of Cocoa Apps

February 23, 2006

There’s plenty of articles out there telling you how to use OCUnit, especially now that it ships with XCode 2.0. They’re all excellent. You should read them, especially Apple’s. This article is simply about a little trick that I’ve come up with to solve a minor annoyance I have with using Apple’s method of hooking up what they call a dependent test bundle.

A dependent test bundle is a really neat idea, actually. It uses your actual application as a framework at link time and then uses some nifty magic to launch the test bundle from inside your application and run all of the tests. Why bother with all of that? It means you can keep your application code in one target and your test code in another target – completely separate. That’s a worthy goal.

The only thing I don’t like about this, though, is that if you’re developing a GUI Cocoa application (and let’s face it, most people are) then the process of running the tests from within the application has the consequence of popping up the GUI and letting it sit there until you quit manually. That’s annoying.

So I came up with a solution. It’s really nothing that fancy, but I thought I’d share. I make a Cocoa Shell Tool target, and I name it something like stub. I make a C file and name it stub-main.m. In that file I put the following three lines:

int main(int argc, char *argv[]) {
  return 0;
}

Then I add all of the application source files that my tests are going to need to link to and make sure it all compiles. I just use that as the bundle loader for my tests, and it’s all good. No GUI popping up.

For an example of how to do this, you can look at the source for OCFit.

Strings, arrays, and duck typing goodness

February 14, 2006

We use more and more ruby around my shop every day, and that just tickles me pink. One thing that we’ve been using it a lot for is managing our Subversion working copies. We have a script that will delete unversioned files. We have a script that will delete ignored files. I wanted to write a script that would do both of those things and also revert any modified files (thus returning the working copy to a pristine state, essentially).

There was a lot of duplication between the two scripts. In fact, the only thing different was one character in a regex: it was ‘?’ for the unversioned and ‘I’ for the ignored. I went through and wrote a new class to represent these things and then I wanted to write a method named delete_if_status which would take a list of statuses and delete any items in the checkout that matched any of them.

I thought it would be cool if I could call it like this:

list.delete_if_status(['?', 'I'])

But also call it like this:

list.delete_if_status('?I')

Naturally, I figured Ruby would have a duck-typing answer to this problem, but just the way it solved it surprised me (just a little–actually, now that I think about it, it’s unsurprising). Here is an IRB log that demonstrates just what I discovered.

irb(main):001:0> 'I?'.split
=> ["I?"]
irb(main):002:0> 'I?'.split('')
=> ["I", "?"]
irb(main):003:0> 'I?'.to_a
=> ["I?"]
irb(main):004:0> ['I','?'].to_s
=> "I?"
irb(main):005:0> ['I','?'].to_s.split('')
=> ["I", "?"]

So what I ended up with was this method:

def delete_if_status(spec)
  status_list = spec.to_s.split('')
  self.delete_if do |item|
    status_list.include? item.status
  end
end

I love Ruby.

Edited: Fixed some formatting with code and output snippets.

No, really, I mean copy the files

February 2, 2006

A couple of weeks ago, my department got a replacement for our linux server (well, that’s really giving the machine more credit than it deserves, it was hardly a server). Being the only guy here who really knows how to set up a linux server in any sort of efficient manner, I naturally took on the task of getting the new hardware up and running. There were, naturally, kinks (there always are) in the process, but I got the machine up and going. We got our wiki and our Subversion repository migrated over to it, and all was good.

Or so we thought. We came in the next morning and nobody could check out from the repository. I combed through the Apache error logs and discovered that the repository didn’t think that some revisions existed, so naturally it wouldn’t let us check out code that had been last modified in that revision. So I tried svnadmin verify /var/svn/repo and sure enough, it blew up. It said that it couldn’t find a file under /var/svn/repo/db/revprops – very odd. When I copied the files from the old repository (with the server off, natch) cp had not given me any errors. So, I went and peeked in the old repository, and the file was there. I copied it over, and the verfiy moved on, but only to break on another revision, and then another, and then another. At that point, I wrote a simple shell script to copy all the files that were in the one directory but not in the other, and in the end I think I copied a total of about 120 files.

Once all the files were copied, everything worked peachy. I’m just completely baffled as to why cp didn’t copy files and also didn’t give any errors. I wonder if it has something to do with one of the filesystems being Samba and the other being a local hard drive.

Waiting For the Build

January 20, 2006

So we’ve been moving over to new computers at work and also upgrading our compiler and changing virus protection and all that jazz that makes work fun and enjoyable. One problem we ran into was that our slow build (that runs more tests) was breaking while our fast build wasn’t. Okay, sure, but what was weird was that it was breaking checking source out from Subversion.

I tackled (along with Brian) this problem today. We had a lot of waiting to do. So, naturally, we took advantage of our new magnetic whiteboard to produce this:

Pacman on a whiteboard with magnets and marker

Pacman on a whiteboard with magnets and marker

Enjoy.

Edited: resized image so it looked decent.

Layout, design, graphics, photography and text all © 2005-2010 Samuel Tesla unless otherwise noted.

Portions of the site layout use Yahoo! YUI Reset, Fonts & Grids.