The Amazing Fifteen Minute Break

How many times have you been working away on a problem and not been able to solve it, then when you are commuting home or you stop for a snack, you find the answer jumps out at you? For me it is almost a given. Anytime I am having a hard time solving a problem, as soon I step away I the answer almost always arrives. So why is that so many times we find ourselves thinking that we can try that one last solution?

Identifing the Struggle

Even identifying that you are struggling with a problem can be challenging, never mind taking a break. But identifying the struggle is the key to staying productive. Once you become aware you can take action.

Many times it is from the help of a coding buddy that I am able to notice and take the much needed break. Other times it is the lack of forward progress. Sometime there is the gut feeling that the design isn’t quite right.

The Fifteen Minute Break

A simple walk around the building or a quick stretch can give you the fresh look at your problem. Fifteen minutes away from the problem allows the mind the break to perform its amazing process. It has worked for me more times than I can count. By walking away you get a different perspective on the problem that you couldn’t get when you were too deep in the weeds.

It is contradictory to think that a 15 minute break would make you more productive, especially when you are struggling to find the solution but I believe that in our industry it allows us to re-frame and be more creative.

How do you identity you are struggling with a problem? How do you take your 15 minutes break to refresh?

CSS Cube Animations

Last year while studying for my MCSD certification I came across a comprehensive post on CSS animation. Following along with the post, I created some spinning dice with the idea of turning the dice into some sort of game. I never finished building the game but spinning dice are fun enough to share:

Note: If you are on IE 10/11 you will only see one side. This is because IE does not support the preserve-3d property. But it works in the new Edge browser!

Runaway SQL Server Service Broker Activation Script

I have been experimenting with using the SQL Server Service Broker in my latest project. We had a long running SQL process that needed to be executed in the background and the Service Broker sounded like a good choice. I found some good articles on how to set this up and had success quickly. After some simple examples I tried the a more complex solution and set up an activation script. This is when the problems started.

Trials and Errors

I quickly found that error handling with with the Service Broker was not straight forward. After implementing some of the error handling I ran the process again but this time I had a bug in my error handling which caused an infinite loop in the activation script. This time when I ran the process it never returned…

The SQL Server log file grew and grew. We tried to restarting the server but when restarted the activation script just started off on an infinite loop again. We found the process id and tried to kill the process but got the error Only user processes can be killed. We tried dropping the activation procedure, the services and the queue. All to no avail.

Solution

We searched to the ends of google/bing but didn’t find a solution. Finally, in a last ditch effort, we remember that we enabled the Service Broker so we tried disabling it. It worked! We had finally killed the process that was running rogue with the following command:

ALTER DATABASE dbname SET DISABLE_BROKER;

It was brute force and luckily we were working in the development environment. I hope that this helps anyone with a runaway/rouge SQL Service Broker procedure. If there is another I would love to hear about it.

BigInteger Structure

Where do you turn to if you have an integer to that is to large for the primitives supplied by the .NET Framework? The BigInteger Structure! The BigInteger Structure in the System.Numerics namespace allows for any size signed integer to be represented.

Unlike the built in primitives such as int, byte, or long, the BigInteger structure does not have a lower or upper limit as represented through the MinValue and MaxValue properties on the primitives.

Like primitives, BigInteger is immutable but this comes with a caveat… You can get an OutOfMemoryException if you perform operations on the value that causes it to grow to large.

BigInteger has overloaded the standard mathematical operators so that you can do math just like any other primitive numeric type:

var x = new BigInteger(1);
var y = new BigInteger(200);

var z = x + y;

Assert.AreEqual(201, z);

Creating a number larger than any of the primitive types can be achieved in several ways:

// Using a byte array
var bytes = new byte[] {1, 2, 34, 45, 12, 54, 23, 42, 88, 45, 45, 45, 12};
var x = new BigInteger(bytes);

// Math on  a large number
var x = BigInteger.Multiply(Int32.MaxValue, 99999);

// Parsing a string
string googol = "1".PadRight(100, '0');
var x = BigInteger.Parse(googol);

More Information

You find out more about the BigInteger structure on the BigInteger MSDN page. Becuase the number is large and immutable, there is information on that page that tells you how to best handle performance problems you might run into.

This type will be available in the cross platform .NET Core Library.

Top Podcasts for March 2015

Whether I am driving to work or cleaning the dishes, podcasts are a great time to learn about a new topic or stay on top of the latest news. In no particular order, the following are the top episodes that stood out to me during the month of March.

What episodes did I miss that stood our for you? Leave a comment and I’ll be sure to check them out.