Posts

Showing posts from August, 2010

GUIDs

NOTE: There is a more complete article on eggheadcafe.com here .

Get File Length over http before you download it

This is one of those forum questions that you “think” you know the answer to, and then you’re proven wrong. User wants to download a file from a remote site but they do not want to proceed with the download if the file is larger than 10MB. Make sense, right? I said there was no way to do this without downloading the file. I was wrong. Here’s how he solved his own problem: static void Main(string[] args) { string completeUrl = "http://www.eggheadcafe.com/FileUpload/1145921998_ObjectDumper.zip"; WebClient obj = new WebClient(); Stream s = obj.OpenRead(completeUrl); Console.WriteLine( obj.ResponseHeaders["Content-Length"].ToString()); s.Close(); obj = null; Console.ReadLine(); } The above correctly reports the file size of 85,827 bytes without ever downloading the file! Somebody had a problem. Instead of giving up (or worse, taking my so-called “expert advice”) he thought  “outside the box” and found a solution. I call that outstanding! NOTE: At least one comm...

Don’t criticize – Be a Mentor

I tweeted this concept recently and got a very positive response. As developers, business owners, partners, and gurus of various breeds, we are constantly exposed to situations where things other people do just don’t seem to fit our personal paradigm. Sometimes, a natural reaction may be to put somebody down or make a sarcastic comment. Don’t do it. Environments like this create a situation where we can excel as developers, or we can turn them into a situation where we turn out to be a complete and total ass because of our behavior towards others. No matter what the situation is, you can catch more flies with honey than with vinegar. There is NEVER a situation where putting somebody down will further the effort – not in development, not in personal interactions, not in a group. Never . What you need to do is step back, hold your breath, and think. Then, hopefully, you can find the resources in your inner being to respond in a positive manner. The results, if you work on...

MongoDb NoRM MonoDevelop on Ubuntu Linux

  This weekend I spent some time setting up Ubuntu Desktop on my Oracle VirtualBox. I installed MonoDevelop, and MongoDb. I added an ASP.NET Web Application that uses the NoRM C# Driver, and after a little futzing (like changing the port on the MonoDevelop XPS web server) it built and ran great! Interestingly, it was a  Visual Studio 2010 solution, but MonoDevelop was able to open it anyway. All I had to do is remove some of the references that “didn’t belong”, and remove the targetFramework attribute from the web.config. Now that’s quite an accomplishment, since I am most definitely not a Linux guy. Kudos to the MonoDevelop guys. They’ve done a great job. And it just shows how portable MongoDb really is. Being able to build and run .NET applications and  even ASP.NET apps on Linux is a big plus.

LINQ THINK

The more I use LINQ, the more I run into legacy code that can easily be improved. The nice thing about LINQ is that it can make your code more elegant and easier to understand, as well as, in most cases, more efficient. Let’s take a simple  example. Here I’ve extracted some legacy code in the form of a method that tells you if a given string “Key” is present in a string array. First, the “OLD” way: //"OLD" way: static bool IsKeyInArray(string[] items, string key) { if (items == null) return false; if (items.Length < 1) return false; if (String.IsNullOrEmpty(key)) return false; foreach (string item in items) { if (item.Trim() == key) { return true; } } return false; } The obvious  thing to see here is that we have to iterate over the entire array. Now the new “LINQY” way: static bool IsKeyInArray2(string[] items, string key) { bool isInArray = false; if (items == null || items.Length <1 || String.IsNullOrEmpty( key)) return false; if (items.ToList().Contains(key...

Don’t Make Other Developers Test Your Code

Yep! I run into this all the time. Developers make changes and enhancements, and they think everything is fantastic. They push it up into source control, and go home for the night. But It’s not fantastic. They don’t have unit tests to prove their code. The next morning, the other developer(s) update the code, and it breaks. Then of course you get into the inevitable series of emails centering around “Hey – this doesn’t work!” Here’s the deal: If you make changes to source code, you better have tests in place to prove that it works, and have run them and seen that they work.  They don't "have to be" fancy unit tests (although that's preferable). They just have to prove that whatever you did works. Only then should you feel comfortable and confident that you can check in your code. Anything less is completely unacceptable. Please DO NOT make me test your code for you! Got it?

Lean up Windows 7 with Msconfig

Image
  Most people are blissfully unaware of all the absolute JUNK that gets run when Windows starts up, mostly due to registry entries installed by various programs, drivers, and what not. Much of this junk can be safely disabled. You can use Msconfig to do it. Here’s how: Hit the Windows Start button at the lower left side of your Taskbar. Click RUN, then enter “msconfig” and click OK. You’ll see four Tabs – the one you want is “Startup”. You can start disabling items by unchecking them. Some items will be automatically reinstalled on the next startup by windows or by necessary drivers. But you can disable a lot, and that means less memory usage and less resource-hogging. Here are the first two screens of mine:   You can see that I have most of it (from the first screen) and all of them (on the second screen) disabled, along with even more on the third screen (not shown). I could care less about Adobe Updater, Itunes, Zune and whatever. If I need to run Itun...