Friday, 10 May 2013

Don’t be a hippogriff


You can be an eagle or a horse, or even a mouse, just don’t be a hippogriff.

I’ve signed up for a slew of online services in the last year or so and I’ve noticed a trend. Whatever the industry, be it development tools or services, social media ego stroking or anything else, companies seem to be getting really good at getting that first message out; they are almost universally great at sending out that first lifeline.

But then.

I’ve had a few e-mails from such companies asking me to get in touch, to suggest times I might be free for a chat, to solicit my feedback. And I think, ‘great, here’s an eagle’. But then no-one replies to my e-mail and I’m left disgruntled and perturbed. I thought I was dealing with an eagle but actually it’s part-horse. It’s a hippogriff!

If you’re going to ask me for my opinion have the decency to respond, even if it’s just to say thanks. And please, oh please, do not send me another e-mail asking for my input. That will just make me mad.

By all means, be a mouse, keep to yourself, that’s cool by me but if you want to start like an eagle, finish like an eagle, otherwise you’ll lose some of your audience because no-one expects a hippogriff.

Monday, 11 February 2013

Generic Javascript Proxy object for Firebase

If you've come across the same issue as me then sometimes you want to act like you have an object but you really only have its Firebase Reference. This is some fairly generic code for proxying the object.
var FirebaseProxy = function(classToProxy, firebaseRef) {
  var key,
      self = this;
      
  self.proxy = classToProxy;
  self.firebaseRef = firebaseRef;
 
  for (key in self.proxy.prototype) {
    if (typeof self.proxy.prototype[key] === 'function') {
      // don't over-write our own properties
      if (key === "proxy" || key === "firebaseRef") {
        console.warning("Name clash in FirebaseProxy. Key = " + key);
        continue;        
      }
      
      (function(inner_key) {
        self[inner_key] = function () {
          var args = arguments;
          
          self.firebaseRef.once('value', function(data) {
            var proxiedInstance = new self.proxy();
            
            if (typeof proxiedInstance.init === 'function') {
              proxiedInstance.init(self.firebaseRef, data.val());
            }
            
            proxiedInstance[inner_key].apply(proxiedInstance, args);
          });
        }
          
      })(key);        
    }
  }
};