Programmatic Sentence Generation – Shakespeare!


Many moons ago, when AOL Instant Messenger was all the rage, I really wanted to write some kind of chat bot, something like SmarterChild except, perhaps, more amusing and less useful. I do recall attempting to use some Perl-based chatbot APIs to connect one of my accounts to AIM, but had very little success. So I gave up on the AIM API, and focused more on the core functionality of what I wanted a chatbot to do: simply construct a sentence given a “seed” word as the first word in the sentence. Therefore, the “Shakespeare” project was born.

What’s in a Name?

Why is this application called Shakespeare? Well, actually, originally it wasn’t – it was called Jabberwocky. I needed a source text from which to construct sentences, and one of the free online books available on Project Gutenberg was Through the Looking Glass by Lewis Carroll, and Jabberwocky is one of my favorite poems from the book. Not to mention the fact that a programmtically-generated sentence would likely sound rather silly and hilarious. Or so I hoped. Anyway, the first version of my program used Jabberwocky as the source text, but later I decided that I wanted a much larger source text, such as one of the works of Shakespeare. I grabbed the text from The Merchant of Venice, cleaned it up, and started using it, and the sentences it generates now are just as amusing or more.

Program Source

This project is written in C++, and is available on GitHub for public consumption here: Shakespeare. Feel free to check it out. The project opens in Visual Studio 2008, but if you don’t have VS2008 installed then it should be pretty easy to edit and compile using g++ or Eclipse or something =)

Source Explanation

The program works via a simple two-step process:

  1. The source text is parsed and string pairs are put into a multimap
  2. The program reads lines from stdin until “quit” is received, and generates a “sentence” for each word entered.

Let’s examine these steps more closely:

Parsing the source text

    while (!file.eof())
std::string s;
file >> s;
s = strlower(s);

// Look for a period
if (s.length() > 1 && s[s.length() - 1] == '.')
s = s.substr(0, s.length()-1);
// Look for an exclamation
else if (s.length() > 1 && s[s.length() - 1] == '!')
s = s.substr(0, s.length()-1);
// Look for a question-mark
else if (s.length() > 1 && s[s.length() - 1] == '?')
s = s.substr(0, s.length()-1);
// Look for a comma
else if (s.length() > 1 && s[s.length() - 1] == ',')
s = s.substr(0, s.length()-1);

// Add the data to the map
if (last != "" && last != "." && last != "!" && last != "?")
wordmap.insert(make_pair(last, s));

last = s;

The code here reads strings from the file, where each string is separated by whitespace. For the most part these strings represent words, but some of the words end with periods, commas, exclamation marks, or question marks. If one of these characters is encountered, we want to treat it like its own “word”. Next, for each word that we find, we insert it into a multimap where the previously encountered word is the key and the current word is the value. By the way, a multimap is just a C++ map that can have multiple non-unique key-value pairs.

Generating the sentence

        while (true)
// Check to see if the word is in the multimap
if (wordmap.find(word) != wordmap.end())
// Get first mapped value
multimap::iterator lb = wordmap.lower_bound(word);

// Count how many there are
long count = wordmap.count(word);

// Select one of them
long index = rand() % count;

// Advance map iterator
for (long i = 0; i < index; i++)

// Check for characters that would end a sentence
if (lb->second == "." || lb->second == "!" || lb->second == "?")
// If sentence is too short, select another word
if (wordcount 1)
// Update the word count in case the only endings to this
// word are ! or . or ?

// Print word
cout <second << endl;
else if (lb->second == ",")
// Print commas
cout <second;
// Print the word with a space
cout << " " <second;

// Update the current word
word = lb->second;
// Not found; end the sentence
cout << ".\n";

The code here looks up the first mapped value for the current word in the multimap (if it exists). If it does, then we pick one of the values for this key at random. Note that multiple identical values can exist because of how the source text was parsed, so you have a higher chance of getting a more common “following” word than one that is not so common. Each following word is printed, unless the word is a “sentence-ending” word such as the period, exclamation mark, or question mark and the sentence is deemed to be too small. Not shown here is the initialization of the first word to be the word that the user typed into the application.

Some Example Outputs

I find many of these to be hilarious. The sentences have a tendency to run on and obviously don’t quite follow the rules of sentences. But because each source word precedes a destination word, the sentences generated often almost make sense:

Will be render’d, will you, monsieur le bon?

Why should i know your master will tarry?

Try confusions with his surety and you the occasion to his affections, dispatch all of rich value of fair hand i am in silver ewes, as he hath the fiend bids me this shadow ere thou to him.

Thou like a night troilus methinks it.

Wit in the duke only are not love me to speak for the truth is no so again his outward wall, for a man knows but who bids me the wind!

Pity on his wealth being seasoned with us in alabaster?

Jump with imagined speed, indeed, for this letter call me dog and that is sum that the knave and it to offend, but assumes some taste of blood to my clerk, for i do you a key, there.


Feel free to leave a comment if you have any ideas for ways to make the generated sentences either more realistic, or more amusing =)

Book Review: Programming Android

<!– –>

Sorry readers (both of you), but I’m doing another book review! This time I’m reviewing the book Programming Android by Mednieks, Dornin, Meike, and Nakamura.

Why I bought this book

Despite now having worked on Android apps as my main source of income for the past year and a half, I couldn’t help but feel like there were certain aspects of the Android framework that I have probably skipped over or not encountered yet with the apps that I’ve written so far. Thanks to iSyncr WiFi and Cheetah Sync, I’ve done a lot of networking / file transfer / iTunes development, and a decent amount of UI design, fragment work, etc., but I wasn’t sure that I’d really learned everything that an Android dev should know, so I bought this book to help fill in the gaps.

Chapter 1: Your Toolkit

This chapter deals mostly with installing Eclipse and the Android SDK on your development machine and getting started with your first Hello World Android app. This chapter looks pretty good actually for anyone new to Android, but fortunately I’ve already learned all of this stuff =)

Chapter 2: Java for Android

I actually really enjoyed this chapter, because prior to working on Android I worked mostly in C++ and .NET, so there’s a fair bit of Java trivia in this chapter that I found informative and amusing. Some of the more interesting things in this chapter:

  • Java is strictly pass-by-value. This is actually just a footnote in the book, but extremely important to know as a Java developer.
  • Static vs. dynamic classes. Top-level classes are “static” by default, because they belong to no other class instance, but classes defined inside other classes are “dynamic” because they belong to the top-level class instance – this is why inline classes have access to the parent class’s variables.
  • Java collections. A short discussion of the main collection types in Java was appreciated, even if I already knew this stuff =)
  • Anonymous classes. These are supported in Java / Android, and are very useful for creating event listeners (eg. view.setOnKeyListener(new View.OnKeyListener() { });).
  • Multithreading. This was perhaps the most enlightening of all. Did you know that the synchronized keyword serializes access to data visibility as well as access to the code block it surrounds? I was definitely not aware of this prior to reading this chapter =)

Chapter 3: The Ingredients of an Android Application

This chapter is a relatively interesting discussion of the basic components that make up an Android app: Activities, Intents, Tasks, Services, and Content Providers. There’s also some basic information on the Android manifest, application resources, and the application life cycle. Not a bad chapter.

Chapter 4: Getting Your Application Into Users’ Hands

This chapter deals mostly with using signing certificates to sign your app, some very basic information on submitting your app to the Android Market, and a brief mention of supporting different screen sizes. There’s not much detail here as far as the actual publication of the app or how exactly to make your app work well with different screen sizes and densities, but considering how thorough the Android Dev Guide is in terms of supporting multiple screens, the authors probably thought it would be silly to add all of this information to the book.

Chapter 5: Eclipse for Android Software Development

This chapter is mostly a treatise on the different kinds of views you can use in Eclipse while writing code or debugging your app. For seasoned Eclipse users, this section is pretty skippable. The chapter also mentions a “static analyzer” for finding bugs in your app called FindBugs. I haven’t used this tool before, but I would definitely consider it now that I’ve read this chapter.

Chapter 6: Effective Java for Android

The most interesting part of this chapter is the discussion on concurrency / threads in Android. Rule #1 of Android development is to not perform long-running operations in the UI thread unless you want your users to get Application Not Responding errors, which are Very Bad. So this chapter discusses how you can use AsyncTasks to perform “slow” operations on a new thread so as not to block the UI thread. There’s also some discussion of serialization and Parcelables in this chapter, which are important concepts to master in Android. However, it did seem a little odd to me that concurrency and serialization would be in the same chapter here.

Chapter 7: Building a View

We’re seven chapters into this book and we’re just now discussing Views and how they’re used to design our app’s user interface. Interesting! It seems to me that this chapter should have come up a LOT sooner. Either way, there’s some discussion of how Views are laid out, especially with the LinearLayout. What I found odd about this chapter is that despite being called “Building a View”, the main flow of the chapter is about Android’s MVC architecture, which is a good way to think about programming in Android, but 2/3 of the chapter has nothing to do with Views. The last part of the chapter shows how to create a Menu for your users. I’m torn on whether or not this should be here considering that Menus are deprecated in Android 3.0 and later.

Chapter 8: Fragments and Multiplatform Support

I’m not sure what this chapter has to do with multiplatform support, because it seems to be entirely about fragments. I’m not too thrilled to see this chapter here – fragments are a relatively advanced UI concept, and we’re learning about it right after we learned how to use Views and event callbacks? Plus, this chapter is really short and I feel like fragments deserve a lot more explanation than given here.

Chapter 9: Drawing 2D and 3D Graphics

I have some mixed feelings on this chapter. The focus of this chapter seems to be describing some of the lower-level things you can do in Android to draw 2D and 3D graphics, especially if you are creating your own widgets / UI components. There’s also some explanation of matrix transformations, effects, and animations you can apply to your Views. There’s also a brief introduction to using OpenGL in Android.

While I was amused to see that you can do all of these transformations and effects in Android, it seems unlikely that most new Android developers would jump right in to creating their own UI components, so I’m not sure why this chapter wasn’t an advanced topic.

Chapter 10: Handling and Persisting Data

The focus of this chapter is mainly how to use Android’s built-in support for SQLite in order to persist and retrieve your application’s data in a relational database. Now we’re talking! Unlike some of the previous chapters, I believe this is something every new Android dev should learn as soon as possible. My only possible complaint about this chapter is that the Shared Preferences Database isn’t even mentioned as a possible way to store very simple app data, but I can overlook that considering that SQLite is a much more scalable solution for persisting data.

Chapter 11: A Framework for a Well-Behaved Application

I’m not sure why this chapter is called what it is, because this chapter is all about an activity or fragment’s lifecycle, as well as how to save and restore state correctly during the lifecycle. There’s also some interesting content on task behavior (and how tasks are launched), though I’m not sure if the intent flags are explained in a way that really makes sense. Still, not a bad chapter aside from its name =)

Chapter 12: Using Content Providers

This is one of the chapters I was most looking forward to when reading this book, because I haven’t had a lot of previous experience working with (or creating my own) content providers. This chapter explains how they work and constructs an example of how they could be used in a small sample application. Overall this chapter is interesting and easy enough to follow.

Chapter 13: Exploring Content Providers

This chapter is a bit like a continuation of the last chapter, where the authors use the previously implemented content provider to create a full application to search and display YouTube videos. Unfortunately, this chapter shows why books aren’t always the best medium for teaching; it’s full of source listings spanning multiple pages and with little contextual glue between them. I found myself wishing that I could find the source for this example online somewhere and just look through the code myself rather than trying to read and digest the source code. Trying to read the source and understand the explanations ultimately proved futile, so despite my best efforts I gave up on finishing the chapter and moved on. I really think this book would have been better if the source had been available online.

Chapters 14-16: Multimedia / Location / Sensors / Speech / Accessibility / Etc

These chapters are considered “advanced topics”, such as playing/recording video or audio on Android, location and mapping, sensors, near-field communications, speech, gestures, accessibility, etc. While these topics are interesting, they also seem to be covered pretty well already on the Android Dev Guide.

Chapter 17: Communication, Identity, Sync, and Social Media

This chapter marries two very different things; the first being an example of how your app could sync contact data with a remote service, the second being using Bluetooth in your app. Why these two topics are in the same chapter is beyond me, but since the former doesn’t seem to be easily discoverable in the Android Dev Guide, it made the chapter worth reading.

Chapter 18: The Android Native Development Kit

This might be one of my favorite chapters in the book. The Android Dev Guide doesn’t really cover the NDK in a long-form topic – it’s mostly just a brief explanation and an offer to download it and play with sample applications. Fair enough, but how are developers supposed to know if the NDK is worth playing with in the first place? This chapter explains what it’s for and how to use it in a way that is concise and easy to read.

Closing Thoughts

I thought that this book was a decent introduction to the Android platform, but the way that the information is split into chapters makes almost no sense. Some topics are too advanced to be covered in early chapters; other chapters feature multiple concepts that have no discernible relation to each other. If there was one thing I would recommend to the authors, it would be to come up with a more logical, linear progression from basic Android topics to advanced ones.

The other main problem with this book is much deeper. In a vacuum, I think this book has inherent value in what in can teach about the Android platform, but it must be compared against the available alternatives. One such alternative is the Android Dev Guide itself, which is free. So the real question is, does this book contain $27 worth of content that you cannot get from reading the Android Dev Guide? Unfortunately I think the answer is no. The Dev Guide is always up to date, contains more information than this book does, and you won’t find yourself struggling to make it through chapter 13. If you prefer reading books to reading websites, or can’t access the internet, or you have about $27 more than you know what to do with, then buy this book. Otherwise, just read the Dev Guide.

Book Review: The Nomadic Developer

I recently bought a couple of new software development books from Amazon, including The Passionate Programmer, Programming Android, The Busy Coder’s Guide to Advanced Android Development, and The Nomadic Developer. Of these, the only book I’ve finished so far has been The Nomadic Developer, so I thought I’d write up a quick book review on the blog.

Why I bought this book

As an indie Android app developer, I have worked on a couple of apps that are selling in the Android Market, namely iSyncr WiFi and Cheetah Sync, as a software contractor for JRT Studio. I am very proud of these apps, and I enjoy adding new features and fixing bugs in them as they arise.

However, I get paid from these apps only when customers buy them, and while I could spend 40+ hours a week adding new features and fixing bugs, this won’t necessarily result in a dramatic increase in the number of people who buy these apps. In economic terms, according to the supply curve of labor, in general an increase in expected wages will tend to cause workers such as myself to supply more labor, but if the demand for the app remains relatively constant, my wages are fixed and so is my desire to trade off leisure time for labor time =)

What am I getting at? Basically, this year I’m looking to get into some paid, hourly contract / consulting work to supplement my indie app income, so that I could have some more control over the correlation between working more hours and earning more income. So I bought this book to see if it had any insights into the world of contracting as a “nomadic developer.”

Things I learned from this book

It’s embarrassing to admit, but before I bought this book I was a little bit confused about the difference between contracting and consulting. Before I started working on Android apps, I was employed full-time as a W-2 employee at National Instruments and then Microsoft, so I was painfully ignorant about the “other” methods of paid software development.

So, first and foremost, I learned that contracting typically means working on short-term software development projects as a “software mercenary” until the job is complete, and then you go back to doing whatever you were doing before. Whereas consulting typically means joining a consulting firm where you are expected to be work on projects to which you are assigned and you are expected to bill hours without spending too much time “on the bench.” Also, typically the scope of a software consultant goes much further beyond simply implementing software according to provided specifications – it often typically requires business acumen, people skills, and advising.

Because this book focuses exclusively on joining a consulting firm, I didn’t learn anything about what software contracting looks like or how to thrive in that environment, but I did learn a lot about what it’s like to work at a consulting firm, should I ever be interested in doing that in the future.

Things I didn’t like about this book

As I mentioned before, I initially bought this book because I thought it might have some insights into software contracting, so I didn’t realize when I purchased it that it was first and foremost a guide to surviving and thriving as a consultant working for a consulting firm. That was my mistake when I bought the book, but it meant that many of the chapters seemed completely irrelevant to my interests.

For example the chapter called “The Seven Deadly Firms” lays out 7 types of consulting firm personalities that are worth avoiding if possible when interviewing for a consulting job, and the chapter explains how you can identify these firms and avoid them. While somewhat interesting, it was pretty irrelevant to me. This also applies to “How Technology Consulting Firms Work”, which focused mostly on how to deal with the account executive, engagement manager, recruiter, consulting manager, etc., and the “Your Career Path” chapter, which focuses mostly on career paths inside of IT consulting.

Things I liked about this book

Now that I’ve got my complaints out of the way, I’ll focus on the things I did like about this book. There’s actually a lot of interesting insight in this book that’s really applicable to any software developer, not just consultants. Chapter 4, “Ten Unstated Traits That Technology Consulting Firms Look For”, is really a recipe for any software developer looking to become a valuable and well-known developer in their tech community. For example:

  • Be good at being interviewed for jobs
  • Always be learning
  • Be active in your technical community / develop your network
  • Work on your writing skills

Chapters 6 and 7, “Surviving” and “Thriving” are full of excellent advice for any developer as well, especially the advice to do what you enjoy, and that billing work = good work. After all, developers who create profit for a company don’t get fired.

Lastly, chapter 9, “Avoiding Career-Limiting Moves”, is a little bit silly, since it’s themed on the seven deadly sins, but it does offer some good (if obvious) advice about the traps that software developers often get themselves into.


Overall, I think that this book has a lot of insights for any software developer, especially those interested in becoming a software consultant, but if you’re not interested in doing consulting at a consulting firm then maybe this isn’t quite the right book for you. Many of the same insights and advice for surviving and thriving as a software developer are also in the similar book The Passionate Programmer, which is approximately half the cost and you won’t waste any time trying to read chapters that don’t apply to you =)

8 Rules for Losing Weight Like an Engineer


Well, it’s January, and that means that many Americans have recently made some new resolutions for 2012, and one of the most common resolutions is to lose weight. So, despite the fact that I am a software engineer and not a personal trainer or nutritionist, I’m going to offer some unsolicited advice on how to lose weight like an engineer =)

Engineers like to measure, quantize, track, and analyze data in order to achieve their goals, and this approach actually does make a lot of sense for losing weight.

Rule #1: 3500 calories is roughly equal to a pound

One of the underlying assumptions you’ll want to make when trying to lose weight like an engineer is that, roughly speaking, 3500 calories is equal to a pound of body weight. In other words, if you consume 3500 more calories in a day, a week, or a month than you burn, then at the end of that period of time you will be roughly one pound heavier. Conversely, if you burn 3500 more calories in a day, a week, or a month than you eat, then you will be roughly one pound lighter.

Rule #2: Calculate Your Caloric Baseline

Your caloric baseline is the average number of calories that you burn in a day, without factoring in workouts or exercise. This number is basically the sum of your Basal Metabolic Rate (your daily energy expenditure at rest) plus any other typical activity that you perform during your day while working, recreation, doing errands, etc. This number also happens to be the average number of calories you’d need to eat in a day to maintain the same weight indefinitely.

It would be pretty inconvenient to spend an entire day in bed hooked up to a calorimetry machine in order to calculate your basal metabolic rate, and it would also be pretty annoying to try to go about your daily business hooked up to a machine in order to figure out your caloric baseline. Fortunately, there are several caloric baseline calculators available on the web that can guesstimate your caloric needs based on your height, weight, age, and general activity level. You’ll probably want to choose the “sedentary” or “light” options so that you can track your exercise separately.

Rule #3: Calculate Your Caloric Goal

One of the biggest mistakes you can make is to try to lose too much weight at once via crash dieting. The generally accepted maximum amount of weight you should try to lose in a week is about two pounds. Why?

  • You could easily lose lean mass (muscle) in addition to fat.
  • You are physiologically and psychologically more likely to binge eat after an unsustainable crash diet.

So, let’s say you want to lose about one pound per week. So your goal is a 3500-calorie deficit per week, or 500 calories per day (when divided by seven). So subtract 500 calories from your caloric baseline and you have your average caloric goal.

Rule #4: Track What You Eat

Now that you have a caloric goal, the next step is to measure your diet to see how many calories it contains. There are a number of websites that provide calorie information and calorie tracking:

Personally, I like Daily Plate because it has a very large and easily-searchable food database, it allows you to track your exercise as well as food, and it can actually calculate and track your progress against a caloric goal.

Another thing you might want to consider, to make measuring calories easier, is to purchase a food scale and use it to determine exactly how much of certain ingredients you’re using when cooking or preparing food. For example if you’re making a sandwich, or cooking some chicken, it can be difficult to tell just how many ounces of meat you’re using without one.

Rule #5: All Calories Are Equal, Except When They’re Not

It’s true that all calories, whether they come from fat, protein, carbohydrates, or sugar, are all basically the same in that they will all cause you to gain weight if you eat too much of them. But, there are some caveats to the basic rule that “a calorie is a calorie”:

  • Your diet should include at least a sizable amount of protein so that you maintain muscle mass. Without protein, you’ll lose muscle mass fast.
  • Some foods are more filling than others per calorie, especially ones with low energy density. Fruits, vegetables, and lean proteins generally have high volume and/or fiber compared to their calorie content, so they help you feel full longer.
  • Salt is not necessarily as bad as we might think it is, but it can lead to water retention. Further, eating salty foods (like chips or fries) can lead to eating more of a food than you would have otherwise because it tastes so good.
  • Alcohol can be pretty bad for weight loss. First, because you are consuming “empty calories” that don’t actually make you feel full. Second, alcohol often leads to increased appetite, which explains late night post-drinking cravings for Jack in the Box. This article does a really good job of explaining alcohol’s overall effect on weight loss.

Rule #6: Track What You Do

If you calculated your daily caloric needs as a “sedentary” or “light” lifestyle, then you’ll want to keep track of how many calories you burn while doing exercise. There are three basic ways to track calories burned while working out:

  1. If you’re using a cardio machine, such as a treadmill or elliptical machine, these will generally estimate your calories burned based on your weight and your speed. However, cardio machines are notorious for overestimating calories burned while exercising.
  2. Use an online calories burned calculator to guesstimate how many calories you’ve burned. This is also not particularly accurate because these calculators assume a relatively consistent amount of calories burned per sport, but intensity levels can vary greatly among individuals.
  3. Buy and use a Heart-Rate Monitor with a calorie count feature. This should take the actual intensity of your workout into account and should be much more accurate than the other two methods.

In addition to the overestimation problem of counting calories, there’s another problem – we tend to focus on the total calories burned of an exercise, not the net caloric burn. In other words, we fail to subtract the extra calories we burned working out versus what we would have been doing instead (like working or using the computer). So when you track calories burned, you might want to intentionally under-report them or possibly not track them at all.

Rule #7: Track What You Weigh

This one is pretty simple. Get an accurate bathroom scale and make it a habit to weigh yourself every day right after you wake up (and after going to the bathroom). Your weight tends to be most “stable” in the morning, so this is the best time to do it. Why do this?

  • It keeps you accountable. Psychologically, it’s much harder to let yourself go and overeat if you see your numbers creeping up.
  • It gives you more data to play with, and engineers love data.

The second part is kind of a joke, but if you track your daily weight you could use it to plot a moving average to see how your weight is trending over time. Since weight tends to fluctuate day-to-day, it can be more visually motivating to see your weight tending downward over time as you stick to your caloric goals.

Rule #8: Weight Isn’t Everything

It’s funny, we tend to make resolutions like “Lose 10 pounds this year”, but we fail to account for the fact that losing weight and losing fat are not quite the same thing. We also tend to equate fitness with being thin, but they’re really not the same thing at all.

If you’ve been tracking your diet and your exercise, you may have noticed that it’s far easier to eat one less slice of pizza than it is to jog for half an hour per day, so you might be tempted to skip exercising and just focus on your diet. But this would be a mistake.

Consider this – would you rather be a slightly overweight person who runs half-marathons, or a very skinny person who can barely walk from their house to their car without getting winded? Let’s be honest, the first person is more fit, and fitness is more important than weight for health.

Further, for every pound of muscle mass that you have, your basal metabolic rate goes up, because those muscles are hungry for calories (especially protein). So over time as you develop more muscle from working out, lifting weights, or doing sports, it should become easier to burn more fat.

I could write an entirely new post on various pros and cons of different exercises and sports, but suffice to say that you should definitely include some kind of regular exercise into your routine while trying to lose weight, in order to maintain muscle mass while losing fat.

Top Ten Things I Like About Seattle

10. Portland / Vancouver

Both Portland and Vancouver are only a few short hours away from Seattle by car, or if you prefer, you can take the train. I’ve been to Portland a few times and I really like it. I’ve also spent about a week in Vancouver and it’s also a pretty cool place to be. I have to admit, I prefer the Portland / Vancouver combo to Houston and Dallas.

9. Sushi / Thai / Indian / Teriyaki / Chinese

Let’s face it, Seattle is not known for its Tex-Mex. But once you get over that (if that’s possible), you can learn to enjoy the diverse range of Asian cuisine available here. I’m especially fond of the Sushi… and the Indian… and the Thai. Okay, I’ll only pick my top three.

8. Nerd Culture (VG Live, PAX, Microsoft, etc.)

The nerd culture is very strong in Seattle / Bellevue, and I kinda like it. This is true of Austin too of course, but in Seattle I have attended PAX and Video Games Live, neither of which I did in Austin. Most of my best friends in Seattle play video games with me, which is all kinds of awesome. For some reason my friends in Austin were much harder to convince to play video games with me – weird!

7. Stone Gardens, Vertical World, and Marymoor Park

Seattle is host to two competing climbing gym companies, Verical World and Stone Gardens, and this is a good thing. Between the two and the three Seattle / Redmond locations, you can go for an awesome bouldering experience, an awesome toprope/lead experience, or a mix of both. Vertical World even hosts an “outdoor club” in the summer which takes people out for climbing on Friday evenings. Awesome. These gyms are truly key for the rainy winter season.

Marymoor Park is also excellent, because it features a sizable outdoor climbing structure in the park where you can climb for the completely reasonable price of $1 to park. This is a great place to practice some crack climbing and leading, if you’re into that sort of thing.

6. Greenlake

Seattle has a lot of bodies of water all over the place. Lake Washington, Lake Sammamish, even South Lake, but my favorite is Greenlake. A relatively small lake north of downtown Seattle, this lake features a 2.8 mile bike/walk path which is absolutely beautiful in the summer. This is my favorite place to run 2.8 miles.

5. Mount Rainier

I’ve never climbed Mount Rainier, but on a really clear day you can see it from Seattle, and it looks awesome. Like a huge distant giant, guarding over the city. You can make a pretty good day trip out of driving around this huge mountain, taking in views from Crystal Mountain, Sunrise Lookout Point, and more. You can also see it from the air when you fly into or out of Seattle.

4. Long Summer Days

The northern latitude makes winters miserable, but the summers more than make up for it. The omnipresent rain goes away, the weather turns into sunny 70s nearly every day, and best of all, the sun doesn’t go down until 9pm in June. I’m not kidding, it’s amazing.

3. Snowboarding at Snoqualmie, Stevens, Crystal, Bachelor, and Whistler

Washington isn’t known for its snow, and it’s certainly no rival to Colorado, but compared to Texas, it’s a winter wonderland. There’s actually quite a bit of variety available between Canada, Washington, and Oregon, with Snoqualmie, Steven’s Pass, Crystal Mountain, Mt. Bachelor, and more. I haven’t even been to them all yet. And did I mention Whistler? It’s like the biggest mountain ever. Seriously. It’s much bigger than Vail.

2. Surfing at Westport

I had no idea when I moved to Seattle that surfing was even an option here. But it is, thanks to the small town of Westport. The city doesn’t produce waves, but the nearby finger jetty does, and every time I’ve been to Westport I’ve caught waves. You might want to check the surf forecast of course, but this town is only 2.5 hours from Seattle, and has 2-3 surf shops that you can rent gear at, as well as a couple great places for lunch or a post-surf snack/beer. Part of me wants to move to Westport just so I can surf every day.

1. Rock Climbing at Vantage, Exit 38, and Smith Rock

Between Exit 38, Vantage, and Smith Rock, you can easily go sport climbing within a half-hour, 2.5 hours, or 8 hours from Seattle, respectively.

Exit 38 is not particularly big, and I’m not super fond of the granite, but it’s a ridiculously convenient crag for its proximity to Seattle. Great for post-work evening climbs in the summer.

Vantage is easily my favorite sport area in Washington. It’s basically several lines of columnar basalt, varying from about 50 feet tall to nearly 100, and I absolutely love the way this rock feels. Since it’s located east of the Cascades in a somewhat desert-like part of Washington, it’s often hot and sunny here even when it’s raining and miserable in Seattle. Some truly epic climbs here, and I have only explored a portion of it.

Smith Rock is well known even outside of Oregon for being an epic place for sport climbing. There are literally hundreds of routes here, and they are stiff. It’s a bit harder to get to, since it’s about an 8-hour drive, but it’s definitely worth it for a long weekend.

In addition to these three, there are numerous other places nearby: Squamish in Canada, Index, Leavenworth, Darrington, Mount Erie, Tieton, and Mazama, half of which I’ve never even visited yet.



For better or for worse, I use iTunes to manage the music on my iPhone. And since I have to have iTunes installed on my computer, I might as well also use it to rip my audio CDs into music files. Traditionally, the file format of choice was MP3, also known as MPEG-1 Audio Layer 3. However, a few years ago I heard about a new file format called AAC (Advanced Audio Coding) promising better sound quality than MP3s at similar bitrates, which iTunes also supports. So I went ahead with a project to re-rip all of my CDs from MP3 into AAC files, which by the way, have the file extension .m4a.

The problem I encountered was that I really disliked the file/folder structure that iTunes automatically uses when it rips your CDs. There seems to be no way to customize this file/folder structure in iTunes, so if you really care about what your files are named and in what directories they are placed, as I do, you’re stuck renaming all of your music files by hand, which is a major pain.

Therefore RenameM4A was born. This simple C# program allows you to select a set of M4A files and rename them according to a rename rule.

Rename Rules: Using RenameM4A

A rename rule is a simple way of enforcing a particular file/folder structure for any M4A file that is to be renamed. Because this is a very simple project, right now the rename rules support the following tags:

As you can see, the tags are surrounded by brackets which denote some kind of information contained within the file. All AAC files have metadata embedded in them which tells you information about the track and where it came from. When RenameM4A processes each file, it looks at the rename rule and replaces any tags encountered with information gathered from the file itself. This step takes place when you press the Preview button, which generates a list of files to be renamed, giving their original file locations and the new file location.

Then, you can hit either the Rename button or the Copy button to move or copy the file according to the destination paths given in the GridView. In fact, if you want to you can edit the GridView in order to fix any discrepancies that may have occurred when running the rule. For example, you might have a track from a particular band’s album where another artist is featured. Since you want the entire album contained within the same folder, you might edit the line for that track to remove the name of the other artist from the directory name.

If you take a look at the rename rule combo box, you can also see that there are a number of pre-loaded rename rules that may appeal to you.

How is AAC better than MP3?

In short, AAC files have superior sound quality and transparency than MP3s do, for the same bitrate. Put another way, you can encode your music at a lower bitrate than an MP3 for the same sound quality. Of course, there are a lot of other improvements, including:

  • More sample frequencies
  • Up to 48 channels of audio
  • Better handling of audio frequencies above 16 kHz
  • More flexibility in designing codecs

Advanced Audio Coding File Format

A SourceForge project called Atomic Parsley appears to have a lot of good information on the MPEG-4 file format, especially as it relates to M4A files. As it turns out, the AAC data is actually just a section within an MPEG-4 file, which can actually contain all kinds of nested data. Each nested section in an MPEG-4 file is called an atom (or sometimes a box); the first four bytes of each box defines its length in bytes, the next four is the name of the box, and the rest is either data or other nested boxes. In a way, that’s pretty similar to how XML works.

Since the only thing that RenameM4A really cares about is the album, artist, year, title, and track number, it simply scans the file for the five atoms it’s interested in and grabs the data. It’s also worth noting that text data appears to be stored in UTF-8 format, so you can’t simply assume that it will be straight-up ASCII.

Recent Improvements

This blog post actually took me a ridiculously long time to write. Mainly that’s because I was a bit embarrassed to release my source code; it was written several years ago and the way it was parsing M4A files was extremely naive. Recently, I rewrote most of the parsing code to make the following improvements:

  • More intelligent parsing; use atom information to jump to the sub-atoms of interest instead of scanning the entire file for “udta” and then each meta tag.
  • Reading only part of the file; since all metadata is under the “moov” atom, RenameM4A only needs to load the portion of the file under moov. The vast majority of a music file’s size is its music data, which is under the separate mdat atom, so we can avoid loading the entire file into memory when we don’t need to.

I did a simple benchmark test of the new and old parsing algorithms by trying to parse 14 half-hour audio files ten times each. The old parser takes about 36 seconds; the new one takes 0.14 seconds; an improvement of around 270 times faster. Not bad.

Download RenameM4A Source + Executable

[RenameM4A Source + Executable]
Note: Requires .NET Framework 2.0 or later.


MPEG-1 Audio Layer 3

Advanced Audio Coding

MPEG-4 Part 14

Atomic Parsley

Atoms, Boxes, Parents, Children & hex (oh my)

Subject: Dissection of m4a format – msg#00046

How To Install Perforce Source Control On Your Windows Home Server

Personal Source Control

If you’re a developer like me, chances are that in addition to the programming you do at work, you probably also have some personal projects that you work on at home as well. Whether you are consulting on the side, or just want to write your own applications, it may make sense for you to have a source control server of your own. There are many benefits to having a home source control system, including:

  • Having a backup of your source code
  • Access to revision history and previous versions
  • Single repository for source code across multiple machines

These are all very good things. It’s very reassuring to know that your source code will still exist on the source control server if your hard drive should crash and burn. It’s also nice to be able to revert to previous versions of your code should you irreparably break something. And lastly being able to easily synchronize source between multiple machines, such as your desktop and laptop, is very handy.

Why Perforce?

You can of course use any source control system you are most comfortable with. I used Perforce quite a bit at National Instruments, and it makes sense to me. I like the ability to have multiple changesets at once. I like that I have a consistent, semi-permanent mapping from my hard drive to the source depot. And most of all, I like that I can install it for free.

I also previously installed an SVN server, and was using TortoiseSVN for a while to check in code on my home network. This kinda sorta works, but… I don’t really like it. It’s hard to explain, but I am so familiar with the way that Perforce works that using TortoiseSVN is a pain. For example, it doesn’t seem like there is any permanent mapping between the source server and your hard drive. You can check out a folder to anywhere, and update a folder from anywhere, but it’s really easy to screw it up. And as for checking out code, well, it seems like you don’t check it out so much as you download it locally, edit it, and then try to commit your changes. I’m sure there are people out there that use it and love it, but I can’t wrap my head around the way it’s supposed to work, and I’d rather use a paradigm much more familiar to me like the one Perforce uses.

Installing P4D

You can download the Perforce Server, called P4D, from Perforce Downloads. I chose Windows for 32-bit Intel (x86) for my machine. Install it. You can pretty much keep all of the default options.

Once it’s installed, you can take a look at your system Services, and you should see that the Perforce service is Started and is Automatic.

Create a New User and a Depot

Use the command p4 user -f from a command prompt in the Perforce directory to create a new user. Your text editor will open a temporary file used to configure your user’s options. You can stick to simply editing the full name and adding a password.

Use the command p4 depot to create a new source depot. You will probably already have a default depot called “depot”, but I added a new one because I want it to be called Root, and I wanted it to be located in D:\Root\ on my server. As before, when you execute this command a temporary document will open in your text editor. Most likely you will just want to change the Map parameter.

Fix Your Firewall

In order to allow connections from other machines on your network, you need to tell your Windows Home Server to allow connections on port 1666, because that’s the port that the Perforce server uses by default. Open up your Windows Firewall Settings, select the Exceptions tab, and click on the Add Port button. Type in “Perforce” and “1666” respectively. Now your Perforce client should be able to connect to the server.

Installing P4V

Now you’re ready to install the Perforce Visual Client, or P4V, on your desktop or laptop. Again, you can download the client from Perforce Downloads. Go ahead and install. Again, you can leave most of the options as default, but you will want to change the server name to match the name of your Windows Home Server.

Go ahead and run the Connection Setup Wizard. You will probably have to manually choose your server name, and to login with the username and password you created on the server. Don’t bother copying files from the server to your workspace, as there are no files in your depot yet.

Once that’s done, your P4V window should look approximately like this:

Creating a Client Workspace

Perforce allows each user to have a set of client workspaces, which is essentially just a way of mapping the depot folders you are interested in to a local drive on your machine. Create a new workspace like so:

Enter a name for your new workspace; generally people use some combination of their username and machine name.

Now, you have to define your client spec. The most important two fields are the Root and the View. Here I set my root to D:/Perforce/Artemis_Hexar/. All of my source files will be under this directory. Next I set my View to a single line mapping of //Root/… //Artemis_Hexar/Root/… The ellipses are a symbol that means all subfolders and files. So here I’m just saying that everything under the Root depot should go under the clientspec, in the Root directory. You can do some interesting things with the View, including exclusions and inclusions, but it’s probably not necessary for our purposes here.

Now your client probably looks something like this:

Add Files to Source Control

Lastly, it’s time to add some files to source control. Take some files that you want to add, and copy them into your clientspec root. For me that means D:\Perforce\Artemis_Hexar\Root\. Next, click on the Workspace View tab so that you can see your local disk tree instead of the depot tree. Right click on the files/folders you want to add and choose “Mark for Add…” This will add them to the default changelist.

Lastly, right-click on the default changelist and submit. You should write a comment on the reason for the change, and make sure you really do want to submit all of the files in that changelist. Now, if you go back to the Depot view, you can see that your files have been added to the depot, and you can check them out for editing, deletion, or rename.


So that’s it! Congratulations, now your personal projects have professional source control. Check in some code, and celebrate with the food/beverage of your choice.