Tuesday, September 30, 2008

Micropoll

 I recently discovered MicroPoll through Scott Hanselman's site and liked the format so I thought that I'd try it out with an inline survey on this blog to see how well it works.

 

Here are the results of the poll:

Polls Powered By MicroPoll

Monday, September 29, 2008

Google Chrome Installer Error 1625

Just tried to install Google Chrome on Server 2008 and received the following error from Google Chrome Installer:

Installation failed. Component ChromeGears failed to install. Detailed message: The installer encountered error 1625: The installation is forbidden by system policy. Contact your system administrator.

Solved: Ran the ChromeSetup.exe file as administrator and everything installed okay. Open the containing folder of the setup file and right click install file (ChromeSetup.exe) and select "Run as Administrator."

Friday, September 26, 2008

Hosts file locked (read-only) on Server 2008

I was trying to edit the HOSTS file on Windows Server 2008 with Notepad++ but after editing it wouldn't let me save it with a "Save failed" - "Please check whether if this file is opened in another program" (the ...whether if... is their message not my typo).

Anyhow, didn't turn out to be read-only as I initially thought or another process as suggested (I did try stopping several services to see if that would help) but instead it turned out to be the fact that I hadn't started Notepad++ as administrator.

I don't understand why I need to run Notepad++ as administrator to edit the HOSTS file but aparently I do. I'm sure that it's just a matter of getting used to this new Vista style UAC that I assume is the underpinning of the security model in Server 2008.

To run Notepad++ (or any other program) as an administrator just right click on the application and select "Run As Administrator."

Thursday, September 25, 2008

Double URL Encoding

Sometimes you know the answer but you still want to see it happen to make yourself happy.

Question: If you encode some text and then encode it again is it encoded inside encoded?
Answer: Yes
Question: What happens if you decode it twice as well?
Answer: You get back to the original unecoded text

Here is a snippet of text that demonstrates it using C# in .NET. You need to include the System.Web library.

            string stringWithAmp = "&";
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlEncode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlEncode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlDecode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlDecode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
 

Monday, September 22, 2008

The Second Law of Continuous Integration

From this post on Jeremy Miller's blog:

Jeremy's First Law of Continuous Integration:

If you check in very often and/or first, you can make merge conflicts be someone else's problem.

The Second Law:

If someone did sneak in a check in between two of your check ins then the merge problem will be small because the number of changes you've done will be small if you're checking in frequently. 

The Law of Encouragement:

Point this out to your coworkers to make all changes between check ins as small as possible so that you don't waste half a day on merging.

Reinstall of Vista and Ubuntu Virtual Machines

Over the weekend I was trying to install a few things on my Vista and Ubuntu Linux virtual machines. Both are 64bit VM's runing under Server 2008 x64 with Hyper-V. I ended up in the situation where the Vista machine lost its network connection and then wouldn't power down. It got to the point of almost powering down and then hung. I tried all sorts of things to sovle this problem but was unsuccessful. This state of the VM was also causing Server 2008 to blue screen on about every fifth reboot and when I looked at the log files they always related to the VM. I also tried to start and stop the Linux VM (which had been in a stopped state all this time) and the same thing happened inasmuch as I couldn't power it down.

In the end I uninstalled the Hyper-V role in Server 2008 and deleted the VM machines from the hard disk. Here are my notes about what I learned and the mistakes that I made.

  1. Download and get the ISO ready before creating a virtual machine.
  2. When setting up a VM that does not have Integrated Components select a legacy network adapter.
  3. Uncheck the box that says "start VM when this wizard finished" (or somthing like that).
  4. Once you've created the VM open the settings and check them all. Check that there's a single network adapter and that it's a legacy adapter.
  5. As soon as you've run the install of the operating system and it's completed its initial updates take a snapshot of the VM.
  6. Take regular snapshots of the VM after each operation that you perform.

 

Saturday, September 20, 2008

Hyper-V with Vista x64 and Ubuntu Linux Desktop x64

Notes about setting up Vista x64 as a guest virtual machine on my Windows Server 2008 x64 machine.

The installation ran relatively smoothly. I pointed the Hyper-V wizard at the Vista x64 iso and the installation happened.

The only tricky part was getting the network connection up and running. On Hyper-V, under settings for Vista x64 I had to add a Legacy Network Adapter and set that to my point to my Virtual Network. I also left the MAC address at Dynamic and unchecked the "Enable virtual Lan identification" check box.

When setting up Ubuntu Linux Desktop x64 I had to use the same strategy with setting a Legacy adapter to get it to hook onto the network.

I read somewhere that it's the x64 part of these operating systems that cause you to have to use the legacy adapter. I'm right on the edge of my knowledge at the moment as I've never done any of this before so take what you read with a pinch of salt. I now believe that it's because the Integration Components (IC's) are not available for these OS's.

Did Borland throw away the C++ compiler market?

Back in the days of DOS to Windows when the market was about 60% DOS and 40% Windows (early 1990's) Borland was the first to the market (when compared to Microsoft) with a C++ compiler. Shortly after this compiler came out they also brought out 2 libraries. One was called OWL which stood for Object Windows Library and I forget the name of the other but it might have been TF for Turbo Framework. OWL was a library for writing Windows apps and TF was a windowing library for DOS.

During that period a lot of programmers were trying to target both platforms to maximize the number of platforms their software ran on - an obvious goal and is still in practise today. What I thought was crazy was they fact that OWL and TF had completely unrelated API's. In other words, there was no way you could easily target 2 platforms with this compiler. At the time I thought that it was ludicrous and I've never seen a good explanation for it.

A short while later Microsoft brought out the first of its Visual C++ compilers with MFC (Microsoft Foundation Classes) and walked away with the market. MFC never targeted DOS but by then I believe that the PC market share had reached a 50/50 point and it was obvious that DOS was doomed. Had Borland brought out a single API that could target both systems I believe that they would have survived for many more years in that market and may have even been a competitor today.

Friday, September 19, 2008

How Stack Overflow is helping me

Jeff Atwood from Coding Horror has recently moved Stack Overflow to public beta. According to my user profile, as of today I've been using it for 35 days and I've found it amazingly useful.

When you're coding there is often a question that has an easy answer but you don't know the answer off the top of your head and your initial searches on Google don't reveal it. I have found that a well worded question on Stack Overflow will usually yield an answer within a few minutes. More complex and difficult questions sometimes take longer.

This is the equivalent of turning around to your 2 or 3 colleagues who are sitting near to you and saying "hey, how do you create a C# continue statement in Ruby?" except you're saying it to 1,000 compatriots on Stack Overflow.

I'm very impressed.

TIPS:

  1. When asking your question be precise.
  2. Ask a question that has a definite answer that will help you move on to the next problem when answered.
  3. Give (as brief as possible) some background to your problem if relevant. Your language (don't assume that everyone codes in C#), OS, platform.
  4. Return to the question and mark one as correct - if appropriate and also vote up any other answers that were useful.
  5. Thank the people that answered your questions.

Wednesday, September 17, 2008

From power on to a working system

I've just built myself a new computer. It has 8GB of RAM, a fast processor and plenty of fast disk space and is running Server 2008 Enterprise. What I'm doing here is recording how long it takes from power on to windows loading to the sign-on screen. Because the system is new and fresh this time should currently be the shortest time that the computer will ever take to perform this task.

I intend to come back to this post and add more times in the months (years) to come and see how much the system slows time as I add bagage to it.

17 Sep 2008 - power to windows: 30 seconds; windows to logon: 40 seconds (Checked build of Server 2008 - later uninstalled)

On new installation of retail version of Server 2008:

18 Sep 2008 - power to windows: 30 seconds; windows to logon: 27 seconds

Installation failed for component Microsoft .NET Framework 2.0SP1

I'm trying to install .NET 3.5 SP1 onto Server 2008 Enterprise and I'm getting this error:

Microsoft .NET Framework 2.0SP1 (x64) (CBS): [2] Error: Installation failed for component Microsoft .NET Framework 2.0SP1 (x64) (CBS). MSI returned error code 1

On inspection of the folders it appears that .NET 3.0 is already installed C:/Windows/Microsoft.NET/Framework/ here. Mystery still not solved...

Tuesday, September 16, 2008

String Contains From Array with Extension Method

Using LINQ, I wanted to find all lines in a file that didn't have any of the strings in an array of "exclude" strings that I had. This is the function that I came up with to handle that case once I'd read in the lines from the file.

        static string[] NotInSecondArray(string[] first, string[] exclude)
        {
            return first.Where(a => !a.Contains(exclude)).ToArray();
        }

However, the string Contains function doesn't take an array so you need to add something like this:

    public static class MyExtensions
    {
        public static bool Contains(this String str, string[] inArray)
        {
            foreach (string s in inArray)
            {
                if (str.Contains(s))
                {
                    return true;
                }
            }
            return false;
        }
    }

Time Estimates

When someone asks me how long it will take me to do something my brain immediately gives me the best case scenario. If I'm being realistic I double that because of all the unforseens that make it longer.

Last Saturday I went to Fry's Electronics with Rob and bought all the parts for a new computer. My estimate to put this computer together was about a week using Sunday and the evenings over the next week. I was going to take my time and make sure that this first time assembly was done correctly and that I didn't break anything.

Rob being the generous genuis that he is came over on Sunday morning and before lunchtime the machine was running and I was installing an OS. This is probably the only multi-hour project that I've estimated that came in so far ahead of the best case scenario. However, this wouldn't of been the case if I'd done it by myself.

Thanks for all your help Rob.

Thursday, September 11, 2008

System.IO.Packaging

I'm experimenting with the Open XML Format SDK 1.0 and to get to the System.IO.Packaging namespace I needed to add a reference to the WindowsBase assembly. I would never have guessed that the System.IO.Packaging namespace was in there and will probably forget in a short while so I'm leaving myself this note here. 

More notes:

The WordProcessingDocument class is in the DocumentFormat.OpenXml.Packaging namespace in the DocumentFormat.OpenXml assembly.

Wednesday, September 10, 2008

AZGroups Forward/Back Button History and jQuery

 Two very good talks this evening 9 Sep 2008 at AZGroups. Thanks to Rob Bagby for staying behind and keeping the conference room open for us.

Scott Cate talked about a new control in SP1 of ASP.NET 3.5, the server side of an Ajax Forward/Back Button history. Scott's code for this demo and many of his other demos can be downloaded from http://www.codeplex.com/ScottCateAjax/

The main snippets of wisdom that I took away from this talk were:

  • 2 new (I think that they're new) attributes to the <asp:ScriptManager> tag which EnableHistory (which you need to set to true to enable the history of the back and forward buttons) and EnableSecureHistoryState whch defaults to true and does not need to be set unless you want human readable text to be on the URL and hackable which may be the case for an intranet or other URL's that you would like to enable human hackability.
  • In your page's OnInit() event you need to wire up the ScriptManager's Navigate event handler where the correct page is set on a paged control when you revisit the page using the navigation buttons.
  • The grid's pageindexchanging and sorting events also need to be added as handlers which is where the history points are set.

So to summarize: Set history points while navigating the grid using the sorting or paging controls on the grid. Restore the grid to those history points in the ScriptManager1_Navigate event when using the back and forward buttons.

The link that's produced is a perma-link whether it's the encrypted one or the plain text link and will return you to the correct page and sort setting that the grid had.

Rob Richardson gave a good talk on jQuery. His blog post about this talk which he gave at the Desert Code Camp can be found at jQuery - LINQ to JavaScript. There's a link on that blog post to his slides that can be downloaded.

Snippets of wisdom:

 

Sunday, September 7, 2008

Google Chrome Recent Pages

Internet Explorer and Fire Fox have a drop down arrow next to the Back (one page) and Forward (one page) arrows on the top left corner of their browsers. When you click this drop down it will list the previous pages that you've visited this session (as opposed to your history which lists pages visited in previous session as well). On Google's Chrome there is no drop down arrow. To get this list on Chrome, click and hold down the back (or forward) arrow for 2 seconds and the list will appear. A carefully hidden feature.

Friday, September 5, 2008

Gravatar

I didn't even realize that this blog/CMS system (Graffiti) supports Gravatar. Thanks to Bill Brown for alerting me to this.

If you don't know what Gravatar is then in as few words as possible: You upload an avatar to the Gravatar site and it becomes associated with your email address. If you put your email address in the email field in a comment to a blog that supports Gravatar then the blog will link your image directly from Gravatar otherwise it retrieves a unique pattern from Gravatar for your email address.

I remember reading about this on Jeff Atwood's Coding Horror blog but didn't even realize that I had it on here until I saw Bill's face popup next to his comment.

Google Chrome already in third position

Three days after Google released the Chrome Browser I took a look at how it ranked on one of my sites by looking at the Google Analytics stats from 2 Sep 2008 to 4 Sep 2008. I was very surprised to see that it's already in position number 3 but it only just pipped Opera so that's not saying much. I'll do this exercise again at the end of the month and see how the position has changed...


Tuesday, September 2, 2008

Google Chrome 0x80040508

Google Chrome has just been released (Google Chrome) and I would love to install it but I'm getting the following error:

"Download error. The downloaded file failed verification. Error code = 0x80040508"

The 475KB bootstrap install ChromeSetup.exe downloads okay but when it runs it brings up the message "Downloading Google Chrome..." and then that message.

Looking forward to finding a solution for this...

Update: Thanks to Ricardo's comment, here's an alternate download for Chrome that might solve your problem.