Sunday, July 26, 2009

Double-chocolate brownies

While CURA were at Bisley for the Imperial Meeting this year, I made the team some of these brownies. They were very much enjoyed by all!

This recipe is designed to make quite firm brownies that travel easily (e.g. on the back of my bike). If you like your brownies nice and squidgy, put less flour in (175 g instead of 225 g).

  • 275 g plain chocolate (50% cocoa solids)
  • 220 g unsalted butter
  • 85 g walnut pieces
  • 170 g milk chocolate (cut into chunks)
  • 225 g plain flour
  • 1 tsp baking powder
  • 4 large eggs, lightly beaten
  • 1 tsp vanilla essence
  • 325 g caster sugar

Pre-heat oven to 170°C (155°C if you've got a fan oven). Line a 30x20x3.5 cm cake tin with lightly buttered greaseproof paper. I find that it makes the brownie easier to extract from the tin if you butter the base of the tin as well.

Melt the plain chocolate and butter in a large (preferably metal) mixing bowl over a pan of simmering water. Remove the pan from the heat and stir in the sugar, followed by the eggs and vanilla essence.

Sieve the flour and baking powder into the mixture, and fold in. Fold in the nuts and chocolate chunks.

Pour the mixture into the cake tin, place in the oven and cook for 20-25 mins. The corners will cook fastest; do not allow them to burn! When cooked, a skewer inserted into the centre of the brownie should come out mostly clean, but it's no big deal if you get a squidgy middle.

Allow to cool in the tin. When cool, remove the brownie from the tin and cut into squares (you should be able to get 24 good-sized pieces from this recipe).

Update: Avoid oil-based chocolate and/or HFCS-based chocolate for this recipe. It won't work.

Simple unit tests in Scheme

One nice feature of the Scheme programming is the ridiculous, over-the-top power of its "hygienic" macro system, which allows a programmer to effectively redefine the language to suit the task at hand.

A few days ago, I needed to write some simple unit tests for some Scheme code I was in the process of developing. The Guile Scheme implementation doesn't come with a library for unit testing by default, so it was necessary to create one of my own. This is it:

(define *failed-tests* '())
(define *passed-tests* '())

(define (assert-true result)
  (if (not result)
      (throw 'test-failed-exception
             (with-output-to-string
              (lambda ()
                (display "  assert-true: ")
                (display "got: ")
                (write result))))))

(define (%begin-test name test-thunk)
  (let ((test-success #t)
        (test-fail-msg #f))
    (display name) (display "... ")

    (catch #t test-thunk
           (lambda (key . args)
             (set! test-success #f)
             (set! test-fail-msg
             (if (eqv? key 'test-failed-exception)
                 (car args)
                 (with-output-to-string
                  (lambda ()
                    (display "  unexpected exception: ")
                    (write (cons key args))))))))

    (if test-success
        (begin
          (display "passed")
          (set! *passed-tests* (cons name *passed-tests*)))
        (begin
          (display "failed")
          (if test-fail-msg
              (begin
                (newline)
                (display test-fail-msg)))
          (set! *failed-tests* (cons name *failed-tests*))))
    (newline)))

(define-syntax begin-test
    (syntax-rules ()
      ((_ name . test-forms)
       (%begin-test name (lambda () . test-forms)))))

(define (report-tests)
  (display "Test summary")(newline)
  (display "Passed: ") (display (length *passed-tests*)) (newline)
  (display "Failed: ") (display (length *failed-tests*)) (newline))

Note that this effectively adds a keyword (begin-test) to the Scheme language, and this very simple macro has a massive effect on the readability of the resulting testcase code. For example, a trivial unit test using this minimalistic framework might look like:

(begin-test 'SuccessfulTest
  (assert-true #t)
  (assert-true (equal? 1 1)))
(begin-test 'FailTest
  (assert-true (equal? #t "string")))
(report-tests)

The framework is completed with the addition a few more assert- functions (left as an exercise to the reader). This code will form part of a future release of gEDA.

(In case you want to use this code in your own project, it is licensed under the GNU LGPL v3 or later). But there are probably better unit test systems for Scheme out there!

Saturday, July 18, 2009

Enchiladas

While I'm on a roll with the recipes, here's my recipe for chicken enchiladas. It's probably not particularly authentic, but I enjoy them! This recipe serves 2 moderately hungry people.

Enchilada sauce

  • 400 g can of chopped tomatoes
  • 1 clove garlic, chopped
  • Fresh chilis, chopped
  • 1 tbsp olive oil

I usually use 2-3 of the normal chilis sold in Tesco or Sainsbury's (with the seeds left in), but I like my echiladas nice and spicy! With those chilis, I find them a bit impotent with the seeds left out.

Fry the chilis and garlic in the olive oil for 2-3 minutes over a medium heat. Add the chopped tomatoes and simmer for 20-30 minutes until most of the excess liquid has evaporated leaving a thick, spicy tomato sauce.

This can easily be made in advance, and freezes well.

Fried chicken filling

This is a very simple filling -- use your imagination and come up with your own! Try other meats, fried peppers or mushrooms, seafood, cheese... Also consider marinating the chicken with spices before frying.

  • 300 g chicken breast, cut into strips
  • 10 g fresh ginger, grated
  • Dried paprika
  • Salt & pepper
  • Half a medium cooking onion, coarsely chopped.
  • 1 tbsp olive oil

Heat the oil over a high heat in a wide-based frying pan. Add the onion, chicken, ginger, and paprika, and season the chicken to taste. Fry until the chicken is cooked through, then set aside.

Like the sauce, this can easily be made in advance.

Putting it all together

  • 4 corn tortilla wraps
  • 150 g grated cheese (cheddar works okay)

Pre-heat the oven to 150°C. Microwave the tortilla wraps for 15-20 seconds until they are warm and flexible. Divide the filling between them, roll them up, and place them together in a small roasting tin. Spread the enchilada sauce generously over the tortillas (making sure to coat them all over). Top with the cheese and salt and pepper to taste.

Bake in the oven for 15-20 minutes, and serve with green salad and spring onions.

Friday, July 17, 2009

This will seem like bragging...

This will seem like bragging, but in retrospect I really did rather well at Cambridge. These are the prizes and scholarships I was awarded over my four years:

  • Emily Davies Scholarship (twice)
  • Henry Tompkinson Scholarship
  • Beatrice Mills Prize
  • Rosalind, Lady Carlisle Prize
  • Raemakers Prize
  • Accenture Second Year Computing Prize
  • i2 Ltd. Third Year Computer-Based Project Prize

Of course, those successes paled into insignificance alongside the accomplishments of some of my peers at certain prestigious inner-city colleges, but I think I did okay for a hick from the sticks (i.e. a Girtonian)!

Edit: I forgot to mention that I also blagged a (large) award from the academic funds for a plane ticket to a conference at MIT. But that was more of a success in terms of "social engineering" than actual engineering!

Wednesday, July 01, 2009

Starting my PhD!

As I mentioned in January, I was awarded a PhD studentship at Surrey Space Centre. I graduated from Cambridge last Friday, with I Class honours in my BA and a Distinction in my MEng, moved down to south-west Woking at the weekend, and started at SSC today!

I'm having to fight a bit to get a Linux workstation -- other groups in the same building (and serviced by the same IT staff!) use Fedora on their desktops, but SSC has historically been an all-Windows environment. In a corporate setting, I might put up with Windows -- there, at least, there is often a reasonably well-staffed IT services department to take care of the innumerable things that go wrong -- but in my experience, PhD students don't get quite that level of support. If I'm going to be solving my own problems, I want to do it with more powerful tools. (Also, Emacs on Windows isn't nearly as much fun. How can I possibly survive without a properly-functioning compilation-mode?)

Nevertheless, I think I'm eventually going to win the battle. In the meantime, it looks like I'll have to make do with Cygwin.

As far as the research is concerned, I've barely start to dip my big toe into the scalding bathtub of things I don't know, and it feels like I've got a long, long way to go before I get to the things no-one else knows either!

Update: I managed to persuade the computing folks to give me second PC running Linux and a USB KVM switch. So that's alright, then.

Chorizo and tomato pasta

Another chorizo recipe that I made to use up what was left over from the previous one. Note that I use Spanish chorizo, not Mexican (as most commonly found in the USA).

Ingredients (serves 3-4):

  • 150 g dried chorizo sausage, diced finely
  • 1 medium cooking onion, coarsely chopped
  • 1 clove garlic, chopped
  • 100 g mushrooms, sliced
  • 400 g can chopped tomatoes
  • Olive oil
  • Balsamic vinegar
  • Dried tarragon
  • 2 small bay leaves
  • Black pepper

In a wide-based saucepan, heat a tablespoon of olive oil, and fry the onion and chorizo for 2-3 minutes (or until the onion is translucent). Add the mushrooms and garlic, and continue to fry until the mushrooms begin to darken and shrink. Add the tomatoes, and stir in the dried tarragon, bay leaves, black pepper, and about a tablespoon of balsamic vinegar. Cover and simmer gently for 20-30 minutes.

Serve with pasta and fresh green salad.

Monday, June 29, 2009

Baked pork chops with chorizo

Here's a simple but delicious recipe I adapted from a dish served at Girton's cafeteria sometime in early 2009.

Ingredients (serves 2):

  • 2 pork chops
  • 60 g dried chorizo sausage, diced finely
  • 1 medium cooking onion, coarsely chopped
  • 1 clove garlic, chopped
  • Salt and pepper

Pre-heat the oven to 180°C (fanless oven 200°C). Sprinkle both sides of the chops with salt, and place in a small roasting tin. Pile garlic, onion and chorizo on and around the meat. Add pepper on top. Cover the roasting tin with tin foil and bake in the oven until the meat is cooked (usually between 45 mins and one hour).

Serve with boiled potatoes and fresh cabbage.

Saturday, January 24, 2009

PhD studentship at SSC

I've been accepted for a PhD studentship at Surrey Space Centre, working on applications of satellite-based Synthetic Aperture Radar (SAR). Even better, I've been awarded a Doctoral Training Grant by the EPSRC, so as long as I pass my MEng I'm going to be going exactly where I've wanted to go for the last couple of years, doing (more or less) exactly what I want to do!

gschem, log files and X selections

Just over a week ago, I posted a series of [RFC] posts to the gEDA-user mailing list suggesting six reasonably non-trivial changes to libgeda and gschem. Although the discussions they started off weren't quite as productive as I was hoping, they did attract quite a bit of interest.

I haven't been afraid to put my money where my mouth is. Since then, I've implemented two of the changes I suggested: a modification of the way gEDA apps create logfiles, and support for copying and pasting bits of schematics between gschem windows. I thought I'd post here to explain the amount of careful design work that goes into even relatively minor changes to the gEDA suite.

Logging

Historically, gschem (and the other gEDA apps) have created logfiles in the current working directory when they were launched. This behaviour quickly resulted in a user's home directory becoming littered with the files, gschem.log files especially.

My initial suggestion was to just not create log files by default, and require users to specifically enable them. However, it was quickly pointed out that since one of the most common reasons for gschem failing to start was that a new user had made a mistake in their configuration file, and that it would be best to carry on with generating logfiles as the default behaviour.

Instead, it was suggested that the logfiles should be put in a centralised, out-of-the-way location, and ~/.gEDA/logs/ was suggested, with the caveat that it would be necessary to make sure that multiple copies of gschem accessing the directory would have to be supported safely, even on different machines, but also that a user could quickly easily find the most recent log file -- so just adding a random suffix with mktemp wouldn't work either!

Having worked out a way of doing this (a secure algorithm for generating sequentially numbered, dated log files), I then realised that on some operating systems, such as Microsoft Windows, $HOME might not even be defined, and that there might be platform-specific differences in the standardised place to keep configuration data. Since the gEDA applications had no existing way of handling these variations, I ended up abstracting out the methods for locating the system and user data and configuration files, and updating all of the gEDA apps to use them.

All in all, changing the location where log files are stored used up at least eight hours of development time.

Clipboard copy, cut and paste

For a long time, gschem has supported copying and pasting schematic data between pages and windows in the same gschem process, but it was never made clear to users that this mechanism didn't use the X clipboard, and thus sometimes copying and pasting didn't work when it would have made sense for it to.

X Window System selections are complicated. There are two selections normally used by X applications: the PRIMARY selection and the CLIPBOARD selection. Traditionally, the PRIMARY selection is contains the most recent piece of text selected by the user with the mouse, and can be pasted by clicking the middle mouse butten, while the CLIPBOARD selection is accessed via "copy" and "paste" actions explicitly invoked by the user. In order to match up with other applications (and because nothing like the PRIMARY selection is available on Microsoft Windows or OS X), we decided to use the CLIPBOARD.

For the same portability reasons (and also because the raw X API is horrendously complicated), we decided to use the GTK Clipboard API to manage the clipboard.

A neat feature of clipboards (and X selections in particular) is that it's possible for the source application to provide the data in different forms, depending on what the "pasting" application wants. We needed a format for transferring between gschem instances, so we decided to use the gEDA schematic format (application/x-geda-schematic). Fortunately, as part of my rewrite of the symbol library back in mid 2007, I'd made libgeda able to "load" and "save" schematics from memory buffers, so I simply hooked the clipboard code into that and things started working!

I then, of course, had to work through the boilerplate required to update the GUI to support it. This took as long as implementing the actual feature.

I've also been working on some other features, using some code that I've had floating around for a long time. But more of that another time!

Sunday, September 21, 2008

More cooking escapades

I tried out two recipes yesterday, with lots of success (well, I thought so, anyway).

First was nice and simple recipe for lemon drizzle cake from the BBC Good Food website -- I used it as a fallback plan when I failed to obtain a copy of my mother's legendary and delicious recipe.

I made it in a 20 cm spring-form tin instead of a loaf tin as the recipe suggests (I don't have a loaf tin at the moment). This meant it only took around 40 minutes rather than the 45 to 50 suggested, due to the cake being somewhat wider and flatter.

The cake was delicious, but a little dense; next time I will try adding an extra teaspoon of baking powder to try and lighten it slightly.

The second was a Thai-style dish called khao pad gai from a WikiBooks Cookbook recipe. Due to the limited contents of my food cupboard and my unwillingness to buy lots of unusual and seldom-to-be-used foodstuffs, my version of the ingredients (to feed two) looked more like:

  • Olive oil
  • 225 g chicken breast, in strips
  • 2 medium eggs
  • 'Some' cooked, cold Basmati rice
  • 1 medium cooking onion, half-ringed
  • 2 small tomatoes, seeds removed and julienned
  • 2 spring onions, thinly sliced
  • 3/4 cup coriander, coarsely chopped
  • Dark soy sauce
  • 'Normal' granulated sugar
  • Salt
  • 2 cloves fried garlic

We didn't bother with the garnish, the nam pla or the Thai chili sauce, but nevertheless the taste came out okay (we were quite pleasantly surprised by how good it was after how awful it looked just after the egg was added). Note that although the recipe specifies a wok, we cooked it quite successfully in a large, flat-bottomed non-stick saucepan.