# Sunday, September 13, 2009
On meta.stackoverflow.com Joel announced a need for countdown application for the coming DevDays, as I am planing to attend one, I have decided to make one. Maybe I will watch my counter at the conference. ;)

It looks like:



Source code: PeterStegnarDevDaysCountdown.zip (198.51 KB)

I have used WPF, .NET 3.5. The speciality of this solution is custom Stackoverflow digits. :)

Short manual:
-you can find exe in "PeterStegnarDevDaysCountdown\WPF_StackoverflowCountDown\bin\Debug"
-start the app with the following parameters, for example: 0900 "DevDays begins in %s"
-just hit an "Esc" key to exit

Core functionalitiy is, of course, countdown:

            if (second != 0)
            {
                second--;
            }
            else
            {
                second = 59;
                if (minute != 0)
                {
                    minute--;
                }
                else
                {
                    minute = 59;
                    if (hour != 0)
                    {
                        hour--;
                    }
                    else
                    {
                        throw new ArgumentNullException("No valid time entry!");
                    }
                }
            }


What do you think?

posted on Sunday, September 13, 2009 12:00:59 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Wednesday, September 02, 2009
Today I have compiled a nice podcast MP3 CD with Stack Overflow podcasts from episode 38 to 57. Yeah I know is strange selection, but you have to start somewhere. :)

NerdCD is meant to be regular geek podcasts compilation. Which will contain mainly the following podcast sources:
Why NerdCD, anyway?

Well it is primary meant to be record to the CD (size of NerdCD is just under 700 MB) and to be listened in the car. Of course you can upload it on your favourite music player (iPod, mobile phone, you name it).

Where can I get I?

It will be distributable in a torrent form.

NerdCD1 torrent: NerdCD1.txt (12.97 KB) (Caution! Rename txt to torrent file extension - torrent extension is blocked on my server, sorry)

Needless to say, seed it! :)
posted on Wednesday, September 02, 2009 9:16:33 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Tuesday, September 01, 2009
I would like to point out the difference between (local) and localhost. Those special "addresses" are often used in connection strings.

There are common misconception that, those address are the same. This is not the case.

"... it depends on the provider you're using to connect. If you're using the SQL Server Native Client or the .NET Data Provider for .NET 2.0 the behavior is the same regardless of which name you use (localhost/(local)/or "."). These providers will first try to connect using Shared Memory, then try to connect using TCP/IP and then finally Named Pipes."

It is not advisable to use (local) for other providers, because of the ambiguity (you have 3 different ways to access the SQL server). It is better to explicitly define the connection type (typically TCP/IP), with localhost.

More info:
http://msdn.microsoft.com/en-us/library/ms187662.aspx
http://msdn.microsoft.com/en-us/library/ms191260.aspx
http://msdn.microsoft.com/en-us/library/ms189307.aspx

posted on Tuesday, September 01, 2009 5:54:42 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Monday, August 31, 2009
Sometimes you need a control over browser window behaviour, i.e. open a new one and close it, eventually.

This is really simple. All you need to write is one liner code.

To open an window:
window.open ("http://www.google.com","window"); 
Then you can close it by:
window.close();
In ASP.NET you have variety of ways to achieve browser window close. One example:
closeButton.Attributes.Add("onclick", "window.close();")
By this, close functionality is dynamic added to the control event.

Important: you can close a browser window with code which was open by the code.

However, this open/close window java script technique is more or less obsolete. If you need to display a special "window" to the user, you should use modal windows. ASP.NET AJAX have a nice control, called "ModalPopup".

posted on Monday, August 31, 2009 7:24:45 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Wednesday, August 26, 2009
How to get the file extension from string file name?

Well brute force approach would be something like that:

string fileExtension = args.FileName.Split('.').GetValue(args.FileName.Split('.').Length - 1).ToString();

Pretty ugly, in spite of one liner code.

Well it turns out that the framework has support for this functionality:

string fileExtension = System.IO.Path.GetExtension(fileName);

Much better, right?

It is good to remember that .NET Framework contain a lot of functionality that you would not think about at first place. That's why is good to check every time is something smells that it could be in .NET Framework. You may find it.

posted on Wednesday, August 26, 2009 4:43:41 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Tuesday, August 25, 2009

Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of "The Art of Unit Testing" (http://www.artofunittesting.com/), a leading tdd & unit testing book; he maintains a blog at http://iserializable.com (which amoung other things has critiqued tests written by Microsoft for asp.net MVC - check out the testreviews category) and has recently been on the Scott Hanselman podcast (http://bit.ly/psgYO) where he educated Scott on best practices in Unit Testing techniques. For a further insight into Roy's style, be sure to also check out Roy's talk at the recent Norwegian Developer's Conference (http://bit.ly/NuJVa). 

Full Details here: http://bbits.co.uk/tddmasterclass

bbits are holding a raffle for a free ticket for the event. To be eligible to win the ticket (worth £2395!) you MUST paste this text, including all links, into your blog and email Ian@bbits.co.uk with the url to the blog entry.  The draw will be made on September 1st and the winner informed by email and on bbits.co.uk/blog

posted on Tuesday, August 25, 2009 8:34:12 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Tuesday, August 11, 2009
A jQuery library quickly emerging really popular - and for a reason. I think it is one of the best JavaScript frameworks. You can do fancy stuff really fast and clean.

You can start a Getting Started with jQuery. On the jQuery homepage you can find a lot of nice tutorials. If you have not try jQuery, please do. You will be amazed.

Bassically what jQuery brings to web delopement is that it separates HTML and behaviour. Similarly what CSS brought: separation of presentation and HTML.

There are a great tool named Firebug, which really helps with web development. This tool surely demand a separate post. You can inspect a web page, play with CSS on the fly, debug, use a console ... Here it comes a jQuery. You can write a jQuery instruction right into the console, and it will be applied on the fly. Amazing. All you have to do is to "jQuerify" a web page.

Another great thing to know when you work with jQuery is what the selector will actually select. You can try a SelectorGadget tool which shows the most appropriate selector for the selected element(s). This tool is so great also because all you have to do to run it, just click a "link" when you are on the desired page to be check. Great!

More on Firebug and jQuery in the great video:

posted on Tuesday, August 11, 2009 7:20:20 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Saturday, August 08, 2009
I have implemented a very simple validation site. You just put an XML and XSD to it and it tells you if your XML document is valid. Simple.

Just vist XML Validation site and try your XML against XSD. Please notice that it is version 0.01 so I presume you know what that means. :)

When and if it will be updated is depended on the planet polarization.


Related:
http://blog.stegnar.com/2009/06/03/SimpleXMLValidationWithNET35.aspx

posted on Saturday, August 08, 2009 9:30:32 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Wednesday, July 08, 2009
A very nice thinking came by me from Rockford Lhotka. It is about future of OS. I quite agree with him. Soon we will have just thin client and everything will be in cloud.

http://www.lhotka.net/weblog/OSEvolution.aspx

Just think how many "cloud" things are you already using? A lot. Today is totally possible to have installed just a browser in you machine, and you can do (almost) everything.

posted on Wednesday, July 08, 2009 8:53:17 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Friday, June 12, 2009
I am looking for the clean, elegant and smart solution to remove namespaces from all XML elements. How would function to do that look like?

I have used StackOverflow. If you do not know this site, I can describe it as a really smart Q&A site, dedicated for programmers.

So I was searching for really great solution for removement of namespaces in XML. Based on one programmer answer I have created a solution which I really likes. You can clearly see, when you have to deal with tree data structure (which XML for sure is) recursion is simply the best approach to do anything with it:
private static XElement RemoveAllNamespaces(XElement xmlDocument)
{
    if (!xmlDocument.HasElements)
    {
        XElement xElement = new XElement(xmlDocument.Name.LocalName);
        xElement.Value = xmlDocument.Value;
        return xElement;
    }
    return new XElement(xmlDocument.Name.LocalName, 
xmlDocument.Elements().Select(el => RemoveAllNamespaces(el))); }
Do you likes? I love it. :)

I was totally convinced that exists some more smart .NET framework function, with which I could help. But I was wrong. The best .NET can do is something like this:
XmlDocument doc = new XmlDocument()
doc.Load(ms);
doc.DocumentElement.Attributes.RemoveAll();
All this function do, is to remove all attributes on root element only ... You could repeat this on every node with help of XPath, but since those selected nodes are immutable, this is little help.

posted on Friday, June 12, 2009 9:12:44 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback