Tuesday, September 21, 2010

My wife's blog

So, it's been a long time since I've done anything on this blog. I guess these things come and go, like most other things in life :) Anyway, in an attempt to help boost some traffic to my wife's blog, I'm linking to it from here, if you are interested in all kinds of great information about things to do instead. So go have a look at what that is all about!

Friday, January 9, 2009

Asus Eee PC 1000H


My amazing wife got me one of these cool new netbooks as a gift for our five year anniversary. This little wonder is amazingly portable, sports 1GB of RAM, 160GB HD, 3 USB ports, 802.11n WIFI, Bluetooth, and a 1024x600 widescreen display. A perfect companion for the road, and much more portable than my Dell XPS M1730 monster :^)

Read more about this great notebook here:
Installing the latest Windows 7 Beta 1 went very well on this netbook. All drivers, except the network drivers were installed. You can install the wired and wireless network drivers by using the support CD. The trick is to run the setup on the support CD in Windows XP SP2 compatibility mode. After doing that, you'll have no issues installing the network drivers. Note, that I could not get TrendMicro Internet Security 2009 to work on this setup. I recommend trying AVG instead.

Sunday, December 28, 2008

The joy of discovering new music

A couple of months ago, I came to an important realization. Many of my favorite bands and artists have become my favorites, because of the guitar. This is especially true for many of my favorite songs. "Fragile" by Sting, "Private Investigations" by Dire Straits, most everything by Mike Oldfield, and the list goes on and on.

I believe I've had this thought for many years, the thought of discovering music, that was all about the guitar, the acoustic guitar. Every time that I've tried to find some artists, that do pure guitar music, I've failed. But not this time. With a little help of some cool new websites, I got on track to find a truly amazing duo, Strunz & Farah.

I initially tried to google spanish guitarists, but the Flamenco genre was not quite what I was looking for. Pandora.com to the rescue. I added the artists that I've found, and hit play. The first few songs got a thumbs down, but slowly, I was on my way to find Strunz & Farah, two truly amazing musicians. You can read more about them here:


I fell in love with their music instantly, and the first thought was, wow, it would be really cool to go to a concert with these guys. Are they still active? They have been together for some 30 years. Luck was on my side, and I found a venue close to home, which was perfect. My wife and I enjoyed the concert tremendously. Admittedly, me more than her, but it was an amazing display of how you can be in supreme control of a guitar, and produce beautiful music.

If they come back, I'm going to go see them again.

Wednesday, December 3, 2008

Speeding up your INSERT's with SqlBulkCopy

With version 2.0 of .NET, we got access to a new class in System.Data.SqlClient called SqlBulkCopy. This class will greatly improve your performance when doing mass inserts into your database.

Using SqlBulkCopy instead of regular business objects doing inserts in a loop, reduced the time to insert about 120K rows from 18 minutes to 3 minutes.

Most examples you find googling SqlBulkCopy will show you an example of how to use the class copying from one table to another. I needed an example of how to assemble my own source data into a DataTable, and then copy that to a new Sql table using SqlBulkCopy. So, here goes.

First, we need an instance of the SqlBulkCopy class. In this example, we're passing along a connection string, and the option to keep the identity of the Id column, we'll be setting up in our source data table:
SqlBulkCopy sbc = new SqlBulkCopy();
We also need the DataTable to use as our source for the copy:
DataTable newTable = new DataTable("MySourceTable");
Once you're done adding rows to your newTable, you can submit the the entire table contents to the server with this statement:
sbc.WriteToServer(newTable);
That's it! In some cases you need to use the SqlBulkCopyMapping class to map columns from your data source, to columns in your target table. There's lots of good documentation on that on a google search.

Thursday, November 6, 2008

C# Refactoring with Design Patterns, Singleton

Design patterns have been around for a very long time. As a matter of fact, I found an MSDN article dating back to 2001, mentioning the Singleton, Strategy, Decorator, Composite and State design patterns.

Why don’t we start looking into refactoring with the Singleton design pattern. As you probably know, the Singleton pattern is about offering a single, global point of access to a class, that has only one instance.

One thing I usually do for every application that I work on, is to create a configuration class, that retrieves all of the .config settings, and in some cases, also retrieves configuration settings for the application from a back-end SQL database.

Up until learning about Singletons, I passed the configuration class on to other classes that needed it. Instead, the Singleton design pattern offers a much more elegant approach. Let’s look at my configuration example, without using the Singleton pattern:

public class Config
{
public Config()
{
ConfigSetting1 =
ConfigurationManager.AppSettings[“Setting1”];
}

public string ConfigSetting1 { get; private set; };
}
Now, this is pretty straightforward. When you instantiate the Config class, you’ll get access to the properties that got fetched for you, from the .config file, and/or from other sources. Then I would normally pass my config instance along to the constructor of other classes and so forth. This can be completely avoided with the Singleton design pattern. The idea is, that since my Config class will only exist once in memory, I can simply let my other worker classes access the static singleton config class directly.

Here is the basic approach to create a singleton class in C#:
public sealed class Config
{
// Static constructer.
static Config()
{
}

// This will trigger the private constructor of this class.
private static readonly Config _Config = new Config();
    // On first access, the static constructor will fire, in
// turn triggering the private constructor.
public static Config Instance
{
get { return _Config; }
}

// Prevents a default instance of the Config class from being created.
private Config()
{
// Do your work here...
}
}
The beauty of this approach is that it is thread-safe, something that is extremely important for this design pattern. For a much more detailed explanation of this, along with alternate approaches, I urge you to have a look at this very good article by Jon Skeet:

Implementing the Singleton Patterin in C#
http://www.yoda.arachsys.com/csharp/singleton.html

Wednesday, November 5, 2008

SysFader/AutoComplete: iexplore.exe - Application Error

For some time at work, I had this really weird problem, in that I couldn't open any links to Office documents from wtihin Internet Explorer. A google search revealed a lot of fixes involving disabling page transitions in IE, or adjusting cache sizes etc. All of them didn't do the trick for me, until I came across this link on Jeff Widmer's blog:

http://weblogs.asp.net/jeffwids/archive/2007/03/12/internet-explorer-and-office-documents-sysfader-iexplore-exe-application-error.aspx

Basically, the issue is on a box that has had Office 2003 and Office 2007 installed, and the beautiful fix is to rename the

OWSSUPP.DLL file in the C:\Program Files\Microsoft Office\Office12 folder.

Lets not discuss how elegant that solution is, but give our minds some peace by accepting that the problem is now gone :-)

Update 11/11/2008 - Turns out, that simply renaming the OWSSUPP.DLL file doesn't fix the issue. Apparently, there is a compatiblity issue with the Office 2007 version of this file. The solution is to copy the one from your Office11 folder. So, rename your OWSSUPP.DLL in the Office12 folder, copy the one from you Office11 folder, and register it. To register the DLL, open a command prompt by running the cmd executable, and navigate to your Office12 folder (see above) and issue this command "regsvr32 owssupp.dll". This will give you an error message, but the registration still was successful. Test it by opening an office document on a SharePoint site.

Hope this helps.

Tuesday, November 4, 2008

Regular Expression Cheat Sheets

Speaking of putting useful things on your (cubicle) wall at work. Today, I realized I needed to lookup some regular expression syntax, and remembered at one time having a really useful cheat sheet up on the wall.

So, setting out to find one, I came across these excellent sites:

Added Bytes:
http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/

RegExLib.com:
http://regexlib.com/CheatSheet.aspx

OpenCompany.org:
http://opencompany.org/download/regex-cheatsheet.pdf