Archiving a message via keyboard shortcut in Microsoft Entourage

This has been driving me nuts for a long time and I finally figured out the applescript for this so I figured I should share.

The script is:

This script assumes you have an exchange account and a folder in that exchange account you want to use.

If you want to use an archive folder that is a subfolder of another folder, you’ll want to tweak the script to say something like “to folder archiveFolderName in folder parentFolderName in Exchange account exchangeAccount” and add a parentFolderName variable to the top of the script.

Now all you have to do is save the script in: “~/Documents/Microsoft User Data/Entourage Script Menu Items/Archive\cA

This will put it in your script menu and set the keystroke ctrl+a to “Archive”.

Enjoy!

Tagged: , | Posted February 27, 2009 | Comments Off

Rant: Using error codes in user messages

In short: DON’T!

What in the world was Apple thinking when you try to upgrade/register/sync your iPhone/iPod and you get “Error: -19″ or “Error: -20″?? What good does this do any one? How am I supposed to fix the problem if I don’t know what the problem is? Isn’t Apple the king of user-friendliness?

When you write software, you should use good error messages. You should use good exceptions. You should use descriptive values.

Granted, some things the user cannot fix. Telling the user the database connection was lost on a web application does very little good for the user. You can however tell the user that an error that was not their fault occurred. At least then I know I can come back and try again later.

Luckily, after rebooting my iPhone I was able to install the recent software update. This may not have been the problem, but certainly Apple could have notified me that I should attempt rebooting.

In any case, be nice to your damn users!

Tagged: , | Posted August 5, 2008 | Comments Off

Using EclEmma to write better unit tests

If you don’t already write unit tests you should be. (Hey, why aren’t you writing unit tests?) Unit testing has so many benefits and the upfront developer cost to write some unit tests can pay huge dividends later when you aren’t spending time debugging broken code nor attempting to save face due to clueless mistakes. You can also use them as a contract to the expectations of your implementations.

So, assuming you have some unit tests, how useful are they if they don’t test everything? At some level you will want to have a good idea that you’re testing everything. (NOTE: I mean everything really important. Writing perfect 100% coverage like this would likely be too expensive for the entire codebase.) This is where Emma comes in (and more importantly for us, EclEmma, an Eclipse plugin for Emma). Emma is a code coverage tool which lets you visual which parts of your code get executed during some execution (regular or JUnit).

Lets walk through using EclEmma to ensure that we have adequate testing being done. Lets test the following two classes.

GuessTheNumber.java:

import java.util.Random;

public class GuessTheNumber {

private final Integer value;
private final int min;
private final int max;
private int guesses = 0;
private boolean solved = false;

public GuessTheNumber(int min, int max, int value) {
this.min = min;
this.max = max;
this.value = value;
}

public GuessTheNumber(int min, int max) {
this(min, max, getRandomNumber(min, max));

}

public int guess(int i) {
if (solved)
throw new IllegalStateException();

guesses++;

int ret = value.compareTo(i);

if (ret == 0)
solved = true;

return ret;
}

public void resetCount() {
guesses = 0;
solved = false;
}

public int getValue() {
if (solved == false)
throw new IllegalStateException();

return value;
}

public int getMin() { return min; }
public int getMax() { return max; }

private static int getRandomNumber(int min, int max) {
return new Random().nextInt(max - min + 1) + min;
}
}

And SequentialStrategy.java:

public class SequentialStrategy {

    private final GuessTheNumber guesser;

    public SequentialStrategy(GuessTheNumber guesser) {
        this.guesser = guesser;
    }

    public int solve() {
        for (int i=guesser.getMin(); i<=guesser.getMax(); i++) {
            if (guesser.guess(i) == 0)
                return i;
        }

        throw new IllegalStateException();
    }
}

Finally, we’ll write up a basic StrategyTest.java:

import junit.framework.TestCase;

public class StrategyTest extends TestCase {

    public void testSequentialStrategy() {
        GuessTheNumber guesser = new GuessTheNumber(5, 100);
        SequentialStrategy strategy = new SequentialStrategy(guesser);

        int value = strategy.solve();
        assertEquals(guesser.getValue(), value);
    }
}

So the question is, how good is our test? If you installed EclEmma, you can right click on your Unit Test in Eclipse, head to “Coverage As” -> “JUnit Test”

This will run your unit test against your code and when complete, highlight the code green, yellow, or red for covered, partially-covered, and not-covered respectively.

According to EclEmma, our code coverage when running StrategyTest is:

Thats not too bad, lets take a look at the output for SequentialStrategy:

We may want to test the IllegalStateException since we currently don’t and we are expecting it to happen if we’ve guessed everything between min and max and haven’t solved the problem. This would ensure if someone else comes in behind us and changes this code, the unit test will fail if they take that out and change it to return, say, Integer.MIN_VALUE.

Lets also take a look at some of GuessTheNumber:

It appears we also want the contract to include an IllegalStateException being thrown if you have already solved the guessing game. It also looks like we don’t ever call resetCount() and possibly retest after doing that. We also never check if getValue() fails prior to having a solution.

If we modify the test slightly to:

import junit.framework.TestCase;

public class StrategyTest extends TestCase {

    public void testSequentialStrategy() {
        GuessTheNumber guesser = new GuessTheNumber(5, 100);
        SequentialStrategy strategy = new SequentialStrategy(guesser);

        for (int i=0; i<3; i++) {
            try {
                guesser.getValue();
                fail("An exception should have been thrown");
            }
            catch (IllegalStateException ex) { /**/ }

            int value = strategy.solve();
            assertEquals(guesser.getValue(), value);

            try {
                guesser.guess(guesser.getMax() + 1);
                fail("Shouldn't reach this point");
            }
            catch (IllegalStateException ex) {/**/}

            guesser.resetCount();
        }
    }

    public void testBadGuessGame() {
        GuessTheNumber guesser = new GuessTheNumber(1, 10, 3000);
        SequentialStrategy strategy = new SequentialStrategy(guesser);

        try {
            strategy.solve();
            fail("Should not reach this point");
        }
        catch (IllegalStateException ex) { /**/ }
    }
}

And now our code coverage is:

I know this was a very basic example that really didn’t test any complex logic or conditions, but I hope it gives you a good idea of how you can use code coverage to improve your unit tests.

Tagged: , , , | Posted May 8, 2008 | Comments Off

Making Terminal.app Easier to Read

I really like the “Pro” color scheme for Terminal.app but I hate how hard it is to read the bold colors. By complete accident however, I came across this Options Page in Terminal.app:

Apparently, you can just click that “Use bright colors for bold text” checkbox and all of a sudden typing things like ls is no longer painful. Just thought I’d share the tip.

Tagged: , | Posted March 19, 2008 | Comments Off

Terminal.app TabNamer v0.1 Alpha

This is a SIMBL plugin for Terminal.app on Leopard that lets you name your tabs. Because this is an Alpha, I am not going to write up instructions on where to get SIMBL, how to install it, or how to install the bundle. If you don’t already know how, then Alpha software is not for you.

That said, after installing the plugin, press Command+Shift+T to name a tab (or use the Name Tab option under the View menu).

NOTE: This has only been tested on Intel Macs with the latest version of SIMBL. If you have a PowerPC and it works for you, I’d love to hear about it in the comments.

Also, due to the nature of me giving this away for free, I cannot guarantee it won’t harm your computer, nor can I promise it will fix your marriage. This is for use AT YOUR OWN RISK. I wash my hands completely of responsibility.

Enjoy!

Terminal Tab Namer v0.1 ALPHA

Tagged: , , | Posted March 2, 2008 | Comments Off