Coding Challenge #11

Coding Challenge Series / Technical Interview Series

A function you create is provided as a parameter a string of arbitrary length. This string has special characteristics though — once a character is read, it is zeroed out and is then read-only.

You may access the string’s individual characters either as an array or a function (whichever your programming language supports, for example string[#] or string.getChar(#)); no other built-in string functions may be used.

The function you create must do the following:

  • Find the longest segment delimited by a character, provided as a second parameter to the function
  • The start of the string and the end of the string should be treated as if they are the delimiter character.
  • Return the longest segment as a new string.
  • Your function may not make a copy of the entire string (only if it matches the long segment).
  • If two segments are the same length, return the last one found.

Oh Silverlight 2.0 Console (Example and Source code)

Try it here.

See a picture below: :)


I ran into one odd issue when using Silverlight 2.0 Beta 2….


void Page_Loaded(object sender, RoutedEventArgs e)
    // if you don't invoke this asynchronously, you can't add at load time
    // (seems to be a silverlight 2.0 issue)
                string.Format("Welcome!\nThe time right now is {0}.", 
        consoleCanvas.AnimateNewChild("\n\nThanks for stopping by "
            + "This code may be used for only for good, not evil.");

The code above for example — if the ConsoleCanvas control (the simple base control for the console output-like functionality) performs any UpdateLayout calls within the context of the Load event, the entire Silverlight control fails to load, silently. The only work-around I could discover was to delay what I wanted to occur by using the asynchronous invoke method on the Dispatcher object.

The easiest way to force a UIElement to measure itself is to use a little trick:

_holder.Width = this.ActualWidth;
child.Width = this.ActualWidth;

child.Width = child.DesiredSize.Width;
child.Height = child.DesiredSize.Height;

The console control maintains a visible (yet opacity is set to 0.0) StackPanel. Each time a new line of output is added via the AnimateNewChild method, it’s placed in the StackPanel. The StackPanel (_holder) is resized to fit the current width of the entire ConsoleCavnas control. Next, the UpdateLayout method of the StackPanel is called — which forces an immediate measure of all of the children (and thus forces any children of the TextPanel to potentially re-layout). The width and height are grabbed and permanently stored as the new size for the child.

Instead of using Storyboards and various animations, I found it more convenient to simply use a DispatchTimer and do the animations manually.

List<FrameworkElement> remove = new List<FrameworkElement>();

for(int childIndex = 0; childIndex < this.Children.Count; childIndex++)
    FrameworkElement child = this.Children[childIndex] as FrameworkElement;

    if (!child.Equals(_holder))
        child.Arrange(new Rect(0, Canvas.GetTop(child), 0, 0));
        double top = Canvas.GetTop(child);
        top -= 2.0;
        Canvas.SetTop(child, top);                       
        if (top + child.Height < 0.0)
// remove them all 
remove.ForEach(fe => this.Children.Remove(fe as UIElement));                

If an element is no longer visible on the screen, it is removed using a Lambda expression and the ForEach method on the List object instance named remove (after the repositioning loop has completed).

Download source, etc. here.

72Photos using Sample Pictures from XP?

Of all of the pictures that a new photo sharing/storage site could have used …, I can’t imagine why 72Photos would be using a photo that was included in Windows XP as a sample photo?

72Photos web site (as of June 18th):


(I tried refreshing the page to see if other pictures are rotated in, but it was the same picture).


Windows XP Sample Pictures:


The Best Free Syntax Highlighting Editor is ….?

Anybody have a preference for a text editor (for Windows)? Although free is preferred, I’ll take suggestions for non-free options.

My requirements:

  • It needs to be FAST
  • Syntax highlighting for common languages (C#/JavaScript/XML/HTML).
  • Maintained / supported
  • Work on Vista/Server 2003+
  • Multiple documents very important (tabbed)


I’d appreciate it if you took 30 seconds to plug what you use.


If Visual Studio is running, I use that normally — but if it isn’t, I don’t like the long load time.

Potential freeware candidates… (but I’m sure there are others):




Crimson Editor (no longer maintained)


Programmer’s Notepad

metapad (no longer maintained)

Notetab Light

Technical Interview Question/Coding Challenge #10

I’m renaming the series of interview questions to be “Coding Challenges.” Rules are still the same: you have about 30 minutes from start to finish for each question. The amount of code necessary to solve a problem is one or two whiteboards of reasonable sized handwriting (20-100 lines of code).

Technical Interview Series

Challenge #10

Create a structure best suited to efficiently storing a hierarchical file name and path system.

Now, write the code to merge two instances of the structures you have created into a single structure. There should be no duplicate file names in the single structure.