LINQ to SQL: The Most Powerful .NET Feature Since C# Attributes

Today I was reading Scott Guthrie’s blog post about the LINQ to SQL. IMHO LINQ looks like the best tool for .NET since C# Attributes! Since the .NET LINQ to SQL Designer will compile a database context for you we’ll never have to write stupid unit tests just to check if a query works (note: I said stupid unit tests). You’ll know the query works by the old programming myth “Well it must work, it compiled!”. Obviously we’ll still have to test some queries, but you know what I mean. You change a column name or drop a column from a table and sometimes you don’t know what parts of the application you broke until either your unit test fails, or if your unit test wasn’t explicit and specific enough, when your customer complains that the report isn’t working anymore.

Ever since Ruby on Rails came out and I actually learned it I lost my enchantment with ASP.NET – until now. Ruby on Rails still blows my mind with how easy it is to use, but I’m really happy that .NET now includes the AJAX framework and this excellent query tool.

The only thing I want from .NET now is Database Migrations in C# a la Ruby on Rails.

Apache URL Redirects Using .htaccess

I’ve redirected everything from http://eric.willcodeforcoffee.com to http://willcodeforcoffee.com using Apache redirects. It is pretty simple, I just created a .htaccess file in the web root for eric.willcodeforcoffee.com and added this one line:
RedirectMatch permanent ^/$ http://willcodeforcoffee.com/

Now it nicely, and permanently redirects everything from http://eric.willcodeforcoffee.com/.

There is one catch however: what about stuff in sub-folders, like http://eric.willcodeforcoffee.com/files/? The above redirect doesn’t handle that so I also added:
RedirectMatch permanent ^/* http://willcodeforcoffee.com/

It doesn’t redirect to the matching pages, but I don’t really want to do that anyways.

Moved Blog Here

Hi, I’m moving my blog here.  I did a manual install on eric.willcodeforcoffee.com and it hasn’t let me post in months, even with updates and stuff…  😛

So I’ve moved the blog to the top level.  We’ll see how that goes.

CakePHP: AJAX Callbacks Order

In CakePHP there is an AJAX helper based on the Prototype library. During an AJAX event, such as clicking a link generated by the AJAX helper ($ajax->link()) you can add javascript call-backs to the $options parameter. These are the callbacks, in the order they are called:

  1. before
  2. loaded
  3. interactive
  4. complete
  5. after
  6. loading

I was expecting a different order, such as loading to come before loaded, but this is how it is!

Also, if you’re updating the content of a <div> it will be updated between the Interactive and Complete steps.

On Time Management

This marks the end of the first day of the second week in the life of the Hoffsoft Consulting Services Corporation. Last week I incorporated and I also sent off my business license request. It’s been exciting, but time consuming.

I’ve been reading a book called Success God’s Way by Dr. Charles Stanley, one of my favourite podcast friendly preachers. The chapter I read yesterday was about the successful use of time, and I was really impressed. Probably one of the biggest problems I struggle with lately has been time management and the effective use of time. I have often felt very overwhelmed by the problems involving working, maintaining my house, managing my father’s estate, building a relationship with my wife, and maintaining relationships with friends – and also trying to fit in time to read books at the same time.

It hasn’t been really easy for me, and probably one of the biggest problems for me is that I didn’t set clear goals for my use of my time. While this book is obviously a book by a Christian author for a person setting God based goals, there is a chapter on time management that wasn’t entirely Bible based, and related some interesting stories from successful business men that Dr Stanley follows himself; at the end of every day he writes down a list of items he would like to accomplish the next day in order of priority and importance, then the next day he follows this list in accomplishing tasks and getting things done.

Probably the most brilliant part of this plan is actually planning the time on the night before. This might seem funny, but to me it makes the most sense! Even when I was working in an office I would spend a lot of time spinning my wheels doing things like getting coffee, checking emails and reading blogs first thing in the morning because I wouldn’t have a set goal for that day in front of me yet. Usually by about 10:30 (or my third cup of coffee) I would snap out of it and start planning my day and getting to work. That is a lot of wasted time in the morning! I’m not sure how bad it has been in the last two weeks, but after reading that chapter last night I’ve been really motivated to change!

In keeping with the tips I’ve learned from this book I’ve started using a new tool, called the GTDTiddlyWiki for managing my goals and for organizing my tasks. I’ve got a default list of Today’s Tasks (today I set it in the morning, but I reviewed and set Tasks for tomorrow at the end of the day) and also a list of Short (next 1-4 weeks), Medium (1-6 months), Long (6 months – 2 years) and Very Long Range Goals (2+ years).

My Short Term goals mostly relate to my current tasks and things I need to get done, Medium Term goals are things that are a little more vague like “Keeping up with ASP.NET developments” that will transform as new code is released, Long Term and Very Long Term goals are goals about my company (i.e. growth by number of employees and earnings) and writing a novel.

I wonder what the effect of reading these things will be on me? I’m excited to find out. I’m going to try to post to the blog a little more often, and this is definitely one of the things I will blog about.

A Warning to Skype Users

Just a warning to anyone else out there who uses Skype: Skype uses TCP Port 80 and Port 443 as alternatives for incoming calls!  This will prevent you from starting up IIS or Apache (which was happening to me).

To fix this issue open up Skype Options (Tools > Options in the Menu) and select the “Connection” tab. There you will find a checkbox marked “Use port 80 and 443 as alternatives for incoming connections”.  Uncheck that box and you should be okay.

CakePHP: Error 500 Too Many Redirects

Another error I ran into was this error:

Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'Limit InternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

It took a lot of looking, and I found out that it was an error in my .htaccess file. However, there are three major .htaccess files in a typical CakePHP application

  1. The Cake Folder .htaccess
  2. The App Folder .htaccess
  3. The Webroot Folder .htaccess

It’s hard to figure out which .htaccess file you have to edit, but my first guess was the webroot folder.

I have setup my directory structure using the alternative setup described later in the CakePHP manual:

  • webroot: This is in /var/www/testing (where testing is the virtual directory of my application (testing.blah.com)
  • app: This is in /home/eric/cake/testingapp
  • cake: This is in /home/eric/cake/cake_1.1.12.4205

The setup seemed to be working, and my normal front page appeared, but if I went to another controller (i.e. testing.blah.com/user/login) I would get the Error 500 message and the Apache error log file said I had done too many redirects in the application.

The solution is extremely easy, but it was very hard to find! But I found it on the IRC logs here: http://irc.cakephp.org/cakephp/viewlog/2007-01-11#2234 courtesy of poLK:

Edit the .htaccess file in webroot (for me that was in /var/html/testing/.htaccess) and add the line “RewriteBase /” to the file, so my .htaccess file now looks like this:

RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

It's a simple change, but took me about an hour or two of research, Google and Groups searching to figure out.

Case Sensitivity

I’ve been doing some work on a project based on the CakePHP (http://cakephp.org/) Framework. CakePHP is awesome, and a great alternative to Ruby on Rails.

When I was moving my project from my development box (Windows) to my testing box (Linux) I started getting weird “Missing Controller” errors. It turns out that the error I was having was because I named my files Main_Controller.php instead of main_controller.php like CakePHP was expecting.

It seems like a simple problem, but I spent almost two nights trying to fix that bug!  I had to dig into the framework code to resolve it.  Probably one of the best parts of the CakePHP framework is that the framework code is pretty light, and while its pretty complicated stuff its still really easy to dig down into it.