Showing posts from 2012

Leading zeros in SQL

So at work today, I ran across a SQL stored procedure called 'fixLeadingZeros' that has the below implementation. It's actually much longer than this since it does it for several columns.... and some columns have longer values. In other words, if the field is supposed to have 8 digits, it has 8 statements.  I couldn't help but to feel a bit disgusted from it and had to share it. UPDATE [SomeTable] SET SomeColumn = '0' + [SomeColumn] WHERE len (SomeColumn) =4 UPDATE [SomeTable] SET SomeColumn = '00' + SomeColumn WHERE len (SomeColumn) =3 UPDATE [SomeTable] SET SomeColumn = '000' + SomeColumn WHERE len (SomeColumn) = 2 UPDATE [SomeTable] SET SomeColumn = '0000' + SomeColumn WHERE len (SomeColumn) =1 UPDATE [Some] SET SomeColumn = '00000' WHERE SomeColumn ='' OR SomeColumn is null This could have been done a LOT easier.  If your goal is to update existing columns so that t

Properly disposing COM objects in your .NET code

Here at work, we are using a third party component where they provide a COM interface. We're using .NET code so we are using COM interop to use the COM object. Remember back in the VB6 days when you would set your objects to null when you're done with it? Well, so did someone else here, because that's what I saw. I'm going to show you an example using the Microsoft Excel Type Library. Here's some sample code that I wrote that will open up an Excel file and get the text value from a cell in the first worksheet.      using  System;      using  Microsoft.Office.Interop.Excel;      internal   class   Program     {         #region  Methods          private   static   void  Main( string [] args)         {              var  app =  new   Application ();              var  books = app.Workbooks;              var  book = books.Open( @"C:\Temp\doc.xlsx" );              var  sheets = book.Sheets;              var  sheet = sheets.Item[1]  as   Workshee

Debugging .NET Windows Service apps more easily

Here at work, I keep seeing a couple of my fellow developers struggle to debug their Windows Service apps that they're writing.  What they have to do is remove the service, install the new version of the service, start the service, then attach the debugger. If there's an error when the service first starts up, the workaround is to introduce a Thread.Sleep before it actually does anything, giving you enough time to attach the debugger. By default, you can't directly run the service from within Visual Studio. If you try, you get the following message: If you look at the code that actually starts the service, you'll see that it's not that different from a console app. By default, it looks something like this:      internal   static   class   Program     {          ///   <summary>          ///  The main entry point for the application.          ///   </summary>          private   static   void  Main()         {              ServiceBase [] Ser

Stepping out of my comfort zone, trying different languages and web frameworks.

For the longest time, I've been developing on the Microsoft technology stack, with MVC using C# for web application development, WCF for web services, MS SQL server for the database, and of course, Windows and IIS for the OS and web server. But I then started asking myself... is this the best way to develop? What are some of the other languages and web frameworks like?  Easier? Harder? I knew I didn't want to really mess around with PHP, just because I don't like how the code feels like spaghetti code of classic ASP.  Another reason for not going PHP is due to performance benchmarks. Here's a neat site that shows how programming languages compare in performance: I decided to try out the Python language, using the Django web framework thinking that it would perform fairly quickly due to the fact that it creates "compiled" files, but found that simple web pages r

Wikipedia goes dark in protest of SOPA, how to get around this

I admire Wikipedia for raising awareness to this issue, and if you found this blog through searching, then you already have been made aware. If there is something you absolutely must see on Wikipedia during the blackout period, here's how you can get around it. Drag the link below to your bookmarks bar. Show wikipedia content Load up the Wikipedia page you want to see. You'll probably be able to see it for a brief second until it's covered up by the SOPA information. Once you have the page up, click on the link that's on your book mark bar. Essentially, it just removes the SOPA overlay and then shows ALL hidden elements... even elements that are normally supposed to be hidden.  I didn't really feel like spending too much time getting it to work elegantly for only needing this for a day, but it certainly does the trick.

Learning new web frameworks

So in case you didn't already know, I'm a web developer and have been doing it for over 10 years now and still really love it.  It's always changing and there's always new things to learn and new challenges and the web is relevant to me and almost everybody else. The majority of my career has been around Microsoft based technologies such as ASP and Currently, I've adopted Microsoft's MVC framework and really love it.  It makes sense and is easy to use.  The razor template engine is really great too. However, I wanted to step out of my comfort zone and learn some new frameworks, see what they do differently or better, and allow me to experience new languages. I first started off dabbling in Python and using the Django framework.  The language is nice and I was pleased with the framework, but wasn't really impressed with the performance. Also, not a lot of major sites have adopted it so it doesn't seem to be gaining a lot of populari