Archive for the “Techy Musings” Category


I think this is awesome. Starting tomorrow (Sunday 27th April - later today if you’re a New Zealander), the Museum of New Zealand Te Papa Tongarewa is going to be thawing and then dissecting a Collossal Squid. According to the BBC article on which I found this, the process will take days, and all of it will be streamed live.

The video streams are live now and I can see an empty thawing bath, a dissection table and some people walking around. I hope to catch them getting started tomorrow.

It would be great to see more engaging stuff like this from other museums and universities over the world. Science and nature encompass us; they’re not just things to be respectfully studied within the walls of a museum. In particular, the great but fairly static institutions in London would do a lot of good for themselves if they could offer something as fascinating as this.

Comments

I’ve started using Twitter.

Each bite-sized update which goes through the service is known as a tweet. How cutesy!

Are Twitter users called Twits?

Comments

I used the maps application on my iPhone today for a genuinely useful purpose for the first time - to find the nearest branch of a shop that my girlfriend and I were looking for.

After excitedly shouting, “ooh, let’s use my iPhone!”, I located the nearest store not more than fifty metres away from where I was standing and looked up, amazed, to see the shop we were looking for just down the road.

I still can’t help feeling that I was cheated out of my value for money.

Comments

NB: This post is not about the Prototype framework.

AJAX has caused something of a renaissance for JavaScript over the past couple of years, so I’m still learning (and relearning) a lot of things about it despite having started using it seven years ago. One thing I revisited today was adding a method to an existing JavaScript object as an elegant alternative to defining a procedural-style function.

JavaScript is object-oriented, which makes it elegant and powerful when manipulating the DOM, because objects in an OO language belong to one another just like elements of an HTML page belong to one another, i.e. in a hierarchical model.

JavaScript’s OO capabilities are, however, limited compared to other languages. You can’t take one object and use it as a basis for new one using extends.

You can, however, add your own home-made methods and properties to existing objects, including pre-made ones (such as String and Array). For example, you could add a function to the Array object to help you find out if an array contains a certain value.

Array.prototype.contains = function(value) {
 for (var i=0; i<this.length; i++) {
  if (this[i] == value) {
   return true;
  }
 }
 return false;
}

Now, any Array which you create has the contains function. It’s more elegant than writing a procedural function, e.g. contains(array, value), which is what I’ve become used to as a result of using the many useful inbuilt procedural functions in PHP.

Comments

When I first wrote “Ben’s Techy Musings” what I really meant was “Ben’s Techie Musings”, Techie being a (sort of) real noun meaning a person involved in tech(nology).

When I realised that “Techy” is apparently an American spelling variant of Tetchy (meaning irritable) my first instinct was to change the name. I decided to keep the name, however, since it describes me so well. I have a habit of being in a bad mood without realising it, particularly if I’m tired or hungry. I’m like a baby, really. My girlfriend would agree that it is dangerous to meet me (or even phone me) before I’ve had my first cup of tea of the day!

So, Techy it stays and although I’ve put a phonetic spelling of the word in the tagline, the double meaning still stands.

Comments

Today I’ve been working on a very long form which needs client-side validation (as well as server-side validation, of course) and tooltips for most of the fields. For users without JavaScript, the tooltips are all shown next to each field. When JavaScript is enabled, however, the tooltips are all hidden at onload and then appear when a field gains focus. When a field loses focus, its value is validated with JavaScript and if this fails, an error message is shown next to that field.

I started doing this the way I usually do events, by putting onfocus and onblur events in the HTML on each field. It worked, but there are so many fields and it became a pain to put this in every field. I find that lots of JavaScript often decreases the readability of HTML, too.

I thought, “there must be a way to use JavaScript itself to add these events to each field”. It turns out that there is:

fields = document.getElementsByTagName('input');
for (i=0; i<fields.length; i++) {
 fields[i].onfocus = function() { ... };
 fields[i].onblur = function() { ... };
}

Now the events code is unobtrusive in the HTML. Users without JavaScript don’t have to download the events code, the HTML is more readable and I need to do a lot less copying and pasting!

Comments

I’m finally using Apple Mail in work again after using the utterly crap Entourage 2004 for months. My favourite things about Apple Mail are:

  • Integration with Address Book
  • Opening attachments without a confirmation dialogue every time
  • Dragging-and-dropping attachments straight onto applications
  • The connection status window doesn’t open itself every time mail is received
  • Number of unread messages is displayed on dock icon
Things I don’t like about Apple Mail:
  • Horizontal, letterboxed layout is less efficient than a column layout on a widescreen monitor
Thankfully there is a plugin available to turn Mail’s interface into a column layout. (That one is for Leopard only; there’s something similar available which works with older versions of OS X.)

Comments