Dot Net What Not Posts

This entry is part 6 of 6 in the series Mazes For Programmers

Having implemented Dijkstra’s algorithm, the next bit of fun was to use it to find paths through the maze. Although I had looked at his code in the book, I decided to have a go at writing my own method from scratch, rather than converting his code into C#. This is a better way to understand the algorithms, and saved me having to figure out some of the less obvious language Ruby features. The end result was actually very similar to his code, although I made use of Linq (yet again) to avoid a loop, making the code a little clearer… I called my method PathFrom, as you specify where you want to go from, and it gives you a path from there to the root of the Distances object. He called his path_to, presumably because it gives you a path to the specified cell from the root. I guess…

This entry is part 5 of 6 in the series Mazes For Programmers

The main part of Dijkstra’s algorithm is implemented in the Distances class. For the most part, my code didn’t look that much different from his. The main change was that I was able to use Linq to remove an if when traversing the frontier… I broke lines 6-8 into three to make it easier to read in this blog, but in the code, it’s just one line. Linq enabled me to avoid having to check if the next cell had already been linked. Adding the numbers to the text output was very simple, as I already added the facility to display cell contents (see part 2 of this series). The challenge was putting these numbers on the UI. This turned out to be much easier than I expected, and even worked first time, which surprised me! I added a method to the window’s code behind, passing in the distances collection…

This entry is part 3 of 6 in the series Mazes For Programmers

Part 3 in my ongoing series of how I implemented the code from Mazes For Programmers by Jamis Buck in C#.

The author rendered the mazes in graphical form using a Ruby library that allows you to create PNG images. This requires you to run the code, then open the saved image, then remember to close it before running the code again, otherwise you get a “File access denied” error, all of which seemed like hard work. As I work with WPF on a day-to-day basis, I decided to use that to render my mazes, as it was quicker and easier.

This post shows how I did it.

This entry is part 1 of 6 in the series Mazes For Programmers

Part 1 in my ongoing series of how I implemented the code from Mazes For Programmers by Jamis Buck in C#.

In this post, I waffle on about the book, why I decided to implement the code in C# rather than Ruby, and generally spend a fair bit of time not saying much. Pretty regular blog post for me!

Our tables (well, most of them, see below) have a primary key named ID, and we make the (foolish it seems, see below part II) assumption that if an entity has a zero ID, then it is new. I was trying to work out the cause of a bug today, whereby a new entity was being treated as if it already existed, and discovered that the problem was caused by there being a row in the database that had a zero ID. Hmm, bleah and other such words of exasperation. As it happened, the particular row in question was marked as (soft) deleted, so I just altered the code to exclude such entities (which it probably should have done in the first place) and all was well. Well, not quite. You see this got me wondering. How many other tables have a row with a zero ID. Obviously, any table…

I blogged a couple of months ago about how MailTrap had achieved precognition. Well, it seems that they aren’t the only ones to manage this. We use Freshdesk for our support ticket system, and they have done the same! Amazing what they can do with these new-fangled rubber-band-and-string-driven computer type things nowadays eh?

I’m not under any illusions that anyone actually reads this blog, I mainly use it as a place to keep my discoveries, as I have a lousy memory, and would never be able to find them otherwise! A case in point was a data query I was asked to do this afternoon. A project’s database includes a table of users, and a table of countries, with a joining table to specify which users are responsible for which countries (this is a many-to-many relationship for reasons that are not relevant to this post). The client wanted a spreadsheet where each row contained one country. This sounded similar in structure to a query I did some time ago, where I discovered an overload of the Linq SelectMany method that I had never used before. Sadly, I had not blogged about it, so couldn’t find the notes. Not making that mistake again, so…

With a couple of recent projects, I have been using Azure DevOps instead of my usual SVN for source control. This uses Git, and whilst the mind migration to Git has been generally painless, there have been a couple of points that keep tripping me up. One of these is convincing Git that the .gitignore file has changed. When you start a new project in Visual Studio, and use Team Explorer to connect to Azure DevOps, it automatically adds everything to Git, including the bin and obj folders. You generally don’t want to put these under source control. No problem, crack up the .gitignore file and add the following lines… Visual Studio sometimes creates this for you, but even if it does, you still need to modify manually if you add a new project, as it doesn’t seem to do that for you. So, you confidently hit the refresh button…