React Slider

August 31, 2018

#JavaScript #React.js #SASS

I’ve been learning React and recently build this slider component in React & SASS. I’ve been deep in React, Angular, Webpack, Node and Javascript in general for the past months. This is a fairly quick and dirty solution. Normally I’d be expecting to use Bootstrap 4 for something like this but it was quite useful figuring out a way to make this work which is why I made a gist of it.

Show Code

I’m proficient in Angular.js according to PluralSight (tl;dr – I’m not)

February 25, 2018

#Angular #JavaScript #jQuery #MySQL #React.js

According to PluralSight these are my proficiencies

I know that this kind of thing is very subjective – but I took some online tests to see how I would perform. I particularly enjoyed TestDome which involves live coding. It’s a challenge doing something against the clock – even when all of the usual lookups and documentation are available. These tests were not easy. There is enough time to look up specific references or syntax – but you have to know what to look up. That seems fairly real world.

SimonSJavaScript (Hard)

SimonSPHP and WordPress (Hard)

SimonSJavaScript with jQuery (Hard)

Meanwhile – I found out about PluralSight via their tie-in with StackOverflow. I have been following various of their ‘paths’ (courses) recently as a way of consolidating / structuring / revising some of what I know – and learning some new stuff. The courses seem mostly very good.

But I was less sure about their testing. The first surprise was when I scored ‘Proficient’ on Angular.js. I got a badge. Yay! Ok – so it’s a JavaScript thing and I know a little bit about Design Patterns which helped. But I haven’t ever used Angular.js so far and I am definitely not proficient. I just tried to choose feasible answers.

These are multiple choice tests against the clock. There is no time to Google the answers. But if you read the questions carefully and have a good general knowledge of web technologies in general then many of the answers will come. You can have two goes at the tests – but you’ll get different questions.

I wasn’t surprised to do ok at the jQuery test – or that I scored relatively low on CSS. I always have to refer the documentation for CSS – even though I have used it a lot. But I was definitely surprised to score higher on node.js than on JavaScript – since I have only ever used node.js locally as a test environment. I am definitely much more familiar with regular JavaScript. Although I often have to remind myself how to do something the regular JavaScript way if I have been buried in jQuery for a while.

And apparently I’m an ‘Expert’ with MySQL. In reality I’m a competent beginner and I get stuff done by reading the documentation or carefully looking at Stack Overflow answers. I’m actually quite weak on using SQL in general – although I have no doubt that I would be quickly up to speed if that was what I was doing every day.

My other proficiencies apparently include C++, React, ‘Security For Hackers & Developers’ and ASP.NET MVC5. In reality I know about the same re React as I know about AngularJS. And I haven’t written any C++ for maybe 20 years. I would have to start again with that. I currently know very little about the world of Microsoft solutions in general (things have moved on a bit since I was programming Visual Basic). I’m just not ‘Proficient’ in all of these technologies. I wish that I were. And everything I know about security is from recipes, checklists and podcasts.

Sulby Theme Slider

February 23, 2018

#CSS #JavaScript #jQuery #JSON #PHP #Shortcode API #Sulby Theme #WordPress


I built this simple slider for my standalone "Sulby" WordPress theme. Written in PHP and JavaScript with jQuery + CSS defining the layout, responsiveness etc. The code is below.

In several past projects we used a well known third-party slider. Now I wanted something more minimal, lightweight and extensible. If we want to change the look and feel then we can do that that in CSS. If we want different functionality then let’s do it in the code. It’s much simpler than trying to work out how to achieve a result via a convoluted plugin interface or restrictive settings.

The PHP creates a WordPress Shortcode. The WordPress Shortcode API can be used to create macros which can be added to a Post or a Page – or to a PHP template using the do_shortcode() function. Eg the slider shown here is added like this:

[insertSulbySlider images=1005,992,1003,1002,993 message-title="Slider Demo" message-body="stock images from my legacy portfolio at Getty Images & iStockPhoto" slider-caption="Bunhill / Getty Images" slider-caption-link="" delay=8 aspect-padding=56.25 header-bool=false]

The images are added by ID. The json_encode function sanitizes this input and then translates the data to a JSON string to be passed to a JavaScript function. The $custom_aspect variable allows me to specify the aspect ratio of the slider. The TL;DR:

eg – 100 = 1:1 / 75 = 4:3 / 66.66 = 3:2 / 56.25 = 16:9

We need to be able to specify the aspect ratio every time. The slider is a div background image but there is not currently a way in CSS to set height such that it is dynamically proportional to widthcalc only works with vw and vh. We could do it in Javascript but that would be clunky (the function would be repeatedly called as the user resized a browser window). Instead we set width to 100% and height to 0 (in the CSS). Then use padding-top as a percentage. The method is described here at

The $header_bool variable flags a specific exception – if the slider is at the top of the page then it wants to be approaching full height relative to the device or browser window – 79vh set in the JavaScript. This particularly matters on phones and the $custom_aspect variable is effectively ignored.

Each slider needs a unique #ID – because elements must be unique per page and potentially we may have more than one slider per page with different properties. That means naming them dynamically. PHP’s uniqid() is a perfectly adequate solution here.

Show Code

Validating JavaScript using ESLint in Visual Studio Code

February 9, 2018

#ESLint #JavaScript #jQuery #JSLint #node.js #SSHFS #Visual Studio Code

ESLint / Visual Studio Code
ESLint highlighting sloppy code

I switched to Microsoft Visual Studio Code originally because Brackets seemed to struggle with remote file systems mounted using via SSHFS (using Fuse for macOS).

Brackets has JSLint built in. Various JavaScript linting options exist for Visual Studio Code. I’m using ESLint and this extension which integrates ESLint into VSCode.

ESLint requires node.js & npm. Install node.js locally using the pkg. The npm package manager is installed as part of that. We then use npm to install ESLint globally (sudo npm install -g eslint).

Then run eslint --init from the root directory of any project where you want to use ESLint to validate the code. That will create a project specific configuration file.

1 2 3

Show All Posts