Sunday, August 28, 2011

Cambridge Film Festival

I pretty much started this blog as as a home for "My Cambridge Film Festival film reviews", however much my blogging has mutated over the years. And this weekend, the programme for this year's CFF is out -- and even more than last year, I'm feeling underwhelmed by the torrent of gritty and edgy features, right-on documentaries, and the usual run of "there's adultery in it, so it must be artistic". It's like it was all set out with a ground rule of "No fun allowed, SRS BZNS ONLY". Oh, and they're exhuming and showing the totally abysmal Silent Running (down there near the nadir of my list of the worst movies I've watched). Twice.

I suppose I could go watch The Seventh Seal and The Day the Earth Caught Fire again; but apart from being in two minds about this locally produced film, Dimensions (which could be another Time Crimes, but could equally well be artsy tosh with a few bits of stage dressing like non-genre writers generate when thinking they're doing SF), the new material singularly failed to catch my eye.

Thursday, August 25, 2011

Late summer cycling break

Same sort of gig as last year, only with different weather.


View August 2011 in a larger map

This time I arrived in Great Bircham about 10:30 on a beautiful summer's day, and headed out on the long run I'd meant to do last year, without the interruption by squall lines.

With the later start, I reached Little Walsingham after the first course of packed lunch (stopping for a pint at the Black Lion), and then kept going east as far as Binham (another pint at the Chequers Inn -- which, despite the name, does not seem to offer accommodation, but would have made a good base for another time), then looping back.

Second course of lunch -- cheesy rolls and a beefsteak tomato from the greenhouse -- at 15:00, partway along the coastal cyclepath, before heading for the first time through the grounds of Holkham Hall from the north. I'd steered clear of it, having previously taken other paths from the south which didn't make good cycling.

This side, the paths were properly made, easy going up and over the rolling terrain, then rolling downhill most of the way to Burnham Market; then the grind up the Ringstead road was where my legs started to tire, but still back to base not long after 17:00, having done about 48 miles.

Tuesday was wet, so read, did internet and generally rested up, with a little stroll around the local area late afternoon.

Wednesday was dry, if cool and generally cloudy, so another clockwise loop through the area (with one misstep when the path I'd meant to take was less obvious on the ground than the one I didn't), through lanes I'd mainly not taken before, with the goal of lunch at the Gin Trap Inn at Ringstead.

After their substantial club sandwich and chocolate mousse, I didn't want to take the rather punishing direct route to Sedgeford, but instead detoured out to Heacham, before finally ambling back (with a number of pauses where a full stomach made it more comfortable to get off and push rather than grind an uphill).

So that was about 28 miles; but between the end-of-day fade on Monday, and the push while digesting, my logged average speed went down from a steady 11 mph as it had been all summer, to only 10.8 :(

Monday, August 15, 2011

Powershell -- higher order functions with arguments that take arguments

Dead simple example based on this:

which results in

Name                                                  Prop                                                 
----                                                  ----                                                 
Junku                                                 **junku+junku**                                      

Also -- reminder to self : ShowUI -- WPF in PowerShell

Trivia

At end of day 11-Aug the car was reading 3474 miles; at the hour that I picked it up last year, 3485. Subtracting the 14 that were on the clock when I picked it up, 3460 or 3471 miles -- a lot less than in previous years.

Sunday evening, the bike was showing 2280 miles; 373 miles in the first 6 weeks of the new year, which is in keeping with last year's rate

The new guided busway cyclepath is a great new way into the town centre avoiding traffic, even though I have to do a mile and a bit on bridlepath or detour twice that distance to get onto the cyclepath feeding to it. If only there were paved spurs to the neighbouring villages. And even though the last hundred yards or so at the station end aren't finished yet.


In the garden, the plums have been in full flood for a couple of weeks -- much earlier than the usual Bank Holiday peak I usually plan for; indeed everything has been early, ever since the early onset of last winter.

Friday, August 05, 2011

What do you get when you iterate null?

In most cases, an exception; but in PowerShell you get $null.

Suppose I have folders with 0, 1 and more than 1 file in (called empty, full and two, say) and I want to enumerate the names of the files contained in each, with some general purpose code.

That should be no problem --

and let's write a little reporting function

When we report on the folders in descending order of contained files we get

test (2).txt
test.txt
System.Object[]
2
++test (2).txt++
++test.txt++
-----
test.txt
System.String
8
++test.txt++
-----
Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\Steve\Documents\scratch\Untitled1.ps1:6 char:15
+     Split-Path <<<<  -Leaf $file
    + CategoryInfo          : InvalidData: (:) [Split-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.Split 
   PathCommand
 
You cannot call a method on a null-valued expression.
At C:\Users\Steve\Documents\scratch\Untitled1.ps1:12 char:15
+   $arg.GetType <<<< ().FullName
    + CategoryInfo          : InvalidOperation: (GetType:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
++++

Not happy.

The first error is what you get when you work on the foreach over $null, yielding $null; and calling code has to special-case the single item return -- getting the .Length property of the return is not the number of files! For that replace $arg.Length by $arg | Measure-Object | % {write-host $_.Count} .

So try this

where we fight PowerShell's fragmentation of sequences all the way. Now we get what we expected

test (2).txt
test.txt
System.Object[]
2
++test (2).txt++
++test.txt++
-----
test.txt
System.Object[]
1
++test.txt++
-----
System.Object[]
0
-----

Oh, yeah -- the more PowerShell way of doing all this:

Sunday, July 31, 2011

Links for July

Microsoft Research's new F* language

Node.js 0.5.2 unstable branch now includes Windows

Scala.net reloaded -- still need to try it out with code that broke the old version.

July wrap-up

Well, it's been a busy month, hence quiet on the blogging front, starting out with:

A summer holiday

While Karen was in hospital last year, I noticed a flyer for Vitalise respite care holidays in amongst various papers, and thought "Let's do this next summer."

So we did.

We chose the first week of July at the Netley Waterside centre as a part of the country neither of us had been to for many years, went through all the paperwork about care requirements and doctor's reports, and crossed our fingers about how well we would get on.

In the end, it was wonderful.

It started off a bit fraught, though; as on the outward journey on a too hot and bright day for comfortable travel, as we were going past Tring, I realised that amongst the things I'd forgotten to pack was my wallet. So I just unloaded Karen and all the other bits, and turned around, to drive down again the next day with all the stuff we've forgotten (doing in two days way more miles than I drive in the average month).

Going back home in the heat was not much fun, especially when combined with stumbling into special traffic arrangements for the Henley Regatta just as everyone was heading home for the evening. But at home, I was cheered to get a phone call from Karen, who was enjoying being able to choose her own bed time.

Second time around I was actually able to find a parking space (as holidays run Saturday to Saturday, the first time there were arrivals and departures jostling for space), freshen up and join the Sunday chill-out.

The centre is really on the water's edge

View from the window

with the gardens sloping down to the path that runs along the sea wall, though the path is only wheelchair accessible in one direction.

Monday, we opted out of the excursion to the Sea Life Center, and after I'd scouted out the area, we went along to the local (the Prince Consort) and took advantage of the ramp up to the beer garden at back. to just sit, enjoy a pint and the summer weather, the two of us on holiday together for the first time in years.

Free flying

But that was the end of the good weather; cooler, windier and wet was the order of the day for the rest of the week. Tuesday's expedition to the Hawk Conservancy Trust at Andover was dampened by the rain arriving as we did, and continuing at varying strength until we left; but despite the weather, the display was spectacular, with sometimes a dozen birds in the air.

Lemur

We did manage to miss the rain for Wednesday's visit to Marwell Zoo, which we only manage to see less than half of; Thursday started wet, so the planned trip to Winchester became a shopping center trip, which we opted out of; and the Friday was an official at-leisure day where we took the opportunity to slope off to the pub (using the industrial strength ramp for the front step) for lunch.

And so, home.

For the holiday, there was the inevitable fact of separate hospital beds for sleeping; the food all home cooked, if unadventurous, with a very early 18:00 dinner time, with breakfast being as much a main meal as that in the evening.

Karen really enjoyed the comparative freedom to choose a bed time -- including at well gone midnight on Thursday, when it was party night.

And for me -- well, when I helped Karen with chasing the last morsels of a meal around a plate, I was told off, that one of the volunteers should do that while I enjoyed a break!

The volunteers are a key part of the operation -- a cheerful, enthusiastic and cosmopolitan crowd from all over the globe, working for bed and board, to just take over much of the step-and-fetch level care, from simply getting a cup of coffee, to pushing manual chairs while accompanying otherwise unaccompanied guests.

So, we'll be back, though next time, assuming I don't have to do the trip 3 times in quick succession, we may opt out of scheduled trips and do our own at our own pace (without being caught up in the half hour or more loading and unloading process).

Trivia -- at just before 10pm on Monday the 4th, I observed a 60-hour old nail-paring crescent moon setting over the port, the sun having set 40 minutes before.

30 years on

And today has been our Pearl wedding. Doesn't time fly!

Logistics being what they are, celebration was lunch, at the recently refurbished Carpenters Arms at Gt. Wilbraham. Being a Sunday, that meant roast, but by being so standard, allowed a like-for-like comparison : big chunks of roast, huge selection of veg, and the best Yorkshire pudding I've eaten in years.

Film — Detective Dee and the Mystery of the Phantom Flame

I this up picked up now it's out here on DVD, having heard of it some months ago.

The film is pure hokum wire-fu, and about as faithful to any of the source material as most movies (about on the level of the wartime Sherlock Holmes vs. Nazi spy films) but entertaining enough for an evening's viewing.

While van Gulik is in the writing credits according to imdb, I saw nothing of what he did by way of exhuming Chinese detective stories (except possibly the fact of popularising Judge Dee in the west) made it into the movie.

Film — Arietty

Seeing this after lunch today, we caught the UK theatrical dub (separate UK production team mentioned in the end credits, and some English regional accents -- most noticeably for the rat catchers -- amongst the cast).

It's been a long long time since I read the original (I have slightly more memories of Adrift and Aloft than of Afield), but the adaptation felt right, though one wonders if it wasn't the speech about the Borrowers dying out that attracted Miyazaki, something to slide in as a soapboxing scene.

Overall, the best thing out of Ghibli since The Cat Returns.

Monday, July 25, 2011

PowerShell strings, ints and comparisons

I hit this doing a little bit of playing around over the weekend, porting some old BASIC progams into PowerShell.

Most of the time treating strings of digits as numbers "just works":

but at times it all goes horribly wrong

with the ASCII value of '5' being 53, we see that these comparisons are being done lexically.

What is needed in these circumstances is an explicit coercion some place down the line; like:

Thursday, June 30, 2011

Select-Xml and nested XPath evaluations

Recall that

worked but

failed with error messages showing that the current iterated value has an XML string representation.

An alternative fix is to explicitly cast the subject of the inner XPath selection to XML, thus

though surprisingly

fails to yield any results from the inner search; and I've not so far determined why. Replacing the final $_.Node by [xml] $_ of course fails because False is not an XML document.

Target Achieved

Arriving home this evening, the bike odometer read 1906.8 miles since I installed it at the end of the first week in July last year. Adding the 97 miles I logged on my spring holiday on a hired bike, that pushes me over the 2000 miles mark. for the year (with 8 days to spare).

So, onwards to 3000 miles by year's end.

Wednesday, June 22, 2011

More PowerShell, XML and XPath -- Select-Xml and multi-node selections

Let's start with the same document as before.

Now at PowerShell 2, we can also do

which avoids the explicit call to the .net infrastructure, but wraps up the actual content we got in the previous example as the Node field inside an object. This is not so much of a problem when picking a single node, but when you want to do the equivalent of SelectNodes nested (e.g. for each Rule, do something with each setting) some disassembly is required in order to perform the inner selection:

It is, however, a bit of an oversight that the Select-Xml cmdlet doesn't consume SelectXmlInfo objects through the usual type conversion mechanisms inside the cmdlet infrastructure:

but once you know there's that gotcha, it can be worked around.

Sunday, June 19, 2011

PowerShell, XML and XPath

Some of the time, PowerShell makes picking apart an XML file nice and easy by providing properties on the XML object matching nodes; but inevitably you get to a point where there are more than one node of a given type as the child of the one you are at. So then it's time to break out the XPath.

Take a sample XML file (this one being a StyleCop settings file, being to hand, and complicated enough to be interesting):

And we want to extract the "FileHeaderMustShowCopyright" enabled property. So we can do something like this:

using PowerShell to navigate where there is no ambiguity, and XPath at each for in the road; or

or

or simply

depending how many of the steps above where we want to end up are of interest.

Friday, June 17, 2011

Splitting Pascal-Cased names in PowerShell

Something I needed to whip up recently, now slightly more polished. Starting with Jon Galloway's Splitting Camel Case with RegEx, and transposing to PowerShell's built-in regex syntax, the core operation becomes like

where we have to use the case sensitive -creplace operator to be able to insert spaces before capital letters. This outputs

Zomg
Wtf
Bbq

Wrapping it up into a function that handles a general batch of strings or things looks like this

so we can do this:

>PascalSplit @("ZomgWtfBbq", "ShazBot")
Zomg
Wtf
Bbq
Shaz
Bot
>

flattening the string array as we go (there is probably a better way to do that, but this works).

Following the link to James "poprhythm" Kolpack's enhancement, we can upgrade the simple function with his look-behind extensions to handle TLAs in names:

which we can test with

>PascalSplit LearnWCFInSixEasyMonths
Learn
WCF
In
Six
Easy
Months
>$a = PascalSplit @("ZomgWtfBbq", "ShazBot", "LearnWCFInSixEasyMonths")
>$a
Zomg
Wtf
Bbq
Shaz
Bot
Learn
WCF
In
Six
Easy
Months
>$a.Length
11
>

Saturday, June 04, 2011

And he still thinks "Referism" would work

One of those rare political rants...

Referism -- the quaint notion that a yearly budget referendum would do anything to check the ruling class.

The EU Referendum blog has started pushing this idea recently -- and in a massive act of cognitive dissonance does so while reporting how, when faced with a tight budget, the pols will protect their core function of providing sinecures to the nomenklatura, and trim the fluff at the margins (like providing services for the hoi polloi). And if that had been voted on, then next year, after parading the bleeding stumps, they'd come back for more ("or we'll kill this kitten/shut this library/sack these nurses..."). And that's assuming they don't take the get-out clause of Parliament being unable to bind itself and pass whatever emergency legislation to bypass.

The key problems are that politicians lie, money is fungible, and any stated budget breakdowns would be worth exactly as much as manifesto commitments are under universal suffrage. Oh, and it cuts out all the persiflage in the way of the root problem with democracy:

"A democracy cannot survive as a permanent form of government. It can last only until its citizens discover that they can vote themselves largesse from the public treasury."

Even a radical replacement like having MPs and Senators chosen by lot from the populace -- a way of taking power from those who most obviously actively seek it -- would still leave the problem of the entrenched Civil Service and the quangocrats.

Tuesday, May 31, 2011

CodeDOM and poor man's lambdas -- Part 2

Unfortunately there is one major sticking point in getting the generation to work for F# -- local variables are declared as let mutable rather than as a ref type which means that the necessary closure cannot be made; this is rather stronger than the lack of support for CodeDefaultValueExpression, which can be fudged around, or for nested types (which just become mutually recursive), though with up-front decision as to the language to generate (rather than making the choice following the expression tree), we could replace problematic elements with snippets.

That aside, the main operation looks like this, similar to the previous examples

If we eschewed F# support entirely, and used a partial class, then we could skip the constructor and field declarations and provide the input by any other mechanism of our choice in a hand-written part.

Generating the closure classes is a simple matter -- especially as the names of the parameters can be used as fields directly without any sigils, provided that they never contain the @this or proxy name by convention. This makes the closure class approach slightly simpler than a snippet driven use of direct lambda syntax, where local variable names to hold out parameters would in general have to be generated so as not to clash with any of the arguments:

where the individual field declarations have to work around the decorations for out or ref, thus:

The generation of the proxy methods is equally mechanical

So, given a simple type

we generate

The F# code contains


Manually replacing this with


then shows up on the next line

as an error The mutable variable 'proxy' is used in an invalid way. Mutable variables cannot be captured by closures. Consider eliminating this use of mutation or using a heap-allocated mutable reference cell via 'ref' and '!'.; and as there are no readonly locals in the CLR -- it's all F# compiler magic that gives the illusion of same -- we're stuck with no control to tweak to make proxy immutable in the F# output.