Tuesday, December 30, 2008

Anime — Allison & Lillia

On a world that is not our Earth, two nations that share a continent have long been at odds, glaring across the separating river, and often breaking out into war. In a period akin to the inter-war years of Europe, these two nations have fallen into an uneasy armistice. Two young people, Wil and Allison, learn from an old man of a secret treasure that could end this seemingly eternal war.

That is a set-up that could last a whole series -- but that's just the first 4 episodes; and in the peace that follows there is skullduggery afoot seeking to reignite the flames of conflict. That provides for a series of escapades, including the involvement of our heroes with the royal family of the tiny statelet of Ixtova; then at the half-way mark, the torch passes to the next generation, Lillia, daughter of the original pair, and Trieze, incognito prince of Ixtova.

It's rather Tintin-esque in flavour; with firearms proving a threat but (except in one case of an old chap needing to exit the stage for plot reasons) never doing any harm. And there are magnificent old style train and aeroplanes.

There is a continual motif of the couples never realising each others' feelings, which one has come to expect from anime, but that never really gets in the way of a good Boys' Own style of adventure. The real weak point is the ending, which is, if you pardon the pun, a bit of a trainwreck -- the last episode is very poorly paced, and uneven in style.

Still, not bad in all -- the journey was fun, if a bit delayed.

Nice idea while it lasted…

To summarize -- if your Scala.Net project only uses .Net 1 features, then you can tweak the IL to use the .Net 2 libraries if you wish; but you can't build something that invokes full .Net 2 functionality as yet.

That means trying to build a Scala project against Silverlight assemblies is a non-starter (or at least not a trivial one) with the current build process. Using the out-of-the-box assemblies:

scalac-net.bat astroclock.scala -Xassem-path 
System.Core.dll;system.dll;System.Windows.Browser.dll;System.Windows.dll
12@(06 15 12 80 ad 02 12 80 b1 12 88 c8)
error: error while loading Control, type 'System.Windows.Controls.Control' is broken
(15@2 in (06 15 12 80 ad 02 12 80 b1 12 88 c8))
9@(06 15 12 80 b9 01 12 86 80)
error: error while loading FrameworkElement, type 'System.Windows.FrameworkElement' is broken
(15@2 in (06 15 12 80 b9 01 12 86 80))
11@(20 01 15 12 25 01 12 78 11 85 b4)
error: error while loading UIElement, type 'System.Windows.UIElement' is broken
(15@3 in (20 01 15 12 25 01 12 78 11 85 b4))
11@(06 15 12 80 ad 02 12 86 38 11 5c)
error: error while loading DependencyObject, type 'System.Windows.DependencyObject' is broken
(15@2 in (06 15 12 80 ad 02 12 86 38 11 5c))
9@(06 15 12 80 b9 01 12 86 10)
error: error while loading Application, type 'System.Windows.Application' is bro
ken
(15@2 in (06 15 12 80 b9 01 12 86 10))
astroclock.scala:90: error: System.Windows.Application does not have a constructor
class MyApp extends Application  {
                    ^
…

while rebuilding the assemblies against either .Net 2.0 or silverlight mscorlib and trying again gave the even more fundamental, but well known

scalac-net.bat astroclock.scala -Xassem-path 
System.Core.dll;system.dll;System.Windows.Browser.dll;System.Windows.dll
error: error while loading String, type 'System.String' is broken
(PEModule.getTypeDefOrRef(): TypeSpec)
one error found

So, to do this would mean upgrading the scala-net compiler to understand .Net 2.0 constructs.


Later:--

In constructs like (15@2 in (06 15 12 80 ad 02 12 80 b1 12 88 c8)), the 0x15 (at position 2) is the code ELEMENT_TYPE_GENERICINST, which is then followed by <an mdTypeDef metadata token> <argument Count> <arg1> ... <argN>. The type metadata turns out to be a type-spec; but the rest of it I've not yet unpicked. And then there'd be reverse-engineering the Scala MSIL decompiler...

The first culprit is DependencyObject (#22 in the typedef table), for a private field; but there are dependency properties on UIElement which suffer the same.

Monday, December 29, 2008

Scala-light?

I ordered a copy of Programming in Scala last Sunday -- and to my surprise, it arrived on my doorstep this morning. This, of course, deflected me from my F# and Silverlight activity today.

I think I shall have to try the experiment of putting Scala.Net into Silverlight, just as part of my usual "can I wedge this into that" play.

I would start with the recipe as before, in the library form; but to retro-fit a link against the Silverlight mscorlib which has the signature

rather than the mainline .Net 2.0 assembly.

What fun toys these are!

Sunday, December 28, 2008

F# CTP and Silverlight 2 and XAML

Following up from yesterday, the rudiments of the clock, to show XAML integration in the F# plus Silverlight combination. This should be enough of a template for starting with and mutating to taste.

The code is unchanged in the Feb 2010 (v 1.9.9.9) CTP.

astroclock.xaml:

which we note has a UserControl as root, and astroclock.fs:

with the obvious AppManifest.xaml:

LATER: Data binding sort of works sometimes; I can get it to work when set at run-time to bind a string to a TextBlock via myTextBlock.DataContext <- this.StringProperty (but not yet through XAML), and Sliders are being totally recalcitrant...

I think there is some autogeneration magic just not happening for F# -- the best I can get seems to be to approximate a one-time binding -- so it's back to wiring up events by hand.

Saturday, December 27, 2008

F# CTP and Silverlight 2

Feb 2010: This post is probably obsolete as we're coming up on Silverlight 4.0, so I've not retested. You might get away with changing the 1.9.6.2 version in the file path to 1.9.9.9 now.

Tinkering with my silverlight/IronPython planetarium clock, I find that the bulk of the errors I'm making are in units of measure -- is this angle in degrees, radians, hours or days? This is just the thing that F# CTP has built in features to cope with. So, proving the concept of Silverlight with F#...

Google turns up a bunch of references, some assuming a full Visual Studio while I'm developing on a laptop with just IronPython Studio and F# part of the time; others slightly out of date (still referring to System.Windows.Controls.dll from the beta).

The latter, John Liao's post, looked promising, though, so I duplicated it thus--

  • New F# library; paste the code in to the autogenerated Module1.fs
  • Remove all references supplied by default
  • Add a reference to System.Core and to System.Windows by navigating directly to the Silverlight SDK binaries in C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies -- at this point you can also add any others you're going to want
  • Use the suggested AppManifest.xaml without the System.Windows.Controls.dll line
    <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" 
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                RuntimeVersion="2.0.31005.0" 
                EntryPointAssembly="SilverLightFSharp" 
                EntryPointType="SilverLightFSharp.MyApp">
      <Deployment.Parts>
        <AssemblyPart x:Name="SilverLightFSharp" Source="SilverLightFSharp.dll" />
        <AssemblyPart x:Name="FSharp.Core" Source="FSharp.Core.dll" />
      </Deployment.Parts>
    </Deployment>
  • create a folder in $(ProjectDir) called simplebutton and copy C:\Program Files\FSharp-1.9.6.2\bin\FSharp.Core.dll into it, along with the AppManifest.xaml above
  • create an empty file null.py in the folder to keep chiron quiet
  • Add the following post-build steps
    cd $(ProjectDir)
    copy /y $(OutDir)$(TargetFileName) simplebutton
    "C:\Program Files\IronPython 2.0\Silverlight\bin\chiron.exe" /d:simplebutton /z:simplebutton.xap
  • Use the suggested TestPage.html, putting it in $(ProjectDir)
  • Build project
  • Load page in browser and enjoy

Note that the FSharp.Core.dll assembly is crucial in the manifest, even though it's not needed as an explicit reference in the project at build time -- everything links happily with it as an implicit component for building -- but without it there in the manifest and the XAP, the Silverlight content fails to load, silently, without putting up anything into the error reporting <div> as a cry for help!

For our Gauleiter of Culture

A propos of this.

OnePlusYou Quizzes and Widgets

"This rating (G) was determined based on the presence of the following words: stab (1x)"

But also

blog readability test

which probably rules out any pols.

Also, at the typealyzer

ISTP - The Mechanics

The independent and problem-solving type. They are especially attuned to the demands of the moment are masters of responding to challenges that arise spontaneously. They generally prefer to think things out for themselves and often avoid inter-personal conflicts.

The Mechanics enjoy working together with other independent and highly skilled people and often like seek fun and action both in their work and personal life. They enjoy adventure and risk such as in driving race cars or working as policemen and firefighters.

A week of contrasts

Saturday last, getting up early-ish to get hair cut, and attend to vanities before going out in the evening, so driving into town rather than taking advantage of the mild weather. Town was quiet, the only real activity a long queue in Borders; though Morrison's had been very busy Friday late morning.

Sunday, very mild, cycling to the garden centre with just an open denim jacket over my T-shirt, for sake of sleeves, and sandals on feet.

Two days at work, winding down, some self development, some tidying up of bugs, getting home with 29000 on the odometer as I parked. Wednesday, cooler, and dull, OK for cycling -- but had brightened to T-shirtable when I nipped out for lunch. Usual dinner with friends in the evening, even if being designated driver takes the edge off.

Thursday -- don't get up at all; drift downstairs for breakfast to eat in bed just before dark.

Friday -- drive to the in-laws, with the A12 being quite busy, and slow to the Blackwall Tunnel. Coming back being surprised on the M11 to often be cruising past traffic in the slow lane when only doing 60 myself.

Today -- hard, white frost again overnight. Drive in to town late morning for a few odds and ends to find the place seething. In all respects, the opposite of last week.

Friday, December 26, 2008

Silverlight 2 and Opera

To make the previous example also work on Opera I would have to

  • Set the data on the object to be "data:application/x-silverlight-2," to get it to work at all
  • to restore the effect of transparency remove the <param name="windowless" value="true" />
  • set an opaque value rather than <param name="background" value="#00000000" /> matching the page background colour
  • manually tile a matching background image and set background image brush with Stretch="None" to match any page background image

In particular, there seems to be no obvious way to get at the parameter set of the object from JavaScript via a DOM look-up on the <object> tag, otherwise I would have done some jQuery magic via browser sniffing instead.

Bug in my jQuery usage. BRB

You can do something like

but once you've tiled with an opaque image, there's no effect (even if this substitution were in fact in time to be useful).

Sample here.

I guess such customization would be possible via the silverlight.js file; however that needs tome work of its own to fix up to provise silverlight 2 data types.

Tuesday, December 23, 2008

PoSh v2 CTP3 linkfest

The release notes give a view from 50,000 feet; the help file stubbornly refuses to play for me (the document window gives a 404 error); but there's already some stuff about the new material out on the 'net:

CTP2->3 migration guide.

Module Manifests

Advanced functions (previously script cmdlets).

Eventing.

Parameter sets for advanced functions.

Updated remoting.

Hmm. This looks like it might resolve those 404 issues...

PoSh v2 CTP3 is out

Download here : http://go.microsoft.com/fwlink/?LinkID=131969

Although it states:

  • Windows PowerShell V2 CTP3 release is compatible with and replaces previous versions of Windows PowerShell. To install the Windows PowerShell V2 CTP3 release you must uninstall any previous version of Windows PowerShell.
  • Windows PowerShell V2 CTP3 uses the execution policy setting from the previous installation, if present. The Windows PowerShell installer does not remove or change the execution policy when you uninstall Windows PowerShell.

On XP, I got bumped from a previous Unrestricted to AllSigned, as I found when starting up the new shell for the first time and getting my start-up script denied.  Going Set-ExecutionPolicy unrestricted then resulted in

Set-ExecutionPolicy : Windows PowerShell updated your
execution policy successfully, but the setting is overridden by a
policy defined at a more specific scope.  Due to the override, your
shell will retain its current effective execution policy of
"AllSigned". For more information, please see "Get-Help
Set-ExecutionPolicy."
At line:1 char:20
+ Set-ExecutionPolicy <<<<  unrestricted
    + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
    + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Com
   mands.SetExecutionPolicyCommand

Running the C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe executable directly (not via shortcut) as the local Administrator (right-click, Run as...) lets that user change settings without spitting out a message stating that this is futile; but that is not propagated globally.

Other users (like my usual login) trying to run scripts still got the same

File ...\???.ps1 cannot be loaded. The file ...\???.ps1 
is not digitally signed. The script will not execute on the system. 
Please see "get-help about_signing" for more details..
At line:1 char:2
+ . <<<<  '...\???.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

as before, and going Set-ExecutionPolicy unrestricted still results in the same message as above, too!

I've not yet found an official work around to this override through PoSh itself -- but you can directly frob the setting by going to the registry (OK, you can do this in PoSh as well, but it's still "cheating") and setting the value of HKEY_CURRENT_USER\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy from AllSigned to Unrestricted.  Although running as Administrator has changed the key at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy to Unrestricted, any per-user setting that has already been struck from this pattern seems to remain to override this.

LATER : setting the HKCU value to RemoteSigned then leaves me at Unrestricted, until I similarly edit the HKLM key as well. LOL WUT?

Set-ExecutionPolicy still remains ineffective as a normal (local administrator) user.

Friday, December 19, 2008

Writing PowerShell cmdlets in F#

Note: This issue was resolved by the May 2009 CTP. The cmdlet code is unchanged in the Feb 2010 (v 1.9.9.9) CTP.

There's a catch to this, as I discovered today. You can't -- or to be accurate, you can't inherit PSSnapIn in F# yet. As also noted here, the F# compiler gets its knickers in a twist about the internal abstract members higher up the inheritance chain, culminating in an error stating that PSInstaller.get_RegKey() and PSInstaller.get_RegValues() are not implemented.

You can't fix this with cunning reflection tricks (if you make an override method to call via reflection into the base class, you get told that there's nothing public to override; if you make it a member, you get back to the same error as before). And you can't fix it by delegating the install to a PSSnapIn subclass in a different assembly, because that just registers the delegated assembly (which probably contains no cmdlets at all).

But you can use a CustomPSSnapIn subclass in an assembly that references the F# code. For a very simple "Hello World", based on the code samples from the Wrox PowerShell Programming book we do something like

in the custom snap-in subclass, which is the only class needed in a C# project, which generates the assembly that you actually register via installutil. This project references your F# module for the cmdlet classes that do the real work, and just does the work of publishing them to the PoSh infrastructure. The essentials of the F# code are (in the .fsi file):

where the constructor declaration is essential for the cmdlet to work, and in the .fs file:

And then we can write F# cmdlets as we wish...

Arch-druid talks sense shock!

If even the Archdruid of Canterbury can see what's going wrong, how bad must it really be getting?

Thursday, December 18, 2008

Sunday, December 14, 2008

Erlang is great stuff!

Following up on Erlang is Interesting and Heartfelt thanks for the Erlang tips!

I have completed the reimplementation of what was about 20kloc of C/C++ (15kloc of which being an SDK of which I actually used only about half the capabilities of), in just over 1kloc. I could probably refactor/rewrite the C/C++ to reduce it in size by a factor of 3-4 -- I have an approximately 1kloc replacement for the parts of the SDK I actually use -- but there is a limit around that mark where the amount of code needed just to placate the Win32 gods applies a hard lower bound for the tout ensemble.

And not only is it shorter (a big win for keeping what's going on in your head in the first place), using the right language for the job means that the threading story is far clearer, too. And, as an unlooked for bonus, the whole thing (a protocol terminating data pump) performs far better under load, without being at all resource heavy.

Given the choice, I don't think there's another platform that I'd choose for doing such bits of network plumbing infrastructure.

Saturday, December 13, 2008

Maximum Moon

A blanket of rain clouds hid the full moon that was both close to perigee and close to the winter solstice last night; but Thursday's clear night was very bright and steely grey, sparkling in hard frost under a cloudless sky with a near as makes no difference full moon.

IronPython 2.0 RTW + Silverlight 2.0

15-Apr-15 : Please ignore -- obsolete technologies

Following on from the β2 sample

Changes made as follows:

  • web page page, silverlight object type : type="application/x-silverlight-2"
  • web page, fallback download location : "http://go.microsoft.com/fwlink/?LinkID=124807"
  • AppManifest : RuntimeVersion="2.0.31005.0"
  • AppManifest : add <AssemblyPart Source="Microsoft.Scripting.ExtensionAttribute.dll" />
  • AppManifest : remove <AssemblyPart Name="System.Windows.Controls.Extended" Source="System.Windows.Controls.Extended.dll" />
  • app.py -- remove the line clr.AddReference('System.Windows.Controls.Extended, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
  • Delete all earlier assemblies and use all the assemblies from C:\Program Files\IronPython 2.0\Silverlight\bin.

Or, from scratch, with the embedding paged base around C:\Program Files\IronPython 2.0\Silverlight\script\templates\python\index.html ...

app.py

app.xaml

AppManifest.xaml

The XAP file is now down to 935kb, which considerably closes the gap with Jython 2.2.1's 670k but is still noticeably larger than a minimal Jython 2.1 applet:

274467 Aug 13 21:48 applet.jar
       956662 Dec 13 17:50 app.xap
         2266 Dec 13 17:53 index.html
         2071 Aug 13 22:02 jython.html

However, now both products are at a stable release, it starts to make sense to actually use the technology.

Following up here.

Sunday, December 07, 2008

Crisp and clear

The weekend has been clear, sunny or moonlit by turns, and very cold; the days very agreeable in the level of sunshine. The cats agree, by going out to sit on the picnic table and bask.

The Tonks are showing that they have pedigrees, by coming in to use the litter tray at intervals -- Kami being an accomplished master of the one-way catflap now.

It was funny to watch them when going out to find something to tastier to drink than tapwater licking at the film of meltwater on the ice in the various containers on the patio.

Wednesday, December 03, 2008

Syntax Highlight Brush for F#

Following on from Scott Hanselman's post about the SyntaxHighlighter script, here's the secret sauce I needed to get it to work.

And here's a first stab at an F# brush, which is in use for this post.

The symbolic class is not yet working; ocaml and reserved do work, and there's more to add, as noted in the introductory comment, if I can get past the symbolic hurdle.

Winter wonderland

Last night wheeling Karen to WI and back, the going was very slippery underfoot and everything was sparkling in the street lights.

This morning, I not only waited until well after sun-up to go to work, but decided to take main roads into work; but that still meant a mile or so on minor roads to get there.

And almost as soon as I got out of the village, traffic started piling up. The reason -- two recovery trucks pulling cars out of a ditch, the only length of ditch without hedges along the whole road.

Very slow journey.

Links for 3-Dec

Reducing memory leaks in JavaScript.

nUnit 2.5 now in beta.

So is Moonlight 1.0 (Silverlight 1.0 for Mono).

JavaScript syntax highlighter -- example page -- Now I need to write F# and Erlang brushes.

Testing that DLR language implementations honour interface contracts.

Monday, December 01, 2008

Belatedly, New Year's Resolution

Finally, belatedly, I have achieved my New Year's Resolution (of 1920x1200) -- for the last couple of years since my 1997 vintage 19" 1600x1200 VDU died, I have had to put up with having a smaller screen resolution at home than in the office (equivalent 19" 1600x1200 VDU, upgraded a few weeks ago to 24" 1920x1200 LCD), which has meant that when I GotoMyPC (the best acquisition Citrix has made during my time with them so far as end-user dog-fooding goes) to home-work, I've had to suffer blurred/shrunken text.

No longer. Now, for the same £200 price-tag as the 19" 1280x1024 screen I got as a replacement for the dead VDU at the time, I now have the same headline spec as at work; this being about 1/4 the price I would have had to pay had I gone straight to this spec. So now I see my office screen at 1:1; and playing video, especially wide-screen video, is just amazing.

This has not been for want of trying, though -- just that actually getting my hands on such an item for the instant gratification facto has taken 3 months : they seemed never to be in stock when I tried to buy.

Amused

The SEO benefits of clean web design emerged in thread on /a/ over the weekend. Apparently my NGE fan-site comes very high up Google search.

This emerged in the context that some who feel that my opinions are not so much heterodox as heretical were uncomfortable that my writings should be so easily stumbled across by newcomers.

Nothing stopping them writing their own sites with cleaner design, though.

Links for 1-Dec

PowerShell synch script for SysInternals tools.

Expression<T> demystified.

Xen makes OCaml news.

Minimal Erlang distro.