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.
Dominic Myers writes about all sorts of stuff to do with HTML, CSS, JavaScript and a fair chunk of self-indulgent stuff. Thoughts and opinions are all his own, and nothing to do with any employer.
Monday, 31 March 2014
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.");