Using the --guess argument in Cucumber

When working with a lot of feature files in cucumber you'll sooner or later run in to the problem of having 2 similar statements ie:
Then /^epic .*$/ do
end

Then /^epic fail$/ do
end
If you just run cucumber <feature file> with this definition it will fail with the following error: Ambiguous match of "epic fail". To solve this problem just add --guess on the command line (cucumber --guess <feature file>). What happens is that the cucumber runner does a bit of evaluating to decide what method to call, so far it has worked as expected. Files needed to test: * fail.feature:
Feature: Fail
	In order to test this
	I want a feature file that contains a test

	Scenario:
	Given a dummy
	When a win
	Then epic win

	Scenario:
	Given a dummy
	When an epic fail
	Then epic fail
* fail_step.rb
Given /^a dummy$/ do
end

When /^a win$/ do
end

When /^an epic fail$/ do
end

Then /^epic .*$/ do
end

Then /^epic fail$/ do
end

Getting the most out of your Android phone

ie running a custom firmware on it. Things you need
  1. Recovery image
  2. HTC ADP 1.6 DRC83
  3. CyanogenMod 4.2.1
  4. Radix 4.2 kernel
  5. Android SDK
Note: all the files a for a HTC Magic PTV32A, if you got another model check the links in the bottom for the correct files. Also read the whole post before you start anything :) So, start with putting the ADP 1.6 zip along with the Cyanogen update zip and the kernel zip in the root on you sdcard. So now we're ready to start the install, begin by turning of your device and then start it while holding down the back key (ie hold down the back key, press the power button and keep the back key pressed until you reach a menuĀ  that have 3 Android mascots surfing in the bottom) At this point unzip the Android sdk and go to the tools folder, from there do fastboot boot <path to your recovery image>, this should give you a green menu. If your running Linux or Mac OSX you need to Google and download the fastboot binary since it's not included in the sdk for those platforms. From the menu do the following things in this order:
  1. Wipe data/factory reset
  2. Wipe data/factory reset
  3. Apply zip: HTC_ADP_1.6_DRC83_rooted_base.zip
  4. Apply zip: update-cm-4.2.1-signed.zip
  5. Apply zip: rad-4.?.zip
  6. Reboot
The first reboot takes a couple of minutes. Since we've done a factory reset you have to reenter your Google account and download all of your applications. So whats the point of installing a custom firmware then? First of you get the latest things from google, some community tweaks and the ability to install apps that require a bit control of your phone. Examples are:
  • market-enabler, a nice app that makes it possible to fake what carrier your phone is connected to so that you can buy apps from marked. This does not allow you to pirate applications just buy them, very handy for people in say Sweden where we don't have market access yet.
  • android-wifi-tether once installed this app allows you to turn your phone into a wifi access point so that you can connect your pc etc to it and use it's Internet connection.
There's a bunch of other applications out there too but these 2 i found particularly useful. Ref: CyanogenMod Radix Kernels + extra install instructions Recovery Images
def get_private_customer_blixten() party_service = Configuration.instance.service_url :party_service xml = RestClient.get "#{party_service}/private_customers.xml?query=blixten@test.se" doc = REXML::Document.new(xml) return doc end

Async file uploading in Silverlight with callback

In one of the projects I'm working on we needed a way to upload an file to a server and update other things once it's uploaded and processed, however the async nature of Silverlight makes it a bit hard. The OpenWrite method on the WebClient works fine for uploading but it doesn't allow us to wait for the response in the same call. So this is what i came up with (I haven't upgraded to Silverlight 3, so it's only tested on Silverlight 2). I've declared an Action<bool> passed into the method that will hold the callback method, simple signature with a bool parameter to indicate success. What I've found was that UploadString offers the ablity to both post data and read the response, that allows us to post data, process it in page_load and then output a response (simple "OK" || "FAIL"). The downside of this approach is that we post a string so depending on what you upload you might need to base64 encode the content to avoid random problems with binary data. A bit of code to complete the post, it's downsized from it's original form and not supposed to work with cut & paste coding. :)
private Action<bool> CompleteAction;

public void UploadFileWithCallBack(string PostUrl, Stream data, Action<bool> completeAction)
{
   try
   {
      CompleteAction = completeAction;
      Uri uri = new Uri(Util.HostName, PostUrl);
      UploadFileWithCallBack(uri, data);
   }
   catch (Exception) { }
}

private void UploadFileWithCallBack(Uri uri, Stream data)
{
   WebClient c = new WebClient();
   StreamReader sr =new StreamReader(data);
   string uploadString = sr.ReadToEnd();
   c.UploadStringCompleted += UploadFileWithCallBackCompleted;
   c.UploadStringAsync(uri, "POST", uploadString);
}

void UploadFileWithCallBackCompleted(object sender, UploadStringCompletedEventArgs e)
{
   try
   {
      CompleteAction(true);
   }
   catch (Exception)
   {
      CompleteAction(false);
   }
}

Android debugging

A quick debugging tip for Android development. If you got an application that crashes on startup and just leaves you with the force close dialog running the following command might help:
adb logcat
adb is located in the tools directory of the Android SDK. Running it with the logcat parameter will output all that the emulator (or attached device) is logging. So in the case of an application crashing on startup you'll find the exception and stacktrace in the log when your run the application. In my case i tried to use findViewById before onCreate had been called.