Posts

And now for something completely different

I use remote desktop almost every day. However it has the annoying habit of keeping idle connections open in a zombie state so when you try to logon to a server you get the dreaded max number of connections has been reached error. To bypass this you need to run the remote desktop app from the command line with some special switches. So to do this simply use this command from the command line prompt: mstsc /console /admin /v:<server>

Convert string to base64 string

A while back I came across the need to convert regular string text into a base64 string. .Net makes this fairly easy to do. I created a public static class and added two public static methods to encode/decode strings. Now they don't have to be static or public but I tend to make helper/utility classes that way. All of the classes being used are in the System and System.Text namespaces. /// <summary> /// Encodes the string to Base64. /// </summary> /// <param name="valueToEndcode">The value to endcode.</param> /// <returns>A base64 encoded string.</returns> public static string EncodeStringToBase64( string valueToEndcode ) { // encode the string into ascii byte array byte[] toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes( valueToEndcode ); // use the byte array to encode to a base64 string string returnValue = Convert.ToBase64String( toEncodeAsBytes ); // drop back the new encoded string value return returnValue; } /...

Validating a Guid in C#

Oftentimes you find a need to validate if a string is a valid Guid or not. Luckily for us .net offers some excellent regular expression tools. I've found the best way to do this is to place a small static function in a helper class that validates a string passed in using a regular expression. All regular expression stuff is location in the using System.Text.RegularExpressions namespace. So in some class simply call use the following code: /// <summary> /// Determines whether the specified string is GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns> /// <c>true</c> if the specified string is GUID; otherwise, <c>false</c>. /// </returns> public static bool IsGuid( String guid ) { if( guid != null ) { return Regex.IsMatch( guid, @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$" ); } return fals...

First post of the new year

Happy new year to everyone! I hope this year brings everyone great health, wealth, and the best possible in everything you strive towards. Normally I post a lot of code to this blog but sometimes I have interesting non code info I like to share. Today is one of those posts. I read a lot of code sites and decided to share the ones I love to read the most with you. The Old New Thing This is my favorite blog an d is run by Raymond Chan of Microsoft. He has a lot of really interesting posts about programming, technology, science, and some great insights into Microsoft and why certain things are the way they are. It's not all code all the time but it's fun to read. Joel on Software Joel on Software, another excellent blog that I think focuses more on the high level aspects of programming and less on the low level in the weeds day to day programming kind of tasks. Still tons of cool and great info to read. Coding Horror Coding Horror I think is more a general programming blog ...

I have joined the OSS community

Besides working a professional software engineer I have a few side projects that I have created. You can see them over at www.jrl-software.com. Recently I decided I would take the plunge and take an application I've created and license it under the GPL v3.0. I'm still not entirely sure how I feel about this whole GPL thing so this has been an interesting expirement for me. I like being able to download source code for many popular programs I use. But at the same time it's disconcerting to know people can see exactly what I've done and written in my code as well. So if anyone wants to look at the project it's hosted on sourceforge and you can see it using the link below. Filesort OSS It will be interesting to see what life if any takes off from this project. I have railed against OSS in the past but I think that was more of a rant against PHP than something against OSS in general.

Learning how to debug

There are a lot of smart programmers coming out of college. You learn a lot of great and important things about computer science and how to be a good programmer. However one thing I think more junior developers (and even us senior) ones can always learn more about is debugging. What debugging you say? Everyone knows how to debug man, just set a break point and step through the code. Well believe it or not but a time will come when you don't have complete access or control over the code you're relying on. So debugging is a lot more then just being able stop code execution. Because of this I recommend everyone read the following blog: Using winDBG winDBG is a debugging tool that allows you to debug windows based applications (even .net ones). It's quite powerful and while not easy to use can allow you to track down exceptions/crashes/hangs in your code. I'm just starting with it myself and the learning curve is huge but I have already learned several new technique...

MFC reading and writing from the registry

After spending some time today coding in MFC I realized I had to store some values in the registry. I haven't done this in a while and didn't find much help on the net so I am adding my experience to hopefully help some folks out. It used to be you had to use the Get/Write private profile string methods in the Win32 API. MFC has made that easier with the CSettingsStore class. This is a new class in the MFC feature pack. So to use it you have to have service pack 1 installed for visual studio 2008. To use the class all you have to do is create an instance of that class and you can use it's methods to read,write,create, and pretty much do whatever you want in the registry. So let's look at some code that does some stuff in the registry. We're going to create/open a new key and write some values to it // let's create a new pointer to our registry class // Sadly the MSDN MFC documentation seems to be wrong // on the constructor logic. // This will put...