Tag Archives: key

The Broken Key in the Bedroom Lock My Life 09 OCT 2013

Our main bedroom’s en-suite bathroom is really, really small. It’s a narrow little rectangle that fits in a shower on the one side, a toilet on the other, and a little basin squished in between the two. This has the effect that if I’m forced to make use of this bathroom, I prefer to lock the bedroom door and leave the bathroom doors open – so that I don’t have to feel trapped in a little claustrophobic space.

Yesterday was work from home day, and with Chantelle out and about and Olga happily cleaning around the house, my bathroom break time forced me into using the bedroom en-suite bathroom for privacy’s sake. Having happily completed my business and about to exit the bedroom, I turned the key in the lock and was surprised by the fact that turning the key presented no give at all. More annoying than surprising was the then subsequent lifting up of the key to examine the key shaft, with the key head still firmly lodged in the lock itself.


country mews bedroom broken key

The broken key. It really is quite ridiculous just how easy this rubbish key snapped. (Seems to be made out of some sort of pewter perhaps?)

After Chantelle finished chuckling at me via the phone, I managed to convince Olga to come to the bedroom door where I instructed her to extract my toolbox from the office and bring it around the house to the bedroom window, where she was forced to then hand me tools through the burglar bars (the toolbox doesn’t fit through the bars in case you’re wondering).

Tools in hand, I then took off the handle and casing and proceeded to extract the key head using nothing other than two small jewel screwdrivers. Feeling very proud of myself, I screwed the handle back on, grabbed the spare key (which is kept on the same bunch as the main bedroom key) and let myself out.

Right, so straight to the Q20 then to ensure this doesn’t happen again thanks to a stiff lock, but more important than that, I don’t think I’m going to be locking that door any more anyway. So hopefully people knock.

Though to be fair, they’ll probably learn pretty quickly should the first couple of days not go so well!

The lock in question - now due for a violent meeting with a can of Q20 lubricant!

The lock in question – now due for a violent meeting with a can of Q20 lubricant!

PHP: Identify the Offset of a Specific Array Element CodeUnit 04 DEC 2012

To learn the offset or array key for a specific array element in a given array turns out to be fairly easy, thanks to the extra search parameter that the always useful array_keys (return all the keys or a subset of the keys of an array) function offers us.

From the manual description: array array_keys ( array $input [, mixed $search_value = NULL [, bool $strict = false ]] ) – array_keys() returns the keys, numeric and string, from the input array. If the optional search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the input are returned.

Knowing this, we can now find exactly where a specific element sits by simply entering a search value when calling the array_keys function, which in practice would look something like this:

$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));
    [0] => 0
    [1] => 3
    [2] => 4

The above example shows us that the array element “blue” appears at offset 0, 3 and 4 in the source array.


Related Link: http://www.php.net/manual/en/function.array-keys.php

The Broken Key in the Lock My Life 09 APR 2012

I haven’t had to do any DIY for quite some time now, meaning that my tools have been quietly lying packed away, alone in a dark and dingy toolbox that they call home.

Well, that is until the other day, when I got a SMS from Chantelle informing me that I would have to enter the house via the sliding door after work, thus setting off the alarm in the process. The reason? Her front door key had broken off in the lock as she headed out to work earlier in the day.

Fun stuff.

Anyway, I did get home, gain access to the house via the sliding door, somehow avoid setting off the alarm, and after the whole Jessica bedtime routine was done and dusted, grabbed my toolbox and got to work on what proved quite an elusive, and stubborn key fragment!

By this stage it was already dark outside, and I can just imagine what the neighbours must have been thinking, what with this shadowy figure outside, bent over the front door and fiddling with the lock with all manner of tools and picks.

Eventually Chantelle arrived home from her late shift and jumped in to help, and after much jiggling, prodding and cursing, it was the eventual application of good old Q20 lubricant that saved the day, making things slippery enough that we could eventually work the broken part out of the lock mechanism and successfully eject it out of the door.

After removing the lock mechanism and giving it a good look over, I decided that it needed replacement due to the stiffness of the turning action, and so headed out the next morning to purchase a new lock for just under R100. However, on installing it, I noticed that the new lock didn’t quite fit properly thanks to an improperly bevelled lock slit in the frame, meaning that the following day I had to head back to hardware store to purchase a chisel for R50.

Anyway, with the lock slit properly chiselled out, the new lock slid in and out like a charm, marking the end of yet another successful DIY excursion.

Of course, this sweetness wasn’t long lasting, as on the disposal of the old replaced lock, I noticed that the day or two of soaking in Q20 had made the locking action as smooth as a baby’s bum, meaning that pretty much all the money I had just spent, could have been saved if only I had been a little more patient.


Accessing Values in Javascript JSON Objects with Keys containing Hyphens (Dashes) CodeUnit 12 AUG 2010

In Javascript, JSON objects (well, JS objects in general) have a great short hand little way of accessing values using the fullstop object notation.

In other words, using a JSON dataset looking like:


we could access the “status” value by simply entering:


However, if we tried the same thing with the “message-data” key, you will note that this will fall over syntactically straight away – all because of that silly hyphen (dash).

So the way around this?

Well you basically have to revert to the long notation format to get at the data associated with these keys, meaning that you would now need to do something like this:


And now you know.


SQL: Add a Unique Compound Key to an Existing MySQL Table CodeUnit 21 JUN 2010

A simple question for today: how does one go about preventing duplicate rows based on the value held by more than one column being inserted into an existing MySQL table?

Well the solution lies in the use of a unique compound key which is basically a way of specifing unique rows based on a value given by a combination of one or more columns.

So for example, if we said we wanted to prevent people sharing the same firstname, surname and title from being added to a persons table, we are in fact specifying a unique compound key to act upon the columns firstname, surname and title!

With this in mind, now adding this key constraint to a table is as simple as running:

ALTER TABLE people ADD UNIQUE KEY (firstname,surname,title)

You’ll note that running this SQL statement on a table containing data already breaking this new rule that we are imposing will fail, meaning that one will first manually have to remove all the offending data before running the ALTER statement again.

And that’s it, a pretty simple little tip for today’s CodeUnit SQL tutorial entry! :)

PHP: How to Sort Your Array but Keep Your Keys CodeUnit 06 APR 2010

PHP comes bundled with a range of nifty array sorting functions the simplest of which will simply take your array and sort it either alphabetically or numerically, acting on the array object itself rather than creating a new, sorted object.

But if you have an associative array, in other words an array with keys, running the sort() function might give you a little shock once it has finished executing – if you check out your array, you’ll notice all of your precious array keys have been completely wiped out, obviously not the greatest of lessons to be learned.

In order to get around this, PHP gives us the asort() function which sorts the values contained in an array accordingly, but at the same time retains all of the original value keys. Similarly, the arsort() function sorts the array in the reverse direction, once again saving the original keys.

(If however you wish to sort on the keys of an array, you can look towards ksort() which literally sorts an array according to its keys and not the values it contains!)

You’ll note that while all these sort functions accept a first parameter which is the actual array to sort, they also come with a secondary, optional parameter which allows you to set just how the array is to be sorted. The following sorting options are available to you: