Blog

Posts written in 2024.

  • The Google Maps Distance Matrix API gives us the capability to calculate travel distance and time between multiple locations across different modes of transportation, such as driving walking, or cycling. This is just one of the many other APIs Google provides to allow us to get the most out of location and route related data.

    I needed to use the Google Distance Matrix API (GDMA) to calculate the distance of multiple points of interests (destinations) from one single origin. The dataset of destinations consisted of sixty to one-hundred rows of data containing the following:

    • Title
    • Latitude
    • Longitude

    This dataset would need to be parsed to the GDMA as destinations in order get the information on how far each item was away from the origin. One thing came to light during integration was that the API is limited to only outputting 25 items of distance data per request.

    The limit posed by the GDMA would be fine for the majority of use-cases, but in my case this posed a small problem as I needed to parse the whole dataset of destinations to ensure all points of interests were ordered by the shortest distance.

    The only way I could get around the limits posed by the GDMA was to batch my requests 25 destinations at a time. The dataset of data I would be parsing would never exceed 100 items, so I was fairly confident this would be an adequate approach. However, I cannot be 100% certain what the implications of such an approach would be if you were dealing with thousands of destinations.

    The code below demonstrates a small sample-set of destination data that will be used to calculate distance from a single origin.

    /*
    	Initialise the application functionality.
    */
    const initialise = () => {
    	const destinationData = [
                        {
                          title: "Wimbledon",
                          lat: 51.4273717,
                          long: -0.2444923,
                        },
                        {
                          title: "Westfields Shopping Centre",
                          lat: 51.5067724,
                          long: -0.2289425,
                        },
                        {
                          title: "Sky Garden",
                          lat: 51.3586154,
                          long: -0.9027887,
                        }
                      ];
                      
    	getDistanceFromOrigin("51.7504091", "-1.2888729", destinationData);
    }
    
    /*
    	Processes a list of destinations and outputs distances closest to the origin.
    */
    const getDistanceFromOrigin = (originLat, originLong, destinationData) => {
      const usersMarker = new google.maps.LatLng(originLat, originLong);
      let distanceInfo = [];
      
      if (destinationData.length > 0) {
      	// Segregate dealer locations into batches.
        const destinationBatches = chunkArray(destinationData, 25);
    
        // Make a call to Google Maps in batches.
        const googleMapsRequestPromises = destinationBatches.map(batch => googleMapsDistanceMatrixRequest(usersMarker, batch));
    
        // Iterate through all the aynchronous promises returned by Google Maps batch requests.
        Promise.all(googleMapsRequestPromises).then(responses => {
          const elements = responses.flatMap(item => item.rows).flatMap(item => item.elements);
    
          // Set the distance for each dealer in the dealers data
          elements.map(({ distance, status }, index) => {
            if (status === "OK") {
              destinationData[index].distance = distance.text;
              destinationData[index].distance_value = distance.value;
            }
          });
          
          renderTabularData(destinationData.sort((a, b) => (a.distance_value > b.distance_value ? 1 : -1)));
        })
        .catch(error => {
          console.error("Error calculating distances:", error);
        });
      }
    }
    
    /*
    	Outputs tabular data of distances.
    */
    renderTabularData = (destinationData) => {
    	let tableHtml = "";
      
        tableHtml = `<table>
                        <tr>
                            <th>No.</th>
                            <th>Destination Name</th>
                            <th>Distance</th>
                        </tr>`;
    
    	if (destinationData.length === 0) {
            tableHtml += `<tr colspan="2">
                            <td>No data</td>
                        </tr>`;
      }
      else {
            destinationData.map((item, index) => {
      		        tableHtml += `<tr>
                                    <td>${index+1}</td>
                                    <td>${item.title}</td>
                                    <td>${item.distance}</td>
                                </tr>`;
                });
      }
      
      tableHtml += `</table>`;
      
      document.getElementById("js-destinations").innerHTML = tableHtml;
    }
    
    /*
    	Queries Google API Distance Matrix to get distance information.
    */
    const googleMapsDistanceMatrixRequest = (usersMarker, destinationBatch) => {
      const distanceService = new google.maps.DistanceMatrixService();
      let destinationsLatLong = [];
      
      if (destinationBatch.length === 0) {
      	return;
      }
      
      destinationBatch.map((item, index) => {
        destinationsLatLong.push({
          lat: parseFloat(item.lat),
          lng: parseFloat(item.long),
        });
      });
      
      const request = 
            {
              origins: [usersMarker],
              destinations: destinationsLatLong,
              travelMode: "DRIVING",
            };
    
      return new Promise((resolve, reject) => {
        distanceService.getDistanceMatrix(request, (response, status) => {
          if (status === "OK") {
            resolve(response);
          } 
          else {
            reject(new Error(`Unable to retrieve distances: ${status}`));
          }
        });
      });
    };
    
    /*
    	Takes an array and resizes to specified size.
    */
    const chunkArray = (array, chunkSize) => {
      const chunks = [];
    
      for (let i = 0; i < array.length; i += chunkSize) {
        chunks.push(array.slice(i, i + chunkSize));
      }
    
      return chunks;
    }
    
    /*
    	Load Google Map Distance Data.
    */
    initialise();
    

    The getDistanceFromOrigin() and googleMapsDistanceMatrixRequest() are the key functions that take the list of destinations, batches them into chunks of 25 and returns a tabular list of data. This code can be expanded further to be used alongside visual representation to render each destination as pins on an embedded Google Map, since we have the longitude and latitude points.

    The full working demo can be found via the following link: https://jsfiddle.net/sbhomra/ns2yhfju/. To run this demo, a Google Maps API key needs to be provided, which you will be prompted to enter on load.

  • Published on
    -
    2 min read

    The Silent Blogger

    Everyone has different reasons for blogging. It could be for professional development, knowledge exchange, documenting a personal journey, or just as a form of self-expression. My motive for blogging includes a small portion of each of these reasons, with one major difference: you have to find me.

    I don't go out of my way to promote this small portion of the internet web-sphere that I own. In the past, I experimented with syndicating articles to more prominent blogging media platforms and communities, but it didn't fulfil my expectations or bring any further benefits.

    I've observed that my demeanour mirrors an approach to blogging in that I don't feel the need to go to excessive lengths to disclose my accomplishments or a problems I've solved. This could be due to my age, as I am more comfortable just being myself. I have nothing to prove to anyone.

    A 13th century poet, Rumi, once said:

    In silence, there is eloquence. Stop weaving and see how the pattern improves.

    This quote implies that silence is the source of clarity that allows thoughts to develop naturally and emerge.

    Ever since I stopped the pursuit of recognition and a somewhat futile attempt to force my written words onto others, the natural order has allowed this blog to grow organically. Those who have found me from keyword searches has resulted in better interaction and monetisation (through my Buy Me A Coffee page). Fortunately, since I've made an effort to make this blog as SEO-friendly as possible, my posts appear to perform fairly well across search engines.

    No longer do I stress over feeling the need to write blog posts using the "carrot and stick" approach just to garner more readership. I found I benefit from blogging about the things of interest. It's quality over quantity.

    If you have got this far in this very random admission of silent blogging, you're probably thinking: So what's your point?

    I suppose what I'm trying to say is that it's okay to blog without the expectation of having to promote every single post out to the world in hopes for some recognition. Previously, this was my way of thinking, and I've since realised that I was blogging (for the most part) for the wrong reasons. In one of my posts written in 2019 I was in pursuit to be in the same league as the great bloggers I idolised:

    I look at my blogging heroes like Scott Hanselman, Troy Hunt, Mosh Hamedani and Iris Classon (to name a few) and at times ponder if I will have the ability to churn out great posts on a regular basis with such ease and critical acclaim as they do.

    I've learnt not to be so hard on myself and lessen expectations. When you trade your expectations for appreciation, your whole world changes; even though a sense of achievement feels great, it's far more important to enjoy what you're doing (roughly para-phrasing Tony Robbins here).

    This new perspective has reaffirmed my belief that I have always enjoyed blogging, but being a silent blogger provides a sense of freedom.

  • Published on
    -
    3 min read

    Kentico 13: Cookiebot Blocking Page Builder Scripts

    Cookiebot was added to a Kentico 13 site a few weeks ago resulting in unexpected issues with pages that contained Kentico forms, which led me to believe there is a potential conflict with Kentico Page Builders client-side files.

    As all Kentico Developers are aware, the Page Builder CSS and JavaScript files are required for managing the layout of pages built with widgets as well as the creation and use of Kentico forms consisting of:

    • PageBuilderStyles - consisting CSS files declared in the </head> section of the page code.
    • PageBuilderScripts - consisting of JavaScript files declared before the closing </body> tag.

    In this case, the issue resided with Cookiebot blocking scripts that are generated in code as an extension method or as a Razor Tag Helper.

    <html>
    <body>
        ...
        <!-- Extension Method -->
        @Html.Kentico().PageBuilderScripts()    
        ...
        <!-- Razor Tag Helper -->
        <page-builder-scripts />
        ...
    </body>
    </html>
    

    Depending on the cookie consent given, Kentico Forms either failed on user submission or did not fulfil a specific action, such as, conditional form element visibility or validation.

    The first thing that came to mind was that I needed to configure the Page Builder scripts by allowing it to be ignored by Cookiebot. Cookiebot shouldn't hinder any key site functionality as long as you have configured the consent options correctly to disable cookie blocking for specific client-side scripts via the data-cookieconsent attribute:

    <script data-cookieconsent="ignore">
        // This JavaScript code will run regardless of cookie consent given.
    </script>
    
    <script data-cookieconsent="preferences, statistics, marketing">
        // This JavaScript code will run if consent is given to one or all of options set in "cookieconsent" data attribute.
    </script>
    

    Of course, it's without saying that the data-cookieconsent should be used sparingly - only in situations where you may need the script to execute regardless of consent and have employed alternative ways of ensuring that the cookies are only set after consent has been obtained.

    But how can the Page Builder scripts generated by Kentico be modified to include the cookie consent attribute?

    If I am being honest, the approach I have taken to resolve this issue does not sit quite right with me, as I feel there is a better solution out there I just haven't been able to find...

    Inside the _Layout.cshtml file, I added a conditional statement that checked if the page is in edit mode. If true, the page builder scripts will render normally using the generated output from the Tag Helper. Otherwise, manually output all the scripts from the Tag Helper and assign the data-cookieconsent attribute.

    <html>
    <body>
        ... 
        ...
        @if (Context.Kentico().PageBuilder().EditMode)
        {
            <page-builder-scripts />
        }
        else
        {
            <script src="/_content/Kentico.Content.Web.Rcl/Scripts/jquery-3.5.1.js" data-cookieconsent="ignore"></script>
            <script src="/_content/Kentico.Content.Web.Rcl/Scripts/jquery.unobtrusive-ajax.js" data-cookieconsent="ignore"></script>
            <script type="text/javascript" data-cookieconsent="ignore">
                window.kentico = window.kentico || {};
                window.kentico.builder = {};
                window.kentico.builder.useJQuery = true;
            </script>
            <script src="/Content/Bundles/Public/pageComponents.min.js" data-cookieconsent="ignore"></script>
            <script src="/_content/Kentico.Content.Web.Rcl/Content/Bundles/Public/systemFormComponents.min.js" data-cookieconsent="ignore"></script>
        }
    </body>
    </html>
    

    After the modifications were made, all Kentico Forms were once again fully functional. However, the main disadvantage of this approach is that issues may arise when new hotfixes or major versions are released as the hard-coded script references will require checking.

    If anyone can suggest a better approach to integrating a cookie compliance solution or making modifications to the page builder script output, please leave a comment.

    Useful Information

  • Published on
    -
    4 min read

    Side Hustling With UserTesting.com

    Banner Image by: pch.vector on Freepik

    I've been looking out for a side hustle to supplement my monthly stock and shares investment contribution - trying to make up for lost time in the years I did not invest. As it was my first foray into the world of side hustling, I wanted to ease myself into things. So it was important for it to be flexible enough to work around office/personal hours and not require too much time.

    During the COVID-era, I kept note of some side hustles I was planning to try out but never got around to doing so. Forgetfulness also has a part to play in matters and was only reminded when coming across one of my notes from July 2021 stored in Evernote.

    Now was a good time as any to try out one of them: Usertesting.com.

    What Is UserTesting?

    Usertesting.com provides a platform for businesses to get feedback on their products and services. Anyone can apply to be a contributor and provide feedback that consists of:

    • Accessibility
    • Usability
    • Live conversations with businesses
    • Pre-release platform feature review
    • Competitor benchmarking tests
    • A/B testing to compare different versions of a product or feature

    Before becoming an active contributor, a UserTesting will require some basic information as part of the registration process and a practice test to be completed.

    Acing The Practice Test

    UserTesting will provide a test scenario to prove you're a legitimate person and have the capability to demonstrate good communication and analytical thinking. It provides a good standard that is expected when carrying out real tests.

    The test itself is not complicated but you should be prepared to clearly think out loud so there is an understanding of your thought process as you're undertaking various tasks. It's always a good idea before performing a task to read the question out loud so your interpretation of what is being asked is clear. Most importantly, be honest in what you're reviewing.

    At the end of the test, provide a conclusion and thank them for their time in this opportunity.

    The fact that UserTesting.com forces users to take an assessment beforehand demonstrates the credibility of the service and sets the standard for the type of businesses they work with.

    UserTesting will respond to your practice test within 2-3 days, provide feedback and let you know if you will be accepted as a contributor.

    What To Expect From The Real Test?

    After completing the practice test, I didn't get real tests immediately. It took a good couple of weeks for them to start trickling in. Even then, I didn't qualify to take part in some tests as I didn't have experience in the area of expertise.

    Tests are performed on Windows, Mac, Android or iOS devices. There might be a requirement to provide feedback using a specific device. Access to a microphone and sharing your screen is a strict prerequisite. Some do ask for a face recording as well, but I decided to refuse tests that requested this.

    Test vary in length and payout:

    1. Short tests - $4
    2. 10-20 minute tests - $10
    3. 30-minute test - $30
    4. 60-minute test - $60

    The 60-minute tests will always be live a conversation directly with the business and scheduled in advance.

    The Type of Tests I've Contributed To

    I have been quite lucky as to the tests offered to me as they seem to relate to the tech industry. Providing feedback for businesses such as Microsoft, SalesForce, Github, GitLab and Amazon has been insightful.

    Other tests have evolved around the sectors of AI, website accessibility, pre-release platform updates and cloud-hosting.

    Payout

    This is the part you have all been waiting for. How much money have I made since starting at the beginning of June?

    Jerry Maguire - Show Me The Money

    I completed twenty tests consisting majority of $10 tests, one $60 test and a handful of $4 tests. Totalling to $232. Each test is paid out within two weeks to your linked PayPal account. Not so bad for an ad-hoc side hustle.

    UserTesting.com Payout - August 2024

    Twenty tests over the span of three months is not a lot when my contribution could have been higher. But when taking into consideration that this side hustle is only pursued outside of working hours and some tests do not apply to my expertise, it's not so bad.

    The majority of tests offered will be worth $10. Some may question whether they're even worth doing, to which I say: Yes! A $10 test can take anywhere between 5-15 minutes to complete on average. When you take the hourly UK National Minimum wage of £11.44, it's not bad. $10 converted to GBP equates to around £7.60. Easy money!

    The more you contribute the higher chance there is in getting more tests offered to you, providing your feedback rating is good. There are some damn interesting ones as well.

    Conclusion

    Don't apply to UserTesting with the expectation of mass riches as you will sorely be disappointed. Think of it as petty cash to count towards a little "fun money".

    Apart from the monetisation aspect of using UserTesting, I feel I am getting an early insight into where certain industry sectors are going, including my own, which is almost as valuable as the payout itself.

    There will be some days or even weeks when there will be no applicable tests. Just stick with it as all it takes is a handful of 30 or 60-minute tests (which can be hard to come by) to get a nice chunk of change for the month.

  • Published on
    -
    4 min read

    Addressing The Lack of Kentico Content

    I spoke to one of my developer friends a while back and as conversations go with someone tech-minded, it's a mixture of talking about code, frameworks, and platforms entwined with the more life-centric catch-up.

    Both having been in the tech industry for over 15 years, we discussed the "old ways" and what we did back then that we don't do now, which led to Kentico - a platform that we used to talk about all the time, where we'd try and push the boundaries to create awesome websites in the hopes of winning the coveted site of the month or year award. It occurred to us that it's not something we talk much about anymore. Almost as if overnight it vanished from our consciousness.

    Looking through the archive of postings, it's evident I haven't published anything Kentico-related in a long time, with my most recent being in September 2020. Despite the lack of Kentico content on my site, it remains a key player in the list of CMS platforms that I work with. The only difference is the share of Kentico projects are smaller when compared to the pre-2020 era.

    In this post, I discuss my thoughts as to the reason behind my lack of Kentico-related output.

    NOTE: This post consists of my view points alone.

    Licensing Cause and Effect

    A contributing factor was the substantial shift in their licensing model sometime in 2020. Moving to an annual subscription at an increased cost and ditching the base license created somewhat of a barrier to entry for small to mid-sized clients who just needed a reliable CMS platform with customisability. So for someone like myself who could provide Kentico solutions in a freelance capacity was instantly priced out.

    I understand why Kentico needed to reassess its price structure. They offer one of the best .NET CMSs and to stay at the top, an increase in revenue is required to drive the business forward. In all honesty, I believe we had a good run on the old licensing model for over ten years, and it was only a matter of time until a pricing review was required.

    It's just a hard sell when trying to sell a CMS with a £10,000 price tag before any development has even started.

    In light of this, it's only natural to look for alternatives that align with your own business strategy and development needs. The time originally spent developing Kentico has now been reallocated to alternative CMS platforms.

    A Stable Well-Rounded Platform

    Kentico is a mature product with many out-of-the-box capabilities (that get better with every release), which indirectly contributed to my lack of blogging on the subject. I usually only blog about a platform when I find useful workarounds or discover an issue that I was able to resolve.

    This is truly a compliment and testament to Kentico's build quality. There is no need to write about something that is already well-documented and written by active users of the community.

    Reassessing The Kentico Offering

    Kentico is still offered whenever possible. Both clients and developers alike have confidence in the platform. Clients enjoy the interface and security. Developers appreciate the customisability, clear architecture, quick hot fixing, and consistency between editions.

    The only question we now have to ask ourselves is whether Kentico is the right platform for the client's requirements. Prior to the change in licensing, you would be scoffed at for asking such a question. Kentico would be the front-runner before considering anything else.

    Nowadays, Kentico would only be put forward to a client if they had large-scale requirements where cheaper CMS offerings fall short for the licensing costs to be justified.

    I was recently involved in an e-commerce project that ticked all the boxes in line with the client's priorities, which made for an ideal use-case to carry out the build in Kentico, such as:

    • Enterprise-level security
    • Industry-standard compliance
    • All in one solution consisting of content management, e-commerce, and marketing automation
    • Scalability
    • Ability to handle large sets of data
    • Advanced customisability

    In my view, if a client is not too concerned about the above, then alternatives will be used and additional development will be carried out to fill in any gaps.

    The Alternatives

    The CMS sphere is ripe with offerings where we are spoilt for choice. I have whittled these down to:

    1. Umbraco
    2. Kentico
    3. Prismic
    4. Dato
    5. HubSpot

    In my view, those variety of CMSs covers all pricing points, technologies and customisability.

    Conclusion

    I would always jump at the chance in developing in Kentico as I know a large complex website can be developed with almost infinite customisation. But we can't help but notice there is a lot of competition out there, each providing a range of features across different architectures and price ranges.

    Based on my own experience, the demand for fully featured CMS platforms that have a large hosting footprint are reducing in popularity in the advent of more API driven (also known as headless) content delivery that works alongside other microservices.

    Investing in the Kentico eco-system (including its headless variant, Kontent) is always worth considering. It may just not be something I will be writing about consistently here as it requires a more corporate-level type of clientele.

  • Published on
    -
    2 min read

    CSS Zen Garden - The Road To Enlightenment

    Who remembers CSS Zen Garden? I do. As if it was yesterday... I remember first gazing my sights on a simplistic but visually stunning webpage demonstrating what all websites in the future could look like.

    CSS Zen Garden broke the norm of the websites we were used to seeing at the time - crowded blocky tabular-based layouts that lacked personality. It was a revelation and a turning point in web design standards!

    As described within the content of every CSS Zen design, its ethos was clear:

    The Road To Enlightenment

    Littering a dark and dreary road lay the past relics of browser-specific tags, incompatible DOMs, broken CSS support, and abandoned browsers.

    We must clear the mind of the past. Web enlightenment has been achieved thanks to the tireless efforts of folk like the W3C, WaSP, and the major browser creators.

    The CSS Zen Garden invites you to relax and meditate on the important lessons of the masters. Begin to see with clarity. Learn to use the time-honored techniques in new and invigorating fashion. Become one with the web.

    CSS Zen Garden pathed The Road To Enlightenment for me in an entirely different manner - deciding my career.

    Having completed my degree in Information Systems at university in 2006, I was at a crossroads as to which IT field I should specialise in. University seems to prepare you for anything apart from how to apply yourself when you exit the final doors of education into the real world.

    CSS Zen Garden changed the trajectory of my career. Originally, I considered entering the field of Consulting to then changing my mindset into garnering interest as a Web Developer instead. This has had a lasting effect. Even after 18 years, I am still involved in Web Development. I tend to focus more on backend functionality rather than look and feel.

    The CSS Zen Garden community spawned a variety of other designs from talented Web Developers that encompassed a design flair. But the design that started it all, 001, will always hold a special place in my heart. The unforgettable Japanese elements - the Itsukushima Shrine, water lilies, and a blossom tree.

    All the designs have stood the test of time and even through the age of modern web browsers and high-resolution screens, they still present a timeless look that fills me with nostalgia.