harriyott.com

Saturday, April 26, 2008

Dell has a screw loose

A friend of mine has a new computer, her very first, and she asked me to set it up for her. I plugged everything in, switched it on, and got a black screen with some hardwareish words on it. It looked like it hadn't booted properly, so I wondered if something had come adrift in transit.

As I tilted the computer ready to open it, there was a gentle "clonk" noise from within. Once I'd opened the case, I saw that the hard drive was connected by only one of its two cables, hence the boot failure. I also saw that the hard drive wasn't attached to anything, and was completely out of its bay and resting on the motherboard.

This was rather surprising, as it should have been screwed into the case. I checked inside the case, but there were no screws rattling around. Not that they could have come off, as the screw-holes in the bay were covered by the side of the case. No, the screws were quite simply never there in the first place. All 4 of them.

Fortunately, my friend's mum had given her a really old Dell (Pentium III old), which was unused in a cupboard and about to go to the tip. I opened it up, and eventually found 4 screws that fitted the hard drive. I attached the hard drive into the new PC, connected the cables and it all works fine.

The question remains though, how on earth can Dell fail on something so basic? Not being into hardware, I don't know whether a minimum-wage worker forgot to screw it in, or the robot's screw pot was empty, but either way, I would have expected better from Dell.

[Tags: ]

Wednesday, April 23, 2008

Geek Dinner with Mike Hadlow

Many thanks to Mike Hadlow, who gave an excellent presentation with code samples about inversion of control containers tonight. A link to the source code for the examples will appear on his blog soon.

Good to meet a few new people too, and catch up with various people I haven't seen for a while.

Friday, April 18, 2008

Working in Uckfield

Despite my enthusiasm for co-werking in Brighton, I have a problem. I live in Uckfield. Not that it's a problem in general; I love being near the country-side, being able to afford a house, and seeing someone I know every time I go into town. Uckfield is a small town, and contrasts greatly with Brighton.

Brighton has free wi-fi along the seafront, and in lots of cafés, bars and restaurants. Brighton has lots of web agencies, software companies, financial institutions and a thriving tech community.

Uckfield is somewhat different. There are very few tech companies in Uckfield. Apart from one or two geek dinners that I organised a while back, there is no tech community in Uckfield. Just like with clothes shopping, you'd have to go to Brighton for that. I've tried working in various catering establishments in Uckfield, but they're not that geared up for it.

Here's a quick run down on what Uckfield has to offer the mobile worker:

  • Vespa. The only place in Uckfield with free wi-fi. Despite this, I've been there only once. MTV was on quite loud, playing music I didn't like. It closes at 4pm, which means I had to find somewhere else to go. The coffee was fine, but I didn't feel that comfortable there.
  • The Coffee House. Opposite Vespa, but not near enough to filch their wi-fi. I've met Heath, the guy in charge, only twice, but already he feels like a friend. Very friendly and welcoming. There aren't many tables, and the chairs are rather uncomfortable for working at though.
  • Costa. The nicest interior by far, and I like the coffee. I asked about wi-fi, and they said they're always asked, but apparently the owner isn't that bothered about it. They might put it in and charge for it one day. I did manage to connect to someone else's unsecured network sitting in the front of the shop though.
  • Luna. Being a restaurant, it's open after the cafés close, so I'll head there if I'm working late. I'm always made to feel welcome, although it is disconcerting sitting near couples out for a romantic meal (I'm sure they're less than delighted too). Although it advertises wi-fi on the sandwich board outside, it hasn't been working for yonks.


There are a few other places to try, but they look even less promising than these. Even though it takes an hour to get to Brighton in rush hour, it's still a good alternative. Clearly there's no mention of co-working in Uckfield (although I can use a window-less room in our church office), so I'm hoping that The Source will be a good option when it opens soon.

Shared Office Space

For the last 3 months or so, I've been working from home, and I've loved it. The flexibility, the commute, and the better family life are huge advantages, but the biggest disadvantage, for me anyway, is the loss of office life. I'm working in my spare room, which is small, contains a bed, an open wardrobe and a small table and chair. It needs painting, and the sun shines in mercilessly, so I have to close the curtains. Some days I don't leave the house, and other days I may not see my family until the afternoon. After a couple of months, the novelty started wearing off, and despite the advantages, I was feeling lonely.

As I'm now getting into twitter, I twittered my loneliness, for no other reason than I fancied telling anyone who would listen. I was surprised when @richardvahrman replied, generously offering me a desk in his office. I spent the next day in a lovely office in Hove overlooking the sea, and had a very productive time. There were 5 of us working in the office, and nobody working for the same company (the others rent desk space from Richard). It seemed like good old office life again, with long periods of companionable, busy silence, interspersed with the occasional techy discussion or general banter.

I was also invited to The Werks, also in Hove, so I went along a week or so later. The Werks is just brilliant. It's a co-working office, where people turn up and work. (Generally it seems to be people like me who work with laptops, rather than people who work with pneumatic drills.) I turned up quite early, and I was the only one there, so I just plugged my laptop in, connected to the wi-fi and got to work. Before long, a couple more people turned up, some who I knew from various Brighton geek events, and some strangers. We all sat round the same table, busying away, with the occasional chat, and sharing advice when appropriate. Again, a really productive environment, as it felt like being at work, as opposed to being at home. I've been back once since, and it was just as good.

There are a few different ways of doing it, which are priced accordingly. Occasional use (couple of times a month) is free (with contributions welcome), 2-3 days a week costs £60p/m, which seems very reasonable. So let's say that's 12 days a month, that makes it a fiver per day. An excellent alternative to renting an office. It's possible to rent a fixed desk and move in too, so there's a good mix of people there.

Thursday, March 27, 2008

Sussex Geek Dinner

After a break of 9 months (with the exception of the joint Christmas geek dinner with the girls), I'm glad to say that I've arranged another Sussex geek dinner.

This time, Mike Hadlow will be speaking on "Alternative Architectures: Inversion of Control". In Mike's words:

"I'm going to talk about how to write software, specifically .NET, as a collection of components using a design pattern called 'inversion of control'. It'll include a little bit about why it's good to do this and I'll also show you an eCommerce web site built with these techniques."


It's on 23rd April 2008 at 8pm, at the Black Horse, Church St, Brighton, and you can sign up on upcoming.org.

For a couple of years, I used a subdomain of geekdinner.co.uk to arrange the geek dinners, but the server crashed, and it isn't back up again yet. After initial concern, I decided to use existing social networks to publicise events, so there's now a Facebook group, a LinkedIn group, an upcoming.org group and a Google groups group. Hopefully that should cover everyone.

Wednesday, February 27, 2008

Pulling data from Excel

I spent much of today pulling data from Excel to put into SQL Server tables. The data was pretty well formatted, but each row of spreadsheet data traverses many database tables.

I saved the spreadsheet to CSV, and then used my trusty friend, the world's simplest code generator (javascript edition), to generate SQL statements from the many rows of CSV which I pasted into SQL Manager, e.g.

INSERT INTO People (FirstName, LastName) VALUES ('$2', '$3')

Some of them became quite convoluted, as once I'd inserted rows into the People table, I had to look up the IDs for the link tables. Also, there were a couple of Irish names with apostrophes in them, so I used a regular expression to double them up:

~(:Wh)'~([,|:Wh]|\))

n.b. I think this is a Visual Studio style regex, as it seems a little different to what I vaguely remember (not that I do remember, that is).

Tip - using units of measure

When naming a variable or database column that is used to store a measure, include the units of measure in the name. For example, instead of calling a column Height, call it HeightInInches. This prevents misunderstandings in future maintenance.

Friday, February 22, 2008

Lines of code != running time

I've just realised I do a bizarre thing in my subconscious when I'm coding. Now I'm all .NET 3.5, I've been writing code like:

feeds.ForEach(f => ProcessFeed(f));

One line of code instead of the usual four (OK, so two lines were the curly brackets) to write a foreach loop.

Now the thing is, I've unwittingly felt like the code now runs faster because the method is shorter. Of course that isn't true, but having nicer, shorter, eleganter, maintainabler code feels like it should be more efficient too.

Friday, February 01, 2008

Microsoft to buy Yahoo!?

I've been using flickr, upcoming and del.icio.us since before they were bought by Yahoo, and I was a little nervous about them all joining my Yahoo profile. Am I going to have to sign into these with my Microsoft Live account now?

Monday, January 21, 2008

SQL CLR - System.InvalidOperationException: The context connection is already in use.

I'm now writing stored procedures in C#, on the SQL CLR, as I have some complex data mangling to do, which I've already solved in C# elsewhere. Instead of converting the code to a long T-SQL stored procedure, I decided to stick it in as is.

Anyway, I got an error message "System.InvalidOperationException: The context connection is already in use." when calling the stored procedure from a trigger. In the trigger, I defined a new connection, did some stuff and called the stored procedure:
using (SqlConnection cn = new SqlConnection("context connection=true"))
{
int stuffID = GetStuffIdFromDatabase(cn);
StoredProcedures.usp_GetMyStuff(stuffID);
}

and in the stored procedure, I ran an update statement:

SqlContext.Pipe.ExecuteAndSend(new SqlCommand("UPDATE Stuff SET [Description] = 'Updated from trigger' WHERE ID = " + stuffID));

I googled around for a while without much luck, but eventually realised that the SqlContext.Pipe.ExecuteAndSend must be creating its own connection. I moved the stored procedure call out of the using block, and it all worked fine.

n.b. I posted this for the benefit of other people who will, in future, google for the error message. If you are one of these people, I hope it helps you, because my regular readers have undoubtedly moved on by now...

Setting a column value to NULL in SQL Server Management Studio

If you've opened a table in SSMS, and you want to clear an existing value to NULL, click on the value, and press Ctrl+0 (zero).

Friday, January 18, 2008

First adventures with DLinq

Hurrah! I get to use DLinq, therefore making me a DLinquent.

[n.b. I googled for "dlinquent dlinq" to see if anyone else has thought of that pun before, and there were no results, which means I thought of it first, hence I am officially witty. Others have used the term dlinquent, but in a different context, thus they cannot justifiably diminish my wittiness. If anyone else tries to pass off "DLinquent" as their own, please refer them to this blog post. Thanks.]

OK, here goes. Let me select a couple of hundred rows from a table and do something with them:

var musicians = from t in DB.Musicians
select t

foreach (Musician musician in musicians)
{
// Do a thing ...
}

Cool. Now lets do some other stuff:

foreach (Musician musician in musicians)
{
foreach (Album album in musician.Albums)
{
// Do a thing ...
}
}

Wow. Even more cool. Actually, hang on, that took ages. Let's try that again with a stopwatch. Hmm. 4 seconds, and there are only 200 musicians, and the database is on the local machine.

Time for SQL profiler, and stepping through the code...

OK, so the select doesn't actually run the select against the database, it just defines it. The foreach runs a select statement. So does the next foreach. Back to the top foreach again. Yup, another select against the database. And another, and another, and, er, hang on, it's fetching data one row at a time. I think it would be quicker to get it all at the beginning, and do the stuff when it's all been fetched.

var musicians = from t in DB.Musicians
select t
Array<Musician> musiciansArray = musicians.ToArray();

foreach (Musician musician in musiciansArray)
{
foreach (Album album in musician.Albums)
{
// Do a thing ...
}
}

That's a bit faster. It's fetched all the musicians when it built the array. The albums are still being fetched one at a time though. [Please excuse me while I google...]

Aha! Right, try again.

DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith(m => m.Albums);
DB.LoadOptions = loadOptions;


var musicians = from t in DB.Musicians
select t
Array<Musician> musiciansArray = musicians.ToArray();

foreach (Musician musician in musiciansArray)
{
foreach (Album album in musician.Albums)
{
// Do a thing ...
}
}

Brilliant. Now the albums are loaded at the same time as the musicians, right up front. Down to two hundredths of a second.