Thom Lawrence

Method missing in C# 4.0

June 7, 2009 · Leave a Comment

I was hoping this would be quite easy, however I ran into this problem. Any answers much appreciated.

→ Leave a CommentCategories: C#

Mocking class methods in Objective-C

May 9, 2009 · Leave a Comment

If you ever find yourself shying away from class methods in your Objective-C designs on the grounds that they reduce the testability of your code, think again:

- (void)testDateSwizzling
{
	Method originalDate = class_getClassMethod([NSDate class], @selector(date));
	Method mockDate = class_getInstanceMethod([self class], @selector(mockDate));
	method_exchangeImplementations(originalDate, mockDate);
	STAssertEquals([NSDate date], [NSDate distantPast], @"Should have mocked method");
	method_exchangeImplementations(mockDate, originalDate);
}

- (NSDate *)mockDate
{
	return [NSDate distantPast];
}

This allows you to substitute your own implementation for a class method, using the magic of Objective-C’s runtime library. I’m going to have a look at how this could be packaged up for OCMock to make the syntax a little nicer, but I’m already using it wherever it simplifies my APIs (NSDates in particular) and wherever I can’t or don’t want to refactor third-party libraries.

→ Leave a CommentCategories: Objective-C

Linking to dynamic libraries in Xcode

March 6, 2009 · 15 Comments

I like to think it’s entirely a lifestyle choice that Cocoa exposes no regular expression API to developers. It’s probably the same motivation behind making Xcode such a tortuous IDE – Apple just don’t want the rabble writing Mac apps.

But, nevertheless, we plug away, and of the half-dozen available regex libraries out there, I settled on RegexKitLite. It’s dead easy to integrate (drop two files in your project) and relies on a built-in (but technically unsupported for development, if not verboten) OS X library called the International Components for Unicode.

The RKL docs show you two ways of referencing it, but neither seemed right to me, and it turns out that Xcode (3.1 at least) makes it even easier.

Simply:

  1. Right-click on each target in which you need regular expressions.
  2. Click on the ‘+’ under Linked Libraries.
  3. Click on the drop-down to filter to ‘Dylibs’.
  4. Scroll down to libicucore.dylib and add it.

After that you’re all set.

→ 15 CommentsCategories: Programming
Tagged: , , , ,

XNA Studio 3.0 under Parallels

September 28, 2008 · Leave a Comment

Still no joy with the new beta. Any VMWare Fusion peeps have any luck?

→ Leave a CommentCategories: Gaming · Programming
Tagged: , , ,

Magic: the Gathering with normal playing cards

September 23, 2008 · Leave a Comment

Rules

  1. Shuffle all 52 cards together and lay the deck face down.
  2. Players draw from this single deck.
  3. When the last card is drawn from the deck, shuffle all graveyards back into the deck.
  4. There is no mana burn.

Other than that, it’s just the same game.

Cards

All nonland cards have a casting cost derived from their rank, in colourless mana. Aces therefore cost 1 mana, and face cards cost 10. Where X is used in the card text below, it is equal to the card’s rank (again aces being 1 and face cards 10).

♠ Spades
Land. ⟳: Add X to your mana pool.
♣ Clubs
Creature. X/X.
♦ Diamonds
Instant. Deal X damage to target creature or player.
♥ Hearts
Instant. Choose one — Target player gains X life; or prevent the next X damage that would be dealt to target creature or player this turn.

Problems

Mana flood and mana screw happen fairly often, and obviously there’s not much variety in the cards. But in desperate times, if you need your fix, it’ll tide you over.

→ Leave a CommentCategories: Gaming
Tagged: ,

Ode to a Karplusan Wolverine

July 18, 2008 · Leave a Comment

How do I love thee? Let me count the ways.

  • Thou art a one-drop with first strike.
  • When blocked, thou hast double strike.
  • Thou mayst deal thine combat damage as if thou wert not blocked.
  • There are some who call thee… ‘Tim’.

And, if God choose, I shall but love thee better after 20 damage.

With apologies to Elizabeth Barrett Browning. :)

→ Leave a CommentCategories: Gaming · Magic: the Gathering
Tagged: , ,

TELL WORDPRESS “IMPORT FROM DASBLOG”

July 11, 2008 · 2 Comments

You have been killed by a grue.

Update: donning my anti-grue kit (XSLT and Emacs), I have managed to resurrect the old posts. Much rejoicing and broken HTML.

→ 2 CommentsCategories: Blogging
Tagged: , , ,

Can haz pluginz?

July 11, 2008 · Leave a Comment

require 'rubygems'
require 'active_record'

class ActiveRecord::Base
  class << self
   def method_missing_with_lol(sym)
     if sym.to_s =~ /^can_haz_(\w+)?/
       send "acts_as_#{$1}"
     else
       method_missing_without_lol sym
     end
   end
   alias_method_chain :method_missing, :lol
 end
end

class Lulz < ActiveRecord::Base
  can_haz_state_machine?
end

Temporary solution for Aaron’s problem, anyway. ;)

→ Leave a CommentCategories: Code · Ruby
Tagged: , , ,

Card of the Day

August 16, 2007 · Comments Off

If you’re on a Mac and love Magic: The Gathering, you can use this Dashboard widget to view the card of the day from the Wizards site. Seeing as everyone’s copy of Dashcode has expired now, I doubt I’ll spend any more time on it. It’s basically just an Ajax request from Prototype and a regex to find the image.

I sometimes wonder if Dashcode will morph into some hybrid iPhone IDE by the time Leopard comes out, if Apple still haven’t relented and allowed developers access to the gadget’s native innards. It was a fairly nice piece of software while it lasted, anyway.

Update: having said I wasn’t going to spend any more time on it, Wizards have changed their HTML, so I’ve updated the regex. This should now work again.
13/09/2008: Wizards have changed the Magic site again, so I’ve uploaded a new file.

Comments OffCategories: Gaming
Tagged: , ,

Worst Update Ever

July 2, 2007 · Comments Off

So Parallels 3.0 has continued to frustrate me. I can forgive the XNA thing – seems just as likely to be Microsoft’s fault. I filed a bug (or is it ‘participated’ in a ‘connection’?) on the atrocious Connect site, which you can vote up if you like… a few people have come here from Google with seemingly the same problem.

It’s not even that ActiveSync still doesn’t work, removing the only other reason I really had to buy the upgrade. It’s three things, really:

  1. My virtual machines occasionally take about a minute to resume.
  2. Tonight, Parallels decided to start corrupting my Windows XP disk image, leaving me with recursive bluescreen fun.
  3. I can’t even repair it, because I can’t work out how to make my install disc image bootable.

So it’s been disappointing. Probably nobody’s fault, but I really feel like going back to 2.5. Or trying VMWare and not having my fans on the whole time even if the VM’s idle etc etc. Grr.

Comments OffCategories: Computing
Tagged: , , , ,