Saturday, August 27, 2011

Food for a Hurricane

Hurricane Irene passed yesterday, bringing periodic rain, which was nice. Others will get it worse as it goes north. Cooking was needed and frozen chicken breasts were awaiting their fate, so the base was decided upon. Now, what to do to them? We had a tub of Ricotta Cheese in the fridge that we hadn't opened, and spinach, so I decided to stuff the breasts and serve them on rice.

1 lb ricotta cheese1/2 lb spinach leaves, lightly chopped
3 tsp chopped garlic1/2 onion, chopped
4 frozen chicken breasts (thick ones)1 pack of Wasa crispbread
2-4 bell peppers (depending on your taste), chopped1 bottle dryish white wine
1 lb pack of baconcocktail sticks
2 tsp dried thyme1 cup grated Parmesan cheese

  1. Start thawing the chicken, but intercept the process before it's completely finished, so that you can hold the breasts on edge without them flopping all over the place. Cut through the breasts parallel to the flat sides in order to "butterfly" them, so they will fold back like the cover of a book.
  2. Put some olive oil in a casserole (mine is from IKEA) large enough to take all four breasts and put on to medium heat. Add the garlic and about 1/4 of the onion and fry gently until the onion is soft.
  3. Raise the heat to medium-high, add the spinach, cover, and start stirring. Keep doing this until the leaves all turn dark green, are liberally covered with the garlic pieces, and are well wilted. Take it all out and let it cool off.
  4. In a bowl, mix the Ricotta, Parmesan, Thyme, and some salt and pepper (use a fork and be rough about it!!!)
  5. Add the cheese mix to the spinach mix and mix the two together well.
  6. One-by-one, lay down the breasts, put as much mix as you think they will hold onto them, fold them gently back together, and wrap them with rashers of bacon (probably 2 or 3 per breast. Secure with cocktail sticks.
  7. Spread the remaining cheese/spinach mix on pieces of crispbread to serve as nibbles.
  8. Put some olive oil into your casserole, bring it back to medium heat, and add the rest of the onion. Put a lid on and cook for a few minutes.
  9. Bring the heat to high and gently add the chicken breasts. It should take about 2 minutes for a side to brown, so brown each side.
  10. Once the chickens are browned, pour in the bottle of wine and add the peppers.
  11. Replace the lid and cook on medium for about 40 mins

I served it over basmati rice.
It has to be good hurricane food, 'cos we've blue skies and puffy white clouds today!

Wednesday, August 10, 2011

Making Mistakes - T-SQL Tuesday 021

SQL Tuesday Wednesday
I'm a database developer and sometimes a DBA, as you'll probably have realised, despite the amount of food and yarn that appears on this blog! Like all developers, I've made mistakes. Like all honest developers, I try my best to admit them, learn from them, and move towards being a better developer.

A better consultant than I (or, at least, one better recognised as such!), Adam Machanic, has posted a challenge to those of us in the SQL Server community who claim to be honest. You can see it by clicking on the caption of the logo on the right (I can't make the logo itself a link, as it is really a link to the page itself!).

The challenge is to publish a blog  post today (Aug 10th, 2011) talking about the bad code we've written. The aim is to provide people with examples of what not to do.

null values
One new thing you learn when you start out with databases is the concept of "I don't know". Rather like the famous statement "there are things that we know we don't know, and there are things that we don't know we don't know" implies, these unknowns have to be treated with care. One learns to use tri-valued logic (True, False, null (or "I dunno!"), for example). One also learns that, because of nulls, there are sometimes queries where the sums don't always add up as you might expect. Here's an example.

You have a table to report from. You've made it by pulling data from tables supplied by colleagues from their parts of the system. One of the fields defines the type of an item - let's say possible values are Computer, Printer, Router, and Unknown. As this is just a temporary table you're got in memory to organise the data for reporting from, you've not bothered with any referential integrity ...

Computer        2706
Printer          522
Router            47
Unknown          174
--------        ----
Total           3449

So you create your report and all looks good, until you see that the sum of the items that you've produced doesn't match the total sum - in fact, it's 551 too small. The real error is not in the query here that outputs from a sproc for an SSRS report: it's in the underlying assumptions!

select Type, count(Type) as 'Quantity'
from @taReport
where Type is not null
group by Type
order by Type
The programmer didn't realise that sometimes the Type might be unknown, so added the where Type is not null clause quite reasonably to avoid the report row saying that there were zero entries with type "NULL" (and, anyway, that always showed a zero!).

Adding this line just before the select statement would convert the null values into Unknowns, which is really what they are!

update @taReport set Type = 'Unknown' where Type is null

The Unknowns number goes to 725 and the total to 4000, which is the correct total number of objects!

Moral of the Story: A database contains a representation of the real world. It isn't a complete representation, to be sure, but so far as it goes, it must be accurate and complete. In this case the programmer made an assumption about the data quality that wasn't warranted.

Obsolete Code
When one works with a database with some history, such as when one is hired into a company with an already-functioning system, it behooves one to enquire into the history of the system. In one project I was investigating the reasons behind the terrible performance of some queries. One reason that I found was the use of functions in the where clauses of these queries - a well-known bad practice. Investigating further, I found that the functions (there were two or three only, used in a number of places) were very simple, and easily replaced with an existing native function in SQL Server 2000.

It was only after I had tracked down and fixed these function calls that I had a chance to learn more about the system history. It had originally been written in Access only, and these functions didn't exist so had to be written by hand! When the database part of the system was moved to SQL Server the code was re-written, apparently without any concern for whether any pieces were actually necessary!

Moral: Think about what you're doing! you may be creating something totally unnecessarily!


Saturday, August 06, 2011

A Colour Nook!!

The wonderful AG, the Keeper of the Books, allowed me to get a new eReader a couple of weeks ago to replace the Pocket PC (picture, right, from Wikipedia) I've had since about 2001. Don't get me wrong, now: the HP Jornada 568 has lasted a very long time for any piece of electronics, was relatively easy to program, has a nice clear screen for reading (a little small, I'll admit), and, recently, has been frequently the object of great curiosity from many people, asking if that was a prototype for a new Apple machine. To be honest, a piece of electronics that lasts 10 years of fairly continuous use definitely gets my respect.

Anyhow, it's coming to the end of its life, with the batteries starting to lose their ability to hold a decent charge and the beast as a whole becoming prone to testy reboots, so I finally decided that a new reader was needed. The problem was, as many have found, one of choice. Many people never moved to an eReader until Amazon introduced the Kindle, so their choice was easy, as they had no history of books to bring forward. I, on the other hand, have around 200 books in a variety of formats - .LIT, .EPB, .PDF, .CHM, .ePub, etc. - that I would really rather not buy all over again.

So, I looked around and found that the Nook Color is really a kind of mini-tablet, running Android 2.2. You could get an emulation on a PC in 2010, so I started playing with it there back then. I also started looking for ways of converting my eBooks (very few of which are Secure, or locked, luckily). I found a program called calibre, billing itself as an eBook manager program, that runs on Linux and Windows, and which will convert a number of formats into ePub, which is the Nook's "native" or preferred format.

Anyhow, I got my new toy a couple of weeks ago, and a few extras that I, for one, really consider necessary. These include a cover, of course, but one that can, as you can see, be used as a stand to hold the Nook at a convenient reading angle.

The next extra, equally important in the short term, but essential for the long term, is a supply of film screen covers to protect the capacitative screen from damage.

Finally, as I have used the small HP for some ten years and am totally accustomed to using a stylus to work the on-screen keyboard, a stylus. The one you see to the left is a rooCase, and comes in the form of a foam tip to an otherwise rather attractive ball-point.

So, it was a few days of play to explore the Nook, get used to expanding and shrinking the screen (annoying, that - web sites used to be written to self-adjust in the days of the old HP!). Anyway, it's certainly got some nice features. One thing I could do with is a set of smaller keys (as I'm not using my fat fingertips) with some extras, rather than having to continually hit an alt key to switch to another keyboard full of numbers and symbols. The text presentation is, on the whole, very good and at least the equal of that in the Microsoft Reader software on the Jornada, and the idea of swiping ones fingers on the screen to turn pages very quickly becomes natural. Then, after getting well stuck in to The Art of SQL, it was time to convert books from other formats. I can only say that calibre worked without any fuss or problems. It uses all the cpu power it can get its fingers on, and definitely isn't the fastest program on the planet, but the output (ePub in my case) is just as good as the originals that I fed it.  

Do I have any grouses about the Nook Color? Well, one or two. I'd like to be able to see the list of books that I have to select from in the equivalent of Windows Explorer's Detail view, instead of icons with only a quarter of the title in view. Of course, that may be possible - just a feature that I haven't found yet.
The other thing that surprised me to start with was the sheer weight of the thing! 654 grammes (with the cover that I bought), 1.44 pounds. Compared to the HP, which only weighed a few ounces, the Nook is a huge monster, and definitely takes getting used to - when reading in bed, for example.

Overall opinion: very favourable. I'd definitely recommend it to people with existing eBooks: ePub and PDF are readable immediately. I'm very happy, and can see the end of paper book purchases in this house looming closer.