Monday, 31 March 2014

Blast from the past

I'm really not sure when this was taken but this is a picture of my Mum, Jess (the dog), Mimi (my Grandmother), Ben (my Brother) and me in the garden at Mimi and Jack's (my Grandfather) in Apperley Bridge on the outskirts of Bradford - sometime in the 70s I'm guessing. I'll try and geotag this post so that you can get a better idea of the exact location.

Using PHP to extract the JSON from a callback

This is of no benefit to anyone else but me as I get sick of having to re-invent the wheel every time I need to extract data from a callback - if it works for you then cool, if not then have a tinker and improve it. It's cobbled together from all sorts of different places and is a replacement for something I did before.

<?php
    $str = preg_replace("/\/\*[\s\S]*?\*\//", '',$str);
    $str = str_replace(PHP_EOL, '', $str);
    preg_match('/callback\(([^\)]*)\)/', $str, $matches);
    $str = $matches[1];
?>
EDIT

Just came across a situation where the JSON wasn't correctly formatted (i.e. the keys in key:value pairs wasn't enclosed with quotes). To correct this so that I could use PHPs json_decode I added these two lines:

<?php
$str = preg_replace('([a-zA-Z]+:)', '"$0":', $str);
$str = str_replace(':":', '":', $str);
?>

Sunday, 30 March 2014

NFA no more

From Friday to Saturday we moved Serendipity from her usual mooring on Stourbridge Common to Hartford Marina to facilitate her sale. She's been up for sale now for a while but we came to the conclusion that it'd be better for prospective buyers to have easy access in order to fall for her charms.

It's been so very difficult. Even walking to the boat from the footbridge along Riverside was hard. I've cycled along that stretch every day for about 15 years either taking sprogs to and from school or going to work or just sauntering around Cambridge shopping or meeting friends. Not sure I'll be doing that route again.

Once I got to the boat I said my goodbyes to a neighbour and hugged Sparkx. Then it was off on our way. We made good time and moored overnight at the Lazy Otter before continuing to Hartford past Earith and St. Ives. We did it very quickly but not quickly enough - I wanted to do it and move on.

So very many memories are in that boat, so much laughter and joy and so much sorrow latterly. I've been a bargee for over a decade and think that the lifestyle suited me right down to the ground (or water). I couldn't've afforded to live so close to my boys without being aboard and it's worked its way into my perceptions of myself to such a degree that it comes right after being a Father and Yorkshireman when I describe myself. That's an interesting game to play isn't? What words do you use to describe yourself and in what order do they come? Mine were:

  • Father
  • Yorkshireman
  • Bargee
  • Husband
  • Developer
  • Son
  • Nurse
  • Smoker
  • Beer Drinker
  • ...

...but the order changes depending upon who I'm with and where I am I guess - or what's happening around me.

Anyway, Serendipity is for sale. She really was a lucky accident for us and I hope that whoever buys her loves her as much as we did and has even half as much joy and none of the sorrow we've had.

I was going to document our trip like last time but am really finding it far to difficult to, spent much of the weekend feeling really rather sorry for myself :-(.

Monday, 24 March 2014

Self Defined Ethnicity in an array of json (sde.json)

I needed this today so wondered if anyone else does...? The Self Defined Ethnicity is a set of codes so that people can record their ethnicity. That's cool, but there's no entry for Yorkshireman... ;-)

var SDE = [
    {
        "code": "A1",
        "value": "Indian"
    },
    {
        "code": "A2",
        "value": "Pakistani"
    },
    {
        "code": "A3",
        "value": "Bangladeshi"
    },
    {
        "code": "A9",
        "value": "Any other Asian background"
    },
    {
        "code": "B1",
        "value": "Caribbean"
    },
    {
        "code": "B2",
        "value": "African"
    },
    {
        "code": "B9",
        "value": "Any other black background"
    },
    {
        "code": "E1",
        "value": "Eastern European"
    },
    {
        "code": "M1",
        "value": "White and Black Caribbean"
    },
    {
        "code": "M2",
        "value": "White and Black African"
    },
    {
        "code": "M3",
        "value": "White and Asian"
    },
    {
        "code": "M9",
        "value": "Any other mixed background"
    },
    {
        "code": "O1",
        "value": "Chinese"
    },
    {
        "code": "O9",
        "value": "Any other ethnic group"
    },
    {
        "code": "W1",
        "value": "British"
    },
    {
        "code": "W2",
        "value": "Irish"
    },
    {
        "code": "W9",
        "value": "Any other white black ground"
    },
    {
        "code": "NS",
        "value": "Not stated"
    }
];

Saturday, 22 March 2014

jQuery Validate email is from a specific domain

I needed to validate that an email address provided via a form was from a user associated with a specific domain, I'll not repeat the domain and the example code I've included uses gmail.com but I'm pretty sure you'll be able to adapt it for your own purposes... and hopefully improve it. I found a number of possible solutions and enjoyed this idea from sectrean over on stackoverflow using Regular Expressions.

This was brilliant in terms of validation that the email address is/was an email address but didn't fulfil my requirement to check the domain of the the email address and didn't offer any more than the built in email method in the jQuery validation plugin. Then I clocked that Jacob Lauritzen had had a crack and that his work had been continued by Erik Woods with a nice little Fiddle.

Thus, on the backs of these giants I wrote this additional method for the Validation plugin, it needs some work and I'm thinking it may well have to accept and array of domains some time soon so I'm gonna have to have to do a wee bit more work on it, perhaps using the parems optional variable to addMethod. If you can think of improvements please don't hesitate to let me know.

jQuery.validator.addMethod("requireGmailEmail", function(value, element) {
    var re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
    if (re.test(value)) {
        if (value.indexOf("@gmail.com", value.length - "@gmail.com".length) !== -1) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}, "Your email address is not valid.");

Thursday, 27 February 2014

Breaded Mushrooms

Apart from freezing Jerusalem Artichokes yesterday - while waiting for access token to expire (got that working... auto-refresh of SalesForce oauth credentials when there's been no activity for 3 hours and a request has been made!) I decided to use up the mushrooms we had in the fridge. I'm a bit odd when it comes to mushrooms as I can't stand the texture when they've been cooked in some ways so I did a wee search on Google and found this recipe: Breaded Mushrooms (the trial).

I baked a crust that we had in the freezer and crushed the resulting toast-like bread with some grated and dried parmigiana. Then I washed the mushroom, patted them dry, dipped them in self-raising flour (the only flour I could find in the cupboard), rolled them in beaten egg and then covered them all over in the breadcrumb stuff. About 10 minutes in the air-fryer with a shake half way through and they were done... and very nice too!

Wednesday, 26 February 2014

I won! I won! I won!

I've not won anything for ages, not since I won a tin of Mushy Peas at a pensioners raffle which I went to with my Nan when I were wee!

You can get your very own copy from Amazon: The Decapaphiliac: or love in the time of cappuccinos and read all about the author on Goodreads.

It's a brilliant read and I think I've bought it in every format so far... still, it's nice to win something!

In fact:

The DecapaphiliacThe Decapaphiliac by Alex Weinle
My rating: 5 of 5 stars

Not since I discovered an old collection of Tales of the Unexpected stories on my Grandad's bedside table have I enjoyed a short story collection as much as this one. Most especially as this collection didn't leave me feeling slightly seedy, steeped in the 1970's and full of ennui. Mr Weinle has a fine turn of phrase and a delicacy of style that left me feeling uplifted by all of his stories... even the slightly disturbing title story - which promised to be seedy but ended up leaving me feeling refreshed and hopeful - I think I'm slightly disappointed by not being more disgusted in all honesty.

I think The Disassociate was wonderful, especially as it held so very many resonances with my previous career as a psychiatric nurse and I'm pretty sure that I've met some of the management types in it. I thought that leaving my previous career would mean that I'd spend less time with psychopaths, not more!

The Glasses Adjuster is lovely too, a proper feeling of fairytale going on there and it left me feeling all warm of snuggly.

All of the stories were brilliant but these three stood out for me, and for this price you can't go wrong... after all Mr Weinle has to make enough to keep on feeding his cottage bulbs of unusual wattage.

View all my reviews