December 2004 - Posts

Passphrase vs. Passwords

There have been a lot of postings the last few months talking about the topic of passphrases vs. passwords and I have finally got around to reading them.

The following articles are very interesting reading and I highly recommend you take a look at them:

Why you shouldn't be using passwords of any kind on your windows networks...
The Great Debates: Pass Phrases vs. Passwords. Part 1, 2, and 3 of 3.

After having read the above I have all but switched to passphrases. I think they are going to be a move in the right direction for me (at least until more biometric type authentication is put into place). 

Well I need to go come up with a few passphrases now.

Posted by puzzlehacker | with no comments

Generic version of string.Join

Have you ever had a list of something other than strings and wanted to combine the list in someway to get a single string? You could use string.Join if you could get your list into a string[] but that is not always so easy. Usually I end up writing my own join method.

Anyway I needed to do this earlier today and I decided to use the new C# 2.0 generics feature to write a generic version of the Join function. Here is the C# code and a sample use:

  1 // Default join that takes an IEnumerable list and just takes the ToString of each item
  2 public static string Join<T>(string separator, IEnumerable<T> list)
  3 {
  4   return Join<T>(separator, list, delegate(T o) { return o.ToString(); });
  5 }
  6 // Join that takes an IEnumerable list that uses a converter to convert the type to a string
  7 public static string Join<T>(string separator, IEnumerable<T> list, Converter<T, string> converter)
  8 {
  9   StringBuilder sb = new StringBuilder();
 10   foreach (T t in list)
 11   {
 12     if (sb.Length != 0) sb.Append(separator);
 13     sb.Append(converter(t));
 14   }
 15   return sb.ToString();
 16 }
 17 static void Main(string[] args)
 18 {
 19   List<int> list = new List<int>();
 20   list.AddRange(new int[] { 10, 20, 30, 40, 50 });
 21 
 22   // Just take the ToString of each integer in the list
 23   Console.WriteLine(Join(" ", list));
 24   // Use an anonymous method to convert each integer to its hex value
 25   Console.WriteLine(Join(" ", list, delegate(int i) { return i.ToString("X"); }));
 26 }

Output:
10 20 30 40 50
A 14 1E 28 32

Hopefully this will be a handy little example for someone on how to use generics and anonymous methods in C#.

Code Htmler

Code Htmler is a simple program that will translate plain text code into a colorized html version of the code. Currently there exist language definitions for C#, JScript, VB.Net and XML.

It uses regular expressions to match language structures, such as keywords and literals (strings, integer, real, etc.). The language definitions are stored in xml files and so languages can be customized or new languages can be created rather easily.

I wrote Code Htmler a long time ago with the some help from Shawn A Van Ness. I just recently recoded most of it so that I could use it for the syntax highlighting within PostXING. With the next release (coming soon I believe have to ask Chris for exact time) everyone will be able to use it to do syntax highlighting for their blog. I have been using it for the last few entries which have code samples, if you want a quick sample.

I have uploaded the source code up to my site http://puzzleware.net/codehtmler/ and up to Project Distributor http://projectdistributor.net/Projects/Project.aspx?projectId=37. At http://puzzleware.net/codehtmler/ you can actually play around with it and test it out on the web. So if you are interested feel free to have a look and let me know what you think.

Storing VS projects on a Network drive

I have a centralized file server where I store pretty much all of my data. When I got my file server I moved all my data to it including my Visual Studio projects. This was about a year ago. 

I figured I could easily map a network drive and load up the projects and work on them from there. However, it didn't work as smoothly as I would have liked it to. For what ever reason about 1/3rd of the time when I save a file (that is on my network drive) Visual Studio hangs anywhere from 10-45 seconds. As you could imagine this gets very annoying very quickly. Since then I gave up the idea of running my projects from my network drive.

Today I was updating an old project that was on my network drive and I figured it should be rather quick so I would try to run the project from the network drive. That was a mistake! Almost every time I saved or built my project I got the 10-45 second hang of Visual Studio. It was really quite frustrating.

I figured that someone else out there must have had the same problem before so I did my usually google research but I didn't come up with anything clean cut. I did however run across a newsgroup posting about a similar problem with Office and Visual Studio. That post pointed to MSDN's Configuring Opportunistic Locking in Windows knowledgebase article. I was so frustrated that I figured hey why not I will give it a try.

I set the registry keys on my file server and I figured the change would take place immediately because usually if it requires a restart the knowledgebase article would say that but this article didn't. After testing it I still had the problem, Grrrrr... I didn't really want to reboot my entire server so instead I just quickly restarted my Server service, hoping that this would fix the problem. Much to my delight it did fix the problem ;)

So anyways the moral of the story is if you want to run Visual Studio projects from a network drive but are having problems with Visual Studio hanging while saving files then you might want to consider setting the registry keys from the above knowledgebase article and remember to restart the server (at least the Server service).

I hope this saves someone else the pain of dealing with this problem.

More Posts