jquery.xslt

I’ve created yet another jQuery xslt transformation plugin. This one is based on the sarissa javascript library, which abstracts many of the cross browser implementation details for you. I tried the jquery.transform plugin, which didn’t work for me in all browsers, but I wanted the same kind of control over caching and ajax calls. This one is already in use at work, and you can get a look at it here.

Leave a comment

Concurrency testing in Erlang with libtest

I’ve just started a new project, with the aim of making it easier to test the concurrent programs I write in Erlang. My stated aims are quite simple:

  • Provide services for capturing inter-process messages and context
  • Provide support for stubbing out processes and OTP behaviours
  • Provide hamcrest matchers that make it simple to define assertions about your application’s behaviour

It’s all in a very early stage (apart from my Erlang implementation of hamcrest, which is coming along nicely now) and the source code is available on github here. Here are a couple of samples to whet the appetite:

?assertThat(registered_name(Mod), observed_message_from(self(), Msg)),
?assertThat(registered_name(Slave, ProcessName), observed_message(Msg)),
?assertThat(Pid, observed_message({message, "hello"})),
?assertThat(?COLLECTOR,
categorises(observed_message({message, "woo hoo"}),
as(category1))).

Stubbing of OTP behaviours will almost certainly be based on emock, and I’m planning on integrating nicely with PropEr as I’ve started using this library quite a lot myself. The mechanics of replacing registered gen_servers and the like (using runtime code generation and/or re-registration/config), I’ll probably leave alone as there are plenty of good libraries out there that do this already.

Leave a comment

Property based testing against mocks?

More of a quick splurge than anything – I was looking over some old code and noticed a unit test that creates a lazy list of tests, each of which asserts some properties about a bisection based search over a set of stub objects which are all based on an existing superclass and have a property defined which returns a randomised value each time you interact with it. Unusual but kind of cool. Here’s the code…

@forall_lazy(searchbase=
    sets(items=stubs(cls=Identifiable,
    salsaId=strings(low=1)),
    size=(1,3011)),
    subject=integers(low=0, high=1010))
def check_detect_using_bisect(searchbase, subject):
  searchbase = list(searchbase)
  item = searchbase[max(0, min(subject, len(searchbase) -1))]
  universe = sorted(searchbase, key=salsa_key)
  search_result = detect(cmp, item, universe, key=salsa_key)
  reason = "item (%i) mapped_to (%i)" % (universe.index(item), universe.index(search_result))
  assert_that(search_result, is_(not_none()), reason)
  assert_that(search_result.salsaId, is_(equal_to(item.salsaId)), reason)

def test_detect_using_bisect():
  [ (yield testcase) for testcase in check_detect_using_bisect() ]

Leave a comment

Post compile hooks with rebar

Sometimes you want your build to do some additional work after compiling. For example, in my Erlang implementation of hamcrest, I dynamically generate the main header file after compiling to ensure that all the functions exported from the hamcrest_matchers module are imported when the header gets included and to ensure that wrapper macros for eunit are also generated for each of them.

Typically you’d just have a makefile deal with this, maybe like so:

compile:
./rebar compile; escript header_gen

But that kind of breaks other people’s builds if they want to use rebar themselves. The problem is that rebar doesn’t yet provide a mechanism for overriding the build/compile command for dependencies (at all, let alone individually) and thus if your build requires a makefile to be run then your consumers build has to incur the same kind of complexity. Fortunately there is a work-around. Rebar provides a compile_post_script hook which you can specify in your rebar.config file. You specify a shell command and rebar will run this hook immediately after compilation. Unfortunately it also runs it when the compile command is applied to all your dependencies (again this is something which isn’t controllable yet) which typically will break because your shell command is not relevant to these apps. I spent a little time trying to do something clever with erl --eval '...' but in the end that didn’t play nicely at all. I then tried to encode the whole thing in a compound shell command like if [ -f hrlgen ]; then escript hrl; fi but then discovered that rebar_utils:sh/1 (which runs the shell command) wraps the supplied command text in an exec system call (which obviously isn’t going to work for a complex if..then expression). In the end, it was a comedic reptile that came to the rescue:

{compile_post_script,
"env ERL_LIBS=deps python -c \"import os; os.path.isfile('hrlgen') and os.system('escript hrlgen') or None\""}.

2 Comments

fixing Microsoft live meeting for Safari on Snow Leopard

This is surprisingly tricky, but in the end (with a bit of help from the safari java console) I determined that the problem is with DNS resolution and have a work-around. Whether this affects everyone or just those of us lucky to be behind a corporate firewall, I don’t know. The fix for me, was to install Java 1.5 and set my java preferences to always choose the 1.5 JVM for running web apps/applets, after which everything seems to play nicely.

Installing java 1.5 on Snow Leopard is itself quite tricky. The secret is to get hold of the java 1.5 update for Leopard and open it using Pacifist, which allows you to navigate into the /System/Library/Frameworks/JavaVM.framework/Versions directory within the installer package, select the 1.5.0 folder and the symlink to it (1.5) then right click and select “install to default location”. Props to this blogger for revealing the secret to that old chestnut. Please be very careful though – if you don’t delete the existing symlink first (which has 1.5 pointing to the current 1.6 install), then you’ll blow away your existing installation!

Unfortunately this means I no longer have an excuse not to attend boring finance meetings whilst working from home. :/

2 Comments

Using epm to overcome rebar dependency handling limitations

I love rebar as a build tool, but¬†occasionally¬†it doesn’t do what I want. One example that keeps cropping up is managing dependencies that require complex commands in order to build them. If the dependency you want to manage is built using autotools or requires a series of commands (configure && make for example) then rebar is going to fail when you try and run ./rebar check-deps which is annoying. Read the rest of this entry »

Leave a comment

Granularity in Dimensional Modelling

It’s been a while since I worked on an interesting Business Intelligence problem, so a recent distraction has proved most stimulating. The reason for this post is a question I’ve had to consider many times in the past: should I design my schema by looking at the reports I’ve been asked for, or is there some other driving force to help me identify “the grain” of a dimensional model? Read the rest of this entry »

Leave a comment