Scott Hanselman

All the world abuzz about Sudoku

October 14, 2005 Comment on this post [12] Posted in Gaming | Tools
Sponsored By

Sudoku1At a conference recently, I asked a delegate from Japan about Sudoku (??, sudoku) presuming that he, being from the originating country, would have some insights I didn't. Oddly enough he hadn't heard of it. Is this Japanese game sweeping the world, save Japan?

From WebSudoku.com: The rules of Sudoku are simple. Enter digits from 1 to 9 into the blank spaces. Every row must contain one of each digit. So must every column, as must every 3x3 square.

Folks seem obsessed with it. When I came upon the puzzle I figured it was a fluke, a curiosity, but then I noticed that American Airlines had Sudoku proudly displayed next to their Crossword Puzzles in the in-flight magazine. It's big in the UK. Some are 'unsolvable' (really hard, no logic applies). PocketMod includes pages with generated Sudoku puzzles.

Personally, I did a few, found it hard, found it interesting, but not that engaging. I mean, it doesn't tickle the nice parts of my brain like Crosswords. I feel that Crosswords require thinking, while Sudoku requires processing. Maybe that's not phrased well, but I think that since most programmers first instinct is to write a solver, and some write the solver faster than they can solve the puzzle just proves my point. Computers are a tool, my brain is not a computer. But, my brain can use a computer to solve a Soduku better than by itself. Trying to make my brain work like a computer just makes it ache.

BTW, don't mis-spell it, because Soduku is rat-bite fever!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Resetting Microsoft Update - Error 0x8024001D

October 13, 2005 Comment on this post [10] Posted in Musings
Sponsored By

Started getting Error 0x8024001D on Microsoft Update last week. Ended up renaming C:\windows\softwaredistribution\DataStore to C:\windows\softwaredistribution\DataStore.poo and that reset Microosft Update. Installed again and I'm back in business. Astonishing lame.

UPDATE: If you're getting error 0x80070057, you can rename c:\windows\SoftwareDistribution\Download to c:\WINDOXP\SoftwareDistribution\Download.poo and all updates will be downloaded and applied again.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Moving ViewState to the Bottom of the Page

October 13, 2005 Comment on this post [7] Posted in ASP.NET | ViewState
Sponsored By

I was working on some ASP.NET hacks and wanted to move the ViewState to the bottom of the page in order to get Google to pay more attention to my page and less to the wad of Base64'ed ViewState.

First I tried this because it's the closest to the way my mind works:

static readonly Regex viewStateRegex = new Regex(@"(<input type=""hidden"" name=""__VIEWSTATE"" 
value=""[a-zA-Z0-9\+=\\/]+"" />)",
RegexOptions.Multiline|RegexOptions.Compiled);
static readonly Regex endFormRegex = new Regex(@"</form>",
RegexOptions.Multiline|RegexOptions.Compiled);
 
protected override void Render(HtmlTextWriter writer)
{
    //Defensive coding checks removed for speed and simplicity. 
    // If these don't work out, you've likely got bigger problems.
    System.IO.StringWriter stringWriter = new System.IO.StringWriter();
    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
    base.Render(htmlWriter);
    string html = stringWriter.ToString();
    Match viewStateMatch = viewStateRegex.Match(html);
    string viewStateString = viewStateMatch.Captures[0].Value;
    html = html.Remove(viewStateMatch.Index,viewStateMatch.Length);
    // This will only work if you have only one </form> on the page
    Match endFormMatch = endFormRegex.Match(html,viewStateMatch.Index);
    html = html.Insert(endFormMatch.Index,viewStateString);
    writer.Write(html);
}

However, it was taking 1 thousanth of a second (~0.001230s) to do the work and that didn't feel right. Of course, by taking over the HtmlTextWriter and spitting it out as a string I've boogered up all the benefits of buffering and the whole streaming thing, but it still felt wrong.

So, against my better judgement, I did it again like this:

protected override void Render(System.Web.UI.HtmlTextWriter writer) 
{
    System.IO.StringWriter stringWriter = new System.IO.StringWriter();
    HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
    base.Render(htmlWriter);
    string html = stringWriter.ToString();
    int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
    if (StartPoint >= 0) 
    {
        int EndPoint = html.IndexOf("/>", StartPoint) + 2;
        string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint);
        html = html.Remove(StartPoint, EndPoint - StartPoint);
        int FormEndStart = html.IndexOf("</form>") - 1;
        if (FormEndStart >= 0) 
        {
            html = html.Insert(FormEndStart, viewstateInput);
        }
    }
    writer.Write(html);
}

I always assumed (mistake #1) that IndexOf was pretty expensive, particularly on larger strings. However, this method averaged out at 0.000995s. It consistently beat the Regex one, even though the Regex one was very simple, the Regexes were precompiled and (I think) simple.

Now, to be clear, I'm just playing here, and I know it's microperf and premature optimization. The really interesting thing would be to do a matrix of page size vs. viewstate size. You know, large page, small viewstate against small page, large viewstate and all points in between, then try it with both techniques and see which is better for these different scenarios. But, I'm tired and have other things to do, so if you like, there's some homework for you. What does this data set look like: viewstate size vs. page size vs. technique?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Professional ASP.NET 2.0 - Coming VERY soon!

October 07, 2005 Comment on this post [20] Posted in ASP.NET | Learning .NET | XML | HttpHandler | Web Services | Bugs
Sponsored By

Bill Evjen beat me to it, but it's true, the big Professional ASP.NET 2.0 book we've been working on for longer than you know is coming out in the next 2 weeks!

UPDATE: Madness! There's a sale on all Wrox/Wiley books at BookPool, and consequently you can pre-order our book for 50% off. Not sure how long that will last.

It's chock full of good information - well over a 1000 pages - and I think you'll enjoy it.

Here's the Table of Contents. I know that I hate buying a book when I only really need just a few chapters. We tried to pack a great deal of information into this book with enough broad strokes to make the beginner developer have to work at it, while the advanced developers still get valuable new details in each chapter.

Introduction.
1. Hello ASP.NET 2.0!
2. Visual Studio 2005.
3. Application and Page Frameworks.
4. ASP.NET Server Controls and Client-Side Scripts.
5. ASP.NET Web Server Controls.
6. ASP.NET 2.0 Web Server Controls.
7. Validation Server Controls.
8. Working with Master Pages.
9. Themes and Skins.
10. Collections and Lists.
11. Data Binding in ASP.NET 2.0.
12. Data Management with ADO.NET.
13. Working with XML.
14. Site Navigation.
15. Personalization.
16. Membership and Role Management.
17. Portal Frameworks and Web Parts.
18. Security.
19. State Management.
20. Caching.
21. Debugging and Error Handling Techniques.
22. File I/O and Streams.
23. User Controls, Server Controls, Modules, and HttpHandlers.
24. Using Business Objects and Interoperability.
25. Mobile Development.
26. Building and Consuming XML Web Services.
27. Configuration.
28. Administration and Management.
29. Packaging and Deploying ASP.NET Applications.
Appendix A: Visual Basic 8.0 and C# 2.0 Language Enhancements.
Appendix B: ASP.NET Resources.
Index.

It was tech-edited by such .NET luminaries as J. Michael Palermo who personally beat the crap out of me and made my chapters that much better. To all the editors, reviewers, and tech editors who responded to my IMs and 3am emails, and to my wife who put up with me up late for over a year, I thank you. To Bill and Devin, thanks for working so hard and including me in this project that we all started well over a year ago (and Bill nearly 2 years!) To Farhan and Srini who each contributed content and reviewed much, thanks for reviewing my code and for the opportunity to review yours.

I hope you guys enjoy it. We worked really hard.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Windows Pre-Login Wallpaper

October 06, 2005 Comment on this post [10] Posted in Musings
Sponsored By

PreloginIt's often useful to put information on the wallpaper of a Virtual Machine, or any Windows machine for that matter, that appears pre-login.

Put the full path in HKEY_USERS\.DEFAULT\Control Panel\Desktop\Wallpaper (string) via RegEdit. You can also set tiling on or off using the TileWallpaper (0|1) key in the same tree.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.