Archive for the ‘Geek’ Category

SproutCore: JavaScript on Rails?

Tuesday, June 24th, 2008

I took a few minutes to read the Hello World tutorial for SproutCore. Looks mighty interesting. The first thing I thought was that it looks like JavaScript on Rails. The framework is installed the same way (rubygems). It uses what looks like rubigen to build out your application skeleton as well as providing other code generators. It even uses erb with rails style tag helpers for the views.

Code wise, it looks like they’ve taken some hints from Cocoa. Views are designed to be localized similar to Cocoa’s nib (or xib) files. Properties are accessed through getters and setters to allow for more hooks. There is support for public and private variables.

I’m not sure I’m ready to jump on this bandwagon completely just yet, but it looks promising. I’ll have to get in there and really mess with it before I can really know what’s what.

What if you Break It?

Friday, June 20th, 2008

As part of the deal around getting the price of the iPhone cut in half, AT&T is mandating that all iPhones be activated in store as part of the purchase process. They do not offer a non-subsidized price at all. What happens if you break your shiny new iPhone. The thing is made, in large part, of glass. Can you get a new one? Do you have to suffer yet another new contract? Credit check? Two more years of lock-in?

MGS4

Tuesday, June 17th, 2008

Over the weekend, my brother brought over the new Metal Gear Solid in the 4th and final (so we’re told) attempt to get me to appreciate the franchise. It worked. I really have not been able to enjoy any of the previous games. Something about sneaking games tends to just frustrate rather than entertain me. After a few rounds of sneak, get caught, fight, reset… I just lose it and start shooting up the place. The problem has been that it was completely impossible to make progress in many sneaking games with this method. In MGS4, you could theoretically blast your way though it all. This freedom actually makes the sneaking components much more compelling to me. So much so, in fact, that I am actually enjoying the sneaking component.

I’m at the beginning of the third act of the game now, and it’s calling to me. I really wish I had another day of weekend to just plant myself in front of the thing and complete the game. The level of polish and the pure breadth of the possibilities is totally compelling.

I can’t give the game a completely positive review, though. The online component, particularly the process involved in getting into a game, is horrid. Let me explain:

  • Launch the game
  • Select “Metal Gear Online”
  • Wait for yet another install process
  • Find out I need to install a patch to the system software
  • Exit the game
  • Launch system updater
  • Wait for download
  • Click through several pages of crap
  • Wait for install process
  • Wait for system reboot
  • Launch the game
  • Select “Metal Gear Online”
  • Wait for game to update itself
  • Exit the game
  • Launch the game
  • Select “Metal Gear Online”
  • Read through horrible description of the grueling process of creating a user account
  • Fill out registration form using an embedded web browser including:
    • Two different usernames with different naming rules
    • Two different passwords with different rules, each entered twice
    • Email address (entered twice)
    • Basic name, number, and address info
  • Close embedded browser
  • Enter username and password (don’t forget which ones)
  • Suffer through “tips” on every page of the character setup process (these are necessary because you would otherwise have no fucking clue how to use this interface)
  • Create your character. Don’t mess up. You can only create one without paying money.
  • Recreate your friends list, as this game doesn’t use the system wide friends lists
  • Dig through several menus to find your friends and find the game they’re in on the games list
  • Attempt to join the game, and hope it works
  • Play, if you’re not too tired

This appears to be basically par for the course on the PS3. I have to say, it’s pretty appalling, especially compared to its competitor. Most of my online play happens on my XBox 360, where the friends list is pervasive across every game and even voice chat works seamlessly across titles. One the XBox, I can accept a game invite from anywhere on the system, including other games or DVDs. The system will actually ask for the correct disc and then, upon insertion, take me directly to the game lobby where my friend is.

The experience of trying to play online severely detracts from my enjoyment of it. Once you’re in a game, it’s fun and seems to suffer little from lag. The surprising lack of polish in the online experience is bafflingly contrasting to the glossy sheen of the single player experience. Based on the merit of the single player content alone I highly recommend anyone who owns a Planet Earth player give this game a test drive. Even if you aren’t a fan of the series, you may find something to like in this game. The online component is interesting if you can get to the meat of it, but you have to really want it.

What’s up with Hoe

Wednesday, June 11th, 2008

I just don’t get it. Hoe looks like a convenience library for creating and deploying gems. But it’s not convenient at all. In fact, due to the extremely sparse documentation, it seems more difficult to use that the standard rake tasks that everybody already has installed.

Maybe I’m missing something, but having worked with Hoe on a project for the last few weeks, the most satisfying part was ripping the damn thing out of my project.

Disclaimer: I used newgem to build my project, so it could be their provided templates rather than Hoe itself that are so confounding.

Acts As State Machine

Monday, June 9th, 2008

What the heck is a state machine and why should you use one? Wikipedia say:

A finite state machine or finite state automaton or simply a state machine, is a model of behavior composed of a finite number of states, transitions between those states, and actions.

Put simply, a finite state machine (FSM) is a design pattern for handling the progression of an object through a set of arbitrary “states” and the transitions between those states. This is a really useful concept whenever you have some data that moves through a workflow. Let’s look at the example of a comment on a blog entry. The “happy path” steps are as follows:

  • A user posts the comment
  • The comment is run through an spam filter
  • The comment is approved by the moderator
  • The comment is displayed on the blog

(more…)

Unit Testing Saves the Day

Sunday, June 8th, 2008

I had been using XMLSimple to parse a bunch of XML input coming from Flex. The client discovered a sequence of events that would cause XMLSimple to stop parsing the CDATA from any XML until the server was restarted. After trying to debug what on Earth could be causing this issue and getting nowhere, I decided to just rip out XMLSimple and use the more battle hardened REXML for my parsing.

Lucky for me, I’d gone to the trouble to write good tests for these actions. It only took me a few minutes to completely change the way the handler was parsing the XML and, because I have a good test suite, I was able to confidently deploy the new version without introducing any new issues. Needless to say, the client was quite pleased. Thank you unit tests!

Testing Rake Tasks

Friday, June 6th, 2008

I recently worked on a project where I was essentially building a library of rake tasks. Obviously, I wanted to be a good citizen and unit test them. Here are a few notes on techniques I used.

You’re going to want to create a complete sample project to test against. One tricky thing about creating a library rather than an app is that you need an app to test against. It actually turns out to be really helpful because you can create exactly the application you need to test against and leave anything unrelated out. For example, if your task is going to take a bunch of code and bundle it into a gem, you’ll want to put together a very simple bit of code in the proper structure so you can test against it. Put things in your code that are easy to grep for.

You don’t always need to run your tasks for every test. For example, if you have some file or rule based tasks, use the Task#requirements array to your advantage. If something’s not working as expected, it makes sense to first make sure your rules are choosing the proper files. This goes for any set of task dependencies.

Do something about rake’s output. Rake likes to tell you all about the marvelous things it’s doing. This can make reading your test results really freaking difficult. I found a really sweet module in rake’s own test library called CaptureStdout. It provides a two methods, capture_stdout and capture_stderr. These methods accept a block and silence the output of anything executed within them.

Make yourself some convenience methods. You can execute tasks from within a rake environment using Rake::Task[:task_name].invoke. How many times do you want to type that? If your answer is anything shy of “One million please!”, you probably want to make yourself a helper for that. My recommendation is that you buddy your helper up with capture_stdout in any way you find clever.

Think about any environment conditions that may effect your code. This is especially something to consider if you’re dynamically generating tasks based on some external variable (such as RAILS_ENV). The best way I’ve found to handle this is to create separate test files for each environment that need to be tested specifically. Then, just make sure you set the property before you require your library.

Use your setup method efficiently. Make sure you clean any temporary or generated files to give the next test a clean working environment.

Think about how long tasks will take. If you’re only testing a subset of the functionality of your library, choose to test against the most specific task possible. Otherwise, you will end up waiting a long time for your full stack to run in every test.

Lastly, remember that rake, by default, will remember if a task has been run and keep it from running again in the same execution. This is great for avoiding circular dependencies in a running app, but it makes testing just that much more a pain. Allow me to offer this snippet for your enjoyment:

Rake.application.tasks.each {|t| t.instance_eval{@already_invoked = false}}

Going to Railsconf

Tuesday, May 27th, 2008

I’m going to Railsconf in a few days. I’ve been spending much of my free time and, recently, a good bit of my professional time working with Rails. In preparing for the conference, I’ve been doing a ton of reading and a good bit of rails hacking.

I’ve been mostly silent on here for the last few weeks. This is partially because I’ve been so bummed about being vandalized and partially because I’ve been spending much of my would-be blogging time on building my own blog engine. Sure, Wordpress is good enough for what I need, but it’s such a big target for automated hacking. Also, I’m not really learning much by using an out of the box application. I want this site to be a place where I can try things out.

It only took me one night to re-build the presentation engine, custom theme and all, with rails. It’s taking me considerably longer to get things like the MetaWeblog API, Akismet, and various other essential components I hadn’t considered complete. Also, there are some static urls that I cannot break such as the links to my very popular Scrollbox.js library and a few other things, which is where most of my traffic comes from. If I were just creating a new site, I’d be able to launch it today, but since I have so many features I have to keep consistent with the old version, it’s going to take a little while longer.

Anyway, the reason I bring it up in this post is that it’s my project for Railsconf weekend. I hope to get it finished and insert as many bells and whistles as possible while I’m away.

What about Testing Rake Tasks?

Friday, May 23rd, 2008

There are a lot of posts out there about using Rake for testing your app. What about testing your rake tasks? You gotta test those too, right?

sIFR on Rails

Wednesday, May 7th, 2008

Here’s a quick rails helper for using sIFR within Rails: http://pastie.textmate.org/192895.