Saturday, December 25, 2010

F# GUI plumbing with reactive Events

My most recent "Aha!" moment with the language is to finally wrap my head around the standard Event module -- a sort of lightweight subset of the Reactive Extensions for .net -- while starting to do some more GUI programming in F#, which is making belated use of the GTK#/Glade spikes I made about a year ago.

It may not make much difference in the simplest cases where

naively went to

but which is equivalent to, using the Event module,

At this point the main difference is the change in the function signature -- first, it is a real F# function rather than being forced to use the implicit cast from a fun to a delegate, even if the function signatures look compatible on the surface; second the function passed to Event.add doesn't have the source argument (but, as shown, that can be brought in as a closure).

So that's a small win from the beginning -- but that just scratches the surface. Where it actually shines is where multiple sources of events have to be handled in much the same way. For example, given a menu containing recently accessed files, with selection meaning to re-open that file, as if they had been selected from a file open action

All the inhomogeneity of the event sources (button click, menu item activation) and their associated EventArgs types is smoothed away by appropriate Event.map calls and the use of closures; different validations are handled by appropriate Event.filter or Event.choose invocations; and then the whole ensemble is gathered together by an appropriate fold with Event.merge as the accumulator.

True, there is nothing here that could not be achieved by making old-style handler functions for AddHandler from equivalent appropriately composed function chains -- the path I was starting to take for this bit of plumbing before I was indirectly reminded of this feature, and dug up this series of posts from a couple of years back (so slightly dated in the details). The big difference that using the Event module makes is that it is more expressive of intent, and separates the concerns -- general event handling plumbing vs this application's business logic -- explicitly.

A white-ish Christmas

Last Saturday started dry but cold, though with some ice still on the road outside -- cycling into town in multiple layers, with only my nose exposed, that was very cold for the first couple of miles until I started to radiate enough heat through it. I got back home mid-afternoon, and took a nap, waking to find the world turned white.

So it was a work-from-home start of the week, while waiting for the ungritted roads in the village to be pounded clear; with a brisk yomp to Waitrose to get me out of the house. By Thursday, as the threatened midweek snow had come to nothing, I did go into the office (probably getting a lot less done than had I stayed at home).

Yesterday, I did the approximately biennial feat of cycling into work for the shortest working day -- although the fields were white, and the sky grey, the road was dry, and the weather, although still below zero on the way in, was milder than it had been (showing quite how accustomed we soon become to the cold). And in doing so that put me over the 1000 miles for this half year.

Today is brighter and sunny, but colder. Where I cleared the drive is dry, but the untouched snow is showing no signs of turning to slush like it had a few days ago. I shall have to make my way down the garden to check the greenhouse and the broccoli.

Tuesday, December 07, 2010

Winter Wonderland

The car thermometer showed -6 as I started out to work at about 08:45 this morning, dropping quickly to -8, and then slowly recovering to -7. Isn't it time we had an apology for predictions like this one from ten years ago?

Monday, November 22, 2010

Sometimes, a man's gotta do what a man's gotta do...

I encountered this outburst of testosterone fuelled experimentation a couple of weeks ago, and mentioned it to Karen -- who immediately said that this was something that had to be done. So, yesterday I actually made some of the

Manliest Bread EVARR!!!!!111elebenty!!!!!!1 *

Bacon. Jalapeno. Cheesy. Beer. Bread. The sheer awesomeness of the concept forced that punctuation, I swear.

And it was a great success.

The recipe (for a bread making machine)

Bread chassis:

  • 1 tsp yeast
  • 1.25 tsp salt
  • 1.5 tsp sugar
  • 350g strong white flour
  • 150g strong wholemeal flour

And in the main mix

In the candied fruit hopper:

  • 4 rashers of thick-cut bacon, dry-fried (pouring off any oozing water as required) until stiff, rinds removed and chopped into ~1cm bits
  • As many jalapeno pepper slices as will fit.

Cook on standard raisin bread program. Cool for an hour, then enjoy!

It was wonderfully savoury warm with butter, and made a fine accompaniment to a chilli powered by the fruits of our greenhouse (to the extent of 2/3 of the loaf). Though I couldn't help feeling that there had to be some way to work some garlic into the mix without spoiling the awesome.

* OK, some pedants will point out that this recipe is just loaded with phytoestrogens. But it's the concept that counts.

Sunday, November 14, 2010

Anime — Strike Witches 2

As hinted by the ending of the previous series, further adventures of half-dressed alternate- WWII aces; despite not being quite popular enough to stop the original studio going under, the franchise was considered worth taking up.

Unfortunately, much of the charm of the first series -- the copious period references, and character driven episodes -- was lost in favour of even more bath scenes and tacky comedy. When, finally, an attempt at plot and drama wobbled into sight in the last couple of episodes, it didn't have any foundation to rest upon.

Overall, rather disappointing for being pretty much what the premise would lead you to expect, and no more. Will I watch the inevitable third season? Probably.

Monday, November 08, 2010

Links for 8-Nov

Asynchronous programming in .net

Also from the PDC -- what next for Silverlight?

Rx Design Guidelines.

SSL/TLS isn't computationally expensive.

NuGet -- gems for .net has a new name.

The Should Assertion Library.

Sandcastle MSBuild integration.

Friday, October 29, 2010

Anime — The Book of Bantorra : Armed Librarians

A belated review, by some months, belated enough that it's fallen off the Crunchryroll roster.

I tried the first episode late last year, and wasn't impressed, but went back after a lot of talk about how the series was getting awesome later on; and fortunately the awful CGI from the first episode seemed to be a one-off.

In a climate where cute girls doing cute things and high-school romance seemed to have driven almost everything else off the table, Bantorra was a welcome return to an adult cast (with well endowed women) and OTT violence. However shoehorning a series of ten light novels with more plot twists than you could shake a stick at into a 26 + 1 recap episode series didn't quite work out so well in the end.

The setting was interesting and unusual in many ways -- a sort of alternate 1940s, where magic also exists, and people have made up European-style names that look and sound more like keyboard mashing (Olivia Litlets, Parney Pealrmanta, Enrique Bis'hile...); in a world where at death, a memory snapshot fossilizes as a "book" that can be "read" by touching it.

So the big struggle starts off between the Armed Librarians under Acting Director Hamyuts Meseta of the Bantorra Library, and the Church of Drowning in God's Grace, whose noble thoughts about the value of humans is belied by their separating their flock into True Men (at the top), Mock Men (mid-range operatives) and Meats (the masses). And then things get more and more complicated, with -- except in the occasional digressive arc for a bit of back-story -- the villains of the piece changing again and again, and major characters being killed all over the show.

Perhaps had it been a 40-episode series it might not have seemed quite so erratic and all over the place; or maybe it would have still seemed like it was trying to fit in everything and the kitchen sink. Overall a decent enough piece of entertainment and one that at least did all it could to be different from the current pack.

Wednesday, October 27, 2010

Javascript Airport weather decoder

While weatherpixie remains on extended hiatus, I have finally put together a simple in-browser replacement. It uses James Padolsey's cross-domain Ajax plug-in for jQuery (indirecting via YQL), a simple parsing script from Manuel Heras, here separated into a stand-alone script, and an iframe-based page to do the work.

The final piece of heavy lifting is to get the appropriate METAR report for the local airfield, and that's just a few lines of javascript --

Here, EGSC is the ICAO code for Cambridge Airport. And that's a lot closer to home than the Met. Office who give out current conditions at Bedford on the Cambridge forecast!

Saturday, October 09, 2010

Road rage

Some weeks ago, I was working late, and so cycling home after the usually flurry of commuter traffic.

Coasting one of the downhill parts, doing in the 15-20mph range, I suddenly heard this strange whirring sound behind me -- and then, suddenly, a whole flotilla of sport cyclists.

Now, when they travel solo, going along in their spray-on advertising, nose on the tarmac, arse in conjunction with the planet Jupiter, they are just subjects of merry jest. When they travel in packs, it's different.

Six to eight pairs of them streamed past me, peddling like the clappers, leaving little to no clearance, doing only the absolute minimum to move out of their straight line and pass, nearly forcing me into the verge -- much more threatening and aggressive road use than any of the buses or farm vehicles I usually have to contend with.

Between their silly outfits and bad behaviour, the sort of thing that gives cyclists a bad name, and discourages cycling as a more relaxed form of transport.

Thursday, October 07, 2010

A season in the saddle

Three months ago, I finally got around to getting a cheap and cheerful trip computer for my bike. Three months later I have done 767.4 miles at an average of 11 mph, as well as measuring that the final part of my journey to work that I couldn't measure with the car odo, starting with an off-road part, comes to just over 1.6 miles each way.

This also measures up to my order of magnitude guesswork that I average closer to 2000 miles in the saddle each year than 1000.

Tuesday, October 05, 2010

Computing per-service SIDs without sc.exe

How it's done is well known:

When configured to have a per-service SID (i.e. type of SID either "Unrestricted" or "Restricted"), the service SID is computed as S-1-5-80-{SHA-1(service name in uppercase)}

Here's a quick script to do it, that can be the basis for including the computation programmatically into e.g. installer generation.

So running it we get:

>& 'C:\Program Files\FSharp-2.0.0.0\bin\fsi.exe' .\ssid.fsx MyService
S-1-5-80-517257762-1253276234-605902578-3995580692-1133959824
>

which compares nicely with:

>sc showsid MyService

NAME: MyService
SERVICE SID: S-1-5-80-517257762-1253276234-605902578-3995580692-1133959824
>

where each of the 5 trailing facets is just the decimal representation of 4 bytes of the SHA-1 hash taken as a little-endian unsigned integer.

Saturday, September 25, 2010

Film — True Legend (Su Qi-Er)

Woo-Ping Yuen's latest chop-socky film about Beggar Su, the master of Dunken Fist wu-shu had its UK première here this evening.

It was almost solid martial arts mayhem, with just a few pauses for breath; however the structure of the film was a bit of a mess -- the intrusive 'now put on your 3D glasses/OK take them off again' around the training arc and what looked like it was going to be the Boss Fight didn't help (nor did the 3D itself where the actors often seemed to be floating detached from the rather washed-out scene around them.

The story itself seems to be a fairly direct one about Su and his adopted brother Yuan who spurns the generosity of his adopted family, and cue two-way revenge tragedy -- then just when you think it's all over, a long coda culminating in the real Boss Fight out of nowhere.

Clearly it must be following the high points of a well known tale -- but it ends up feeling unresolved because of the broken narrative rhythm, whereas stopping at the tragedy of the 3/4 mark would have given closure (if you don't ask too deeply why a martial artist of Su's calibre would dig a box out of sandy ground with his bare hands, rather than using some one-inch-punch technique to break open the lid in situ).

In all, not entirely satisfying popcorn fare.

Wednesday, September 22, 2010

Film — Henri Quatre (Henry of Navarre)

Added to the Film Festival programme after the program went to print, a competently done edited-highlights costume drama (German production, dialogue in French with some Italian and Latin) of the life and turbulent times of the eponymous French King.

Not something I would have gone out of my way to see, had I not already earmarked this week for the festival, but equally not something where I felt I'd wasted the afternoon.

Sunday, September 19, 2010

Anime — Kemono no souja Erin

Where 2007's Seirei no Moribito adapted the first of a series of ten novels by Nahoko Uehashi over 26 episodes, this 2009 series adapted the first two of a separate quartet of hers over 50 episodes; and while they are, in broad, fantasy, there is none of even the limited magic from the Moribito series.

We follow Erin -- crabapple -- for a decade or so from her childhood, where her mother, Soyon, tends some of the ferocious war lizards -- touda -- that the Grand Duke of the land employs as the ultimate weapon against potential invaders, and Erin herself is a keen observer of her mother's craft and of the natural world around her. As an outsider, from a despised people, who had only married into the touda raising village, Soyon is the obvious scapegoat when the whole colony fall to some mysterious sickness.

Literally cast adrift after her mother's death, Erin is eventually fostered by a kindly bee-keeper, under whose care she discovers more about the natural world -- and encounters for the first time the ohju, the wolf/roc lord beasts with their iridescent plumage. Being fascinated by these creatures, and nature as a whole, she finally manages to be inducted into the prestigious school-cum-ohju care centre near the capital, in the peaceful lands of the True Queen, whom the Grand Duke protects.

And as Erin takes to her craft, and violates all manner of traditions of ohju-care in doing so, politics and dissension amongst the successors of both the throne and the dukedom brew up and engulf her, against all her desires, until a final resolution that changes the status quo forever.

Being spread over so many episodes, the pacing is glacial during the first arc, until Erin is cast into exile (part of the reason why this review is somewhat belated); but once that is past, and the story starts to move, albeit at a leisurely pace, it becomes gently compelling, in the same quiet way that Aria is.

It is clearly an anime aimed at younger children -- not only are there some comic relief characters whose function is purely that; but the last episode concluded with an announcement that there would be a 10 episode summary then broadcast on an education channel. As such, where there is violence involving touda or ohju, the art moves from realistic to an effective highly stylized mode; and the person-to-person combats are almost bloodless; this being Japan, though, there are several themes, including Erin's preference for suicide to being used as a tool by any of the competing factions, that are probably not sanitizable for sensitive Western tastes.

Overall, good, but not great. Being on Crunchyroll, it's viewable without fansub guilt -- but equally it's unlikely to make it to DVD.