Monday, August 11, 2008

Rube Goldberg Machine

I regularly hear Scott Hanselman refer to a Rube Goldberg Machine on his Hansel Minutes podcast and once you hear something repeated enough times you need to look it up. From wikipedia: A Rube Goldberg machine is a deliberately over-engineered apparatus that performs a very simple task in very indirect and convoluted fashion.

Now I understand why he often compares a software project to a Rube Goldberg Machine.

Phoenix Startup Weekend 17-19 October 2008

The first Phoenix Startup Weekend will be 17-19 October 2008. It looks intense (54 hours work over a weekend) but also very interesting. I've marked this on my calendar but haven't booked yet. I'm very keen on doing this although I'm guessing that I'll be shattered by the time Monday comes around and will need to go back to work to have a break.

Friday, August 8, 2008

C# boxing and unboxing

In my quest to become a C# expert I've decided that I should be able to accurately and unambiguously define each and every C# term and keyword. As such I'm going to try and create a post about each one in my own (and quoted) words to act as my own reference to this language.

Boxing and Unboxing

From the documentation: Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object.

My understanding is that the Object class internally has a boolean HasValue property which if false means that this object has a "value" of null. If it's true then a value has been assigned. I also assume that there is a Type property which represents the type of object that has been stored (such as Int32) and also an area of memory for the object itself which represents the size of the object presumably obtained from the sizeof() operator.

Stuffing a value into an Object is called boxing and this is done by means of a cast:

Int32 i = 1;
Object o = (object) i;

Retrieving the value into a strongly typed type is called unboxing and this is also done using a cast:

i = (Int32) o;

Notes

Comments welcome...

Tuesday, August 5, 2008

Copy data from local table to remote database table

I need to do this every now and then and as usual forget the syntax or what I did last time to do this. I need to copy some of the data in a table to an identically structured table on another (different) database running on another Server. I do this from SQL Server Management Studio (SSMS) 2005.

  1. Using Server Objects > Linked Servers I link the remote server to my local server. (You could also connect to remote server 1 and link to remote server 2 and do this between 2 remote servers.)
  2. If the target table has an Identity key I usually disable this by setting it to no and then after the copy I set it back to yes.
  3. The syntax to copy the data is:
    insert into [255.255.255.255].dbname.dbo.tableName
    select * from dbname.dbo.tableName where ColID=[some condition]

If the "local" DB is a remote server then precede that DB name with the IP address in square brackets as well.

Another way to do the data transfer is to specify the columns after the first tableName (in parenthesis) and instead of the * (without parenthesis) and omit the identity column and let SQL Server generate that value for you if you don't need to copy it. This is the syntax:

insert into [255.255.255.255].dbname.dbo.tableName (col1, col2, col3) select col1,col2,col3 from dbname.dbo.tableName where ColID=[some condition]

Friday, August 1, 2008

type or namespace name 'ProfileCommon' could not be found

I recently hit this compile error while converting a Visual Studio web site project to a VS2008 Web App project: The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)

Turns out that Web Applications don't support the auto generation of the ProfileCommon object like web site projects do. To get this to work install this VS addin and then add it to the build process as described here.

Sunday, July 27, 2008

7z Zip and Transfer Speed Comparison

I regularly backup my databases and transfer them from the server to a local machine. My strategy is to use the 7-Zip compression utility to compress the database first and then transfer it. A smaller file will obviously transfer faster and locally I'm going to zip it anyway to save space if I'm not using it.

Today I had a situation where I was going to use the DB once I'd transfered it so it was a matter of zipping, transferring, and then unzipping. While I watched the file zip I was surprised at how long it was taking to zip and wondered if I was gaining or losing by doing the zip-transfer-unzip steps rather than just do the transfer. So I measured what I was doing.

The file size unzipped is 47Mb and zipped is 6Mb. The transfer rate is around 12 MBS (Cox Cable).

Method 1: zip - transfer - unzip:
zip: 95 seconds
transfer: 27 seconds
unzip: 3 seconds
Total: 125 seconds

Method 2: transfer
transfer: 192 seconds

Contrary to what I thought, the zip-transfer-unzip method is about 35% faster. This would obviously scale to better performance if your connection speed is slower.

Something else that you should consider is being a good net-citizen and use less bandwidth than you need to which fits in with the results of this experiment. In fact, I think if we were charged (even partially) on the bandwidth we use instead of paying a fixed amount for an unlimited amount it would have a great impact on the web's availability.