Author Robert

I’m Moving!

After much thought, I’ve decided to move this blog to creatingcode.com.

The new feed location is here – Creating Code

Here are the following changes I am going to make when switching over to Creating Code

  • Create more programming centric articles.
  • Focus on quality over quantity
  • Keep the same light-hearted attitude towards the delivery of the content, while taking the production of the content more seriously.

There are a couple of articles I’ve written for Cube Antics that I think have some real promise, but are lacking in either depth…

Starting a WordPress Theme From Scratch

So much of web design today is duplicating effort. This is especially true for creating WordPress themes because of the extra blog code that needs to be hooked into each theme.

I started a new project on GitHub called MinWP that will contain all of the source files necessary to get started with a new WordPress theme. The goal is to create a fully functional 2-column theme with absolutely no additional design elements added to it.

Now, to create a new WordPress theme,…

Using .NET to Monitor a Directory for Changes

.NET’s FileSystemWatcher class can soothe the paranoid control freak in all of us by monitoring a specified folder for different types of file system changes.

The Code

using System;
using System.Text;
using System.IO;

namespace FolderWatcher {
  class Watcher {
    static void Main(string[] args) {
      FileSystemWatcher watcher = new FileSystemWatcher(@"D:\test");
      watcher.IncludeSubdirectories = true;
      watcher.Filter = "";
      watcher.Renamed += new RenamedEventHandler(renamed);
      watcher.Deleted += new FileSystemEventHandler(changed);
      watcher.Changed += new FileSystemEventHandler(changed);
      watcher.Created += new FileSystemEventHandler(changed);
      watcher.EnableRaisingEvents = true;

      Console.ReadKey();
   }

    private static void renamed(object sender, RenamedEventArgs…

301 Redirect with ASP .NET

When redirecting URL’s it is very important not to lose all of your search engine mojo. The best way to do this, is by using a 301 redirect which notifies the requester of a permanent URL move.

<script runat="server">
private void Page_Load(object sender, System.EventArgs e) {
  Response.Status = "301 Moved Permanently";
  Response.AddHeader("Location","http://www.newdomain.com");
}
</script>

Should you have to redirect a URL to a new location, using a status 301 redirect is the safest way to do it.

Creating a Fluid Two-Column Layout With a Single Fixed Width Column

Ever wonder if you can create a fluid layout with a fixed witdh column? Well, you can!

layout.html

<html>
  <head>
    <title>Fixed Left Column</title>
    <link rel="stylesheet" href="test.css" type="text/css" />
  </head>
  <body>
    <div>Left div</div>
    <div>Right div</div>
  </body>
</html>

test.css

.left {
	width: 300px;
	float: left;
	background-color: #CCCCCC;
}
.right {
	margin-left: 300px;
}

There are very few times in life that you can have things both ways, this is one of them.

Using #if and [Conditional()] to Keep Debug Code Under Control

The #if directive provides a perfect way to ensure your released executable doesn’t execute any code that was only intended for debug mode.

#if (<symbol>) will return true whenever the symbol being checked has been defined by default, or manually using #define.

#if DEBUG
	//Perform debug only code
#else
	//Release-level code
#endif

Remember, this is only one application of #if, you can use it any time you need to check to see if a symbol has been defined.

You can also use the [Conditional("<symbol>")] attribute…

Sending Email in ASP .NET

I can’t think of too many websites that don’t send automated email. Unfortunately, for ASP .NET programmers, there are several incorrect code snippets online which try to explain how to send email.

Here’s the code I use on the contact form for my personal website which does the trick quite nicely.

/* using System.Net.Mail; */
MailMessage newMail = new MailMessage();
newMail.To.Add(toAddress);
newMail.Subject = subject;
newMail.Body = body;
newMail.From = new MailAddress(fromAddress, name);
newMail.IsBodyHtml = true;

SmtpClient SmtpSender = new SmtpClient();
SmtpSender.Port = 25;…

Worrying About Small Details Can Kill Your Project

It’s amazing how seemingly insignificant things can completely derail a software project. I was working on my first project of the year -a simple online Regex tool- and abruptly stopped work when I realized that the name I had chosen wasn’t good enough. I then proceeded to obsess off and on for days until I came around full-circle and decided to stick with what I originally came up with.

Not only was this a horrible waste of time, it completely killed…

PDF Download: Why’s (poignant) Guide to Ruby

This is one of the best (and most entertaining) introductions to a programming language that I have ever read. If you are even remotely interested in learning Ruby, _why’s guide is a great place to start.

And, wherever you are _why, thanks for such a fantastic read.

PDF download: Why’s (poignant) Guide to Ruby

Honing Your Programming Skills with Project Euler

There’s nothing quite like that feeling you get when you finally figure out the solution to a problem. Whether it is solving a complex math equation, beating your friend at Tic-Tac-Toe, or even successfully programming the DVR for the first time. As programmers, we are constantly looking for new problems to solve and interesting ways to improve our programming skills.

Project Euler is a programming challenge site that hosts (currently) 272 programming problems of varying difficulty. Users can log in, attempt…