Thursday, 28 June 2018

Colour shading with JavaScript

Shading a colour can be an utter pain but when I came across this script from CSS-TRICKS I was happy as a pig in muck. At least I was until I had to change the colour received via a call to getComputedStyle. getComputedStyle returns the colour in this format rgb(RedDecimalNumber, GreenDecimalNumber, BlueDecimalNumber) (red is rgb(255,0,0)) rather than the #RedHexadecimalNumberGreenHexadecimalNumberBlueHexadecimalNumber (red is #ff0000). The original script I was using was the one linked above so I had to convert the colour from getComputedStyle to hexadecimal, alter its shade and return it back to the original element's style as hexadecimal again.

This method seemed overly complicated, and I clocked that I didn't need to return it to the element as hexadecimal but could use it just as an RGB string in the inline CSS. Then I got to looking at the original script and realised that as getComputedStyle returns an RGB string, I could rewrite the original function to use a regex function and return that to the inline CSS instead. The following is the function:

o.replace(/\d+/g,c=>~~c+s>=255?255:~~c+s<=0?0:~~c+s)

I always forget that replace can take a function as the second argument but in this instance, it's cool that it does. The following is a less ES6y version:

o.replace(/\d+/g, function(c){
  if((parseInt(c, 10) + s) >= 255){
    return 255
  }else{
    if((parseInt(c, 10) + s) <= 0){
      return 0
    }else{
      return parseInt(c, 10) + s
    }
  }
})

Fun eh?

Monday, 25 June 2018

Vue simple-webpack on c9

I've lost track of how many times I've had to re-research this issue so I thought I'd best document it here. When playing through tutorials on Vue I often use c9 but had problems figuring out how to get the simple-webpack versions running. This, then, is how to get it up and running with a the vue-cli.

Open webpack.config.js and turn off the host check by adding this to the devServer object:

devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true,
    disableHostCheck: true
}

Then open package.json and alter the dev scripts object so it looks like this:

"cross-env NODE_ENV=development webpack-dev-server --host $IP --port $PORT --open --hot"

Of course, this works for me but YMMV.

Sunday, 22 April 2018

A new outdoor venue for Witchford Archers

One of the things that always impresses me about Witchford Archers is just how well we work together! Last year when we had to move venue, we worked like crazy to move all of our kit. While it might seem that all we do is shoot, and drink afterwards, in the background, there's so much activity it makes me positive about humanity!
We prepared our new outdoor venue yesterday. Nick has moved heaven and earth to secure the playing fields at Sutton C of E (VC) Primary School as a lovely place to shoot when the sun's out. Yesterday we made significant progress with building a... shed doesn't do it justice, to be honest as it's a work of art!
Designed and architected by Alan and Chris loads of work went into sourcing and preparing materials as cheaply as possible.
Aided my Derek, Nick, Oliwia and Dominic it was erected in a lovely shady spot in the playing fields over the course of Saturday the 21st of April 2018. The following show just what was accomplished!

Wednesday, 4 April 2018

Detect IE11

I'm old enough to remember why we needed jQuery: IE6.

Now I'm less used to using it and prefer vanilla JS but still wish for its universal levelling of the playing field because now I have to deal with the peculiarities of IE11 on a near daily basis so, thanks to this answer on StackOverflow, you'll often see this peppering my code:

if(!!navigator.userAgent.match(/Trident.*rv\:11\./)){
    // Do something peculiar...
}

Monday, 26 March 2018

Rock your lobster

I've moved jobs, and that's all well and good, but the best thing is meeting the new people. One of whom suggested I read 12 Rules for Life by Jordan Peterson (thanks, Gorka). It's an interesting read/listen, not least because his first rule is all to do with standing up straight... and something to do with lobsters...

The thing is, my back is borked with my vertebrae all on the way to being fused together (bloody AS). Thus I'm unable to even look behind me unless I turn around (got to love mirrors in cars).

And don't get me started on Yoga! I've tried it, and I thought it was a lovely idea (I even bought a mat on offer in Sainsbury's), but I lasted all of 5 and a half sessions until I knocked it on the head. The straw that broke the camels back was the instructor's insistence that we gradually curve our backs from sitting up until we were lying flat on our backs, at which point there was an almighty slap! There was no gradual curving involved; I just crashed back because I can't gradually curve my back as it's a solid lump. Unless that is, Maria's has expanded all of her strength pummeling it once a month, at that point it sort of moves freely for a little while (or it feels as if it does anyway, or I don't care because I'm too relaxed to notice).

So never put off a decent massage (thanks, Maria) and don't worry too much about standing up straight. He, Mr Peterson, does suggest other things. If you can't stand up straight, you can do other things like looking someone squarely in the face and putting your shoulders back... he even trots out the old adage about smiling making you feel better, even if you're not feeling all that chipper to start with (It's true as well).

Sunday, 11 March 2018

One line NHS Number checker

I didn't know this until recently, but the UK's NHS number is a rather smart device, and I ended up spending a few minutes looking at this page and then generating this checker:

const chechNhsNum = num => {
  let multiplier = 10;
  return num.split("").reduce((a, c) => {
    if(multiplier > 1){
      const semiTotal = ~~c * multiplier;
      multiplier--;
      return a + semiTotal;
    }else{
      return 11 - a % 11 > 9 ? false : ~~c === 11 - a % 11
    }
  }, 0);
};

Then I got to thinking how small I could make the checker and worked this up:

const validNHSnum=num=>num.split("").reduce((a,c)=>a.m>1?{a:a.a+~~c*a.m,m:a.m-1}:11-a.a%11>9?false:~~c===11-a.a%11,{a:0,m:10});

Which is sort of like the puzzles Mr Monks and I used to beat ourselves up with when we played Empire of Code. Running it through Babel produces this, which I guess is more readable:

var validNHSnum = function validNHSnum(num) {
  return num.split("").reduce(function (a, c) {
    return a.m > 1 ? { a: a.a + ~~c * a.m, m: a.m - 1 } : 11 - a.a % 11 > 9 ? false : ~~c === 11 - a.a % 11;
  }, { a: 0, m: 10 });
};

Thursday, 8 March 2018

Contagious nausea


A friend and I were discussing the most humorous bodily functions, and we got into a disagreement over whether farting of vomiting was the funniest.

I'm pretty sure that farting is the one most likely to make me guffaw, but she told a rather good story about sick that made me chortle.

The main reason why I think vomit is no laughing matter is that for me at least, it's contagious. I see someone being sick and I automatically get the gag reflex as well. And it doesn't even have to be a person.

Once-upon-a-time, when we lived afloat, I was quietly sitting working on my laptop in the galley when the cat went mental! Eddie was a bruiser of a cat with a face that only his mother, god rest her diseased soul, could love. He looked and acted like a thug, and I'm pretty sure he thought he was a dog.

He'd found a moth you see, and not just any old moth but one the size of Mothra. It was huge! He thought it was immense fun to chase around after the poor bugger dragging considerable tears in its wings. To such an extent that it was no longer able to keep itself aloft and fell to the floor, still waving it's enormous wings - though to no avail. It just lay there waving it's broken wings until, that is, Eddie pounced.

He batted it around a wee bit until he got bored and then chomp, down it went.

His table manners were as brutish as everything else about him, and he didn't bother to chew so down the poor moth went, still flapping.

The flapping must've tickled something in his withered innards as, not 10 seconds after he'd swallowed dear old Mothra, he threw it back up.

"Ah, bloody cat", says I and I gentle step over it to grab some kitchen roll to wipe up the mess. Crouching down after gently moving the cat out of the way (he was cleaning his claws and looking disinterested now that he's murdered his plaything) I bent to my task. But, looking down at the forlorn once-giant, I noticed that s/he was still vainly trying to escape and was gently waving those tattered wings while being slightly crushed and covered with Eddie's digestive juices and the odd semi-digested cat biscuit.

That was it! Thankfully I was close to the oven, so I grabbed the largest pan I could and threw up in it while, through streaming eyes, I cleaned up the mess before putting the whole sorry lot into the fire for a decent cremation.