Christmas 2015 with the Fosters

20151206_105450Four months ago James David Martin Foster was born. And he is even more awesome now than when he was born.

As I write this James only has a few sleeps (as James sleeps multiple times in a day I can’t put an exact number) until his first Christmas. James is pretty much unaware of what is going on as he is still too young but that doesn’t stop his parents enjoying the season.

He has lots of Christmas themed clothes which we have been enjoying taking pictures of him wearing. He makes a great looking elf I think.

James at ChristingleWe took James to his first Christingle service at St Michael le Belfrey at the start of December. A Christingle service is where you stick a candle and cocktail sticks into an orange. James loved it, he already loves looking at lights so loved looking into the light from the candle.

12309579_10153809916077792_2703731936729335666_oAnother Christmas activity we did this year as a family was to appear in a nativity. St Michael le Belfrey every Christmas hold a cafe to tell people the good news about Christmas and they have a nativity outside which includes donkeys. Don’t we make a great holy family. (Excuse the coffee cups but it was cold.)

Me and James’s mummy have gone a bit crazy with buying him presents, we have both got him lots of things to open on Christmas morning (or more likely mummy/daddy will do the opening)

James also has three Christmas days to look forward to, with different sides of the family each no doubt with him as the centre of attention.

Exciting times. Happy Christmas everyone, make yours as special as ours.

The Christmas count down with code

In December we count down the days to Christmas. People often have advent calendars filled with chocolates or even Lego.

But what about if you are a programmer, how can you count down the days till Christmas? What about if you had a daily Christmas themed coding challenge? Well is the answer.

Christmas coding challenges

Each day a new challenge is available. So far the challenges are related to Christmas and Santa delivering his presents. The challenge is split into two closely linked parts. You are given a randomly generated input and your need to give an answer using a short string or number.

The challenges are getting harder, with some completely defeating me, (not surprising with my limited programming knowledge). The challenges are language independent so you could try them in javascript or c#. I have been using Visual Studio and C# and my code is viewable on github.

So far I have completed Challenges 1 to 6 and also 10. Partly because I found challenge 7 very difficult but I am hoping to have another go at it.

While coding through these challenges I have done a fair amount of refactoring. I started off with a simple console app with most of my code in one method. As the number of challenges increased I started moving the code for each challenge into its own class, with methods and properties that were unique to the challenge. I also added a main menu so you can choose which challenge to run. Some of my code to answer the challenges takes some time to run so this was quite a time saver over running each challenge in order.

These challenges are very good at teaching me things about coding. I have got to think about data structures, what is the best way to store this information, classes and methods and return types, how to output data to the screen, how to input/import data.

Before I try and work on the next challenge lets have a look at the first challenge:

Santa is trying to deliver presents in a large apartment building, but he can’t find the right floor – the directions he got are a little confusing. He starts on the ground floor (floor 0) and then follows the instructions one character at a time.

An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means he should go down one floor.

This is a simple loop through a long string of ( and ) and keep track of the floor number you are on to calculate what floor Santa finishes on. The second part of the challenge asks at what point in your input string does santa reach the basement (floor -1)

Happy Christmas

I saw this tweet on twitter.

He’s making a database,
He’s filtering twice
SELECT * FROM customers WHERE behaviour = Nice
Santa Clause is Coming to town.

This started me thinking surely in a normalized database structure behaviour wouldn’t be stored in the customer table, so I propose the following change.

He’s making a database,
He’s filtering twice
SELECT * FROM customers WHERE EXISTS (select * from behaviour where behaviour.CustomerId = customers.Id and behaviour.Type = Nice)
Santa Clause is Coming to town.

Happy Christmas everyone, hope you all have restful holidays.