Another big Monad blogger splash

Without a doubt, we are blessed here on the Monad team with a community of very talented bloggers.  To add another to the list, we are now joined by Karl Prosser.  His first few blogs are doosies – integrating Monad with SQL server, and hosting Monad in an interface very similar to SQL’s Query Analyzer.

Keep up the great work!

 

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]

Introduction to Cryptography

Cryptography is one of the areas about security that many feel is difficult to approach.  Encryption, certificates, signatures, public keys, hashing – these are terms that most people like to keep at arm’s length.

That is until you’ve read a good introduction to the subject. Although the topic of cryptography is large and very deep, a good introduction easily provides the concepts in which to frame your thoughts and discussion on the subject.  At the very least, it can help give you an idea about what that big mess of text is at the bottom of types.mshxml :)

Pithy and Readable? Do tell!

A long time ago, Raymond Chen wrote about how to interact with the ShellWindows COM object using C++.  It was doable, but clumsy.  He then revisited his post, showing how much easier it was when accessed through a scripting language as its designers had intended.  As can be expected, the comments flowed fast and furious in illustration of the conciseness of various languages that the readers were fond of.

I’ve been meaning to show the Monad equivalent – not just because it is pithy, but because it is pithy and meaningful.  As MOW points out, it is amazing how frequently this happens.

MSN Search, without the carpal tunnel syndrome

As their blog  has so far failed to point out, it looks like MSN Search pushed a new release live today.  Unfortunately, I can’t find any mention anywhere on the internet about what’s new. 

I very much like the new colour scheme, though.  It’s light.  It’s fresh.  The old blue box made me feel constrained, but the impact goes deeper than that.

When I worked on Encarta, there was a MSN-wide effort to move to the white theme.  One of the major factors was perception: people feel that sites with minimalistic palettes load faster.  Even if the only change is to the background colour in a stylesheet.

MSH Logo – allowing users to extend its functionality

In the last article, we continued to develop our version of MSH Logo.  In typical software-geek fashion, we designed a train-wreck for a user interface.  Rather than provide our users with the power required to make fancy graphics, we shackled them with a handful of ineffective commands.  But it was all we thought the users needed!

Many situations aren’t even this clear-cut.  For example, the Microsoft Office System is a phenomenal suite of applications.  It has more features than you could ever want to count.  But that still isn’t the whole story.  The scripting support in Microsoft Office turns it into an infinitely extensible, bona fide, application development platform.

It doesn't matter if search engines lie

Robert Scoble recently asked the question, “Why Do Search Engines Lie?”  He calls out that the engines are usually off by a few results - with 692 results instead of a claimed 699, 100 results instead of a claimed 101, etc.  The numbers are worse when you count only “unique hits.”  That gives numbers like 62 of 713, or 44 of 368.  I’m sure that developers of the respective search engines could give great technical answers to his question, but it’s probably best answered rhetorically: “Who cares?”

Caching credentials for administrative tasks

Tony has been working on a great series of posts to explore some of Monad’s security features.

He provides a method to start programs using the Administrator account, without having to always type in the Administrator’s password.  To do this, he uses the export-secureString cmdlet to export the password to disk, and the import-secureString cmdlet to re-import it when required.

The export-secureString cmdlet, when not given an encryption key, uses Windows’ Data Protection API, known more commonly as DPAPI.  The Data Protection API is the standard Windows mechanism by which programs protect sensitive data, such as passwords and private keys.  Internally, Windows protects the data by encrypting it with a password it creates from your logon credentials - making the data unavailable to other users.

MSH Logo – A GUI Disaster

Ok, so now that we’ve talked about our grand design for MSH Logo, our next task is to simply integrate this into a GUI.  You can download the Visual Studio 2005 project from here.

The most interesting class, by far, is our Turtle class:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Monad_Hosting
{
    /// <summary>
    /// A turtle class that implements some of the logo primitives.
    /// It stores a reference to the canvas upon which it draws, and
    /// is responsible for drawing on that canvas.
    /// </summary>
    class Turtle
    {
        Graphics canvas;
        Pen drawingPen = new Pen(Color.LightGreen);

        // Although the canvas can only represent integer
        // positions, we store our state in double precision.
        // Otherwise, most interesting graphics (that tend to
        // involve recursion and small numbers) look terribly
        // broken.
        double currentX, currentY;
        bool penDown = true;
        bool showTurtle = true;
        int direction = 90;

        public Turtle(Graphics canvas)
        {
            this.canvas = canvas;

            Initialize();
        }

        public void PenUp()
        {
            penDown = false;
        }

        public void PenDown()
        {
            penDown = true;
        }

        public void Forward(double steps)
        {
            int oldX = (int) currentX;
            int oldY = (int) currentY;

            // In essense, the turtle draws the hypotenuse
            // of a triangle as it moves.  Since the user provides
            // the length of the hypotenuse, we use standard
            // trigonometry to determine the X and Y components
            // of the movement independently.
            currentX += steps * Math.Cos(DegToRad(direction));
            currentY -= steps * Math.Sin(DegToRad(direction));

            if(penDown)
            {
                canvas.DrawLine(drawingPen, oldX, oldY, 
                    (int) currentX, (int) currentY);
            }
        }

        public void Backward(double steps)
        {
            Forward(-1 * steps);
        }

        public void Left(int degrees)
        {
            direction = (direction + degrees) % 360;
        }

        public void Right(int degrees)
        {
            direction = (direction - degrees + 360) % 360;
        }

        public void Hide()
        {
            showTurtle = false;
        }

        public void Show()
        {
            showTurtle = true;
        }

        public void Draw()
        {
            if (showTurtle)
            {
                // We leverage the 2d transformations of the .Net
                // Graphics class here to save us from doing the 
                // math for rotation contortions ourselves.
                // Rather than draw a rotated turtle, we instead rotate
                // (and reposition) the canvas, then draw a straight
                // turtle.  When we restore the canvas again, the
                // turtle now appears rotated.

                System.Drawing.Drawing2D.GraphicsState canvasState = 
                    canvas.Save();
                canvas.TranslateTransform((float) currentX, (float) currentY);
                canvas.RotateTransform(90 - direction);

                canvas.DrawLine(drawingPen, -4, 4, 0, -8);
                canvas.DrawLine(drawingPen, 0, -8, 4, 4);
                canvas.DrawLine(drawingPen, -4, 4, 4, 4);

                canvas.Restore(canvasState);
            }
        }

        public void Reset()
        {
            Initialize();
            canvas.Clear(Color.DarkGreen);
        }

        private void Initialize()
        {
            currentX = canvas.VisibleClipBounds.Width / 2.0;
            currentY = canvas.VisibleClipBounds.Height / 2.0;

            penDown = true;
            showTurtle = true;
            direction = 90;
        }

        // The user specifies their angles in degrees, but
        // the .Net math classes prefer radians.
        private double DegToRad(int degrees)
        {
            return (Math.PI * (double) degrees / 180.0);
        }
    }
}

Our GUI application mainly interacts with the Turtle object:

Gregg Shorthand Quick Reference

This quick reference summarizes the useful resources available at gregg.angelfishy.net. The document puts the Gregg alphabet, and 147 brief forms all in one helpful quick reference.

MSH Logo - our design strategy

As I mentioned last time, this series of articles will introduce you to some of the features of Monad’s hosting model.  Before we get into the details of hosting Monad, though, we need to first lay out our conceptual framework.

Our application is a simple WinForms control.  It displays a small triangle (of Logo fame,) and users control movement of the turtle through a small set of commands.  The turtle supports the following: