Posts

Working From Home Is The New Normal

The 2020 COVID-19 pandemic really turned the world on its head. Despite the fact people have lost their jobs, businesses have been hurt, airlines are struggling and tourism has taken a nosedive, many of us have been fortunate enough to keep our jobs and work from home. Many large tech companies have already announced permanent changes allowing employees to work from home indefinitely. Twitter, Square and Facebook being some of the biggest who have announced changes.

How To Handle Async/Await Errors in Javascript

Some developers are still new to async/await in Javascript. If you’re used to callbacks or using .then to get the value of a promise, async/await can be a bit of a black box, especially when it comes to errors. The most straightforward and recommended way to handle errors is using try/catch. This will allow you to catch errors if your async function rejects or throws an error. async function getProducts() { try { const response = await fetch('/products'); const products = await response.json(); } catch(err) { console.error(err); } } If you had a function which handles API requests, you could do something like this:

How To Copy A Public and Private Key From Windows Linux Subsystem Terminal

In WSL (Windows Subsystem for Linux) you get access to a Linux terminal right inside of Windows 10. For the most part, it works great. However, when it comes to copying and pasting the contents of files from Linux into Windows, the option is obscured. You can right-click the toolbar on the WSL terminal window, go to properties and enable the copy and paste features if you’re on one of the latest versions of it.

How To Optimise Microsoft Flight Simulator 2020 Including CPU Performance Issues

If you are like me, you do not have the world’s most expensive and powerful gaming PC. When Microsoft Flight Simulator 2020 was announced, I was excited like a kid on Christmas. While my machine allegedly falls somewhere in the medium performance category, admittedly, the performance has been anything but smooth for me playing the game. Through trial and error, I’ve struck a good balance between the game not looking like Minecraft and not running like a potato.

How To Use Autonumeric.js With Aurelia

As a long-term user of the InputMask plugin, I’ve long put up with its downsides such as issues around negative amounts and decimals. Recently, I was tasked with integrating Autonumeric into an Aurelia application at work and the result was simple and elegant, I thought I would share it. The result works out a lot nicer than InputMask which I personally find to be an absolute nightmare to work with for currency scenarios especially.

Revisiting My Open Source Ideas From Six Years Ago

Six years ago I open-sourced some ideas onto Github I had floating around in my head. The web has changed a lot in six years, so I thought I would revisit my ideas and see what was good and what wasn’t. Massive Cryptocurrency API The idea was simple, an API for sending and receiving cryptocurrency payments. While Coinpayments was listed as a previous competitor, nobody else that I know of came to the table with a solution that has survived into 2020. Coinpayments is all but the standard for crypto payments now.

Recursively Fetch Data From The GitHub API Using Octokit

Recently I began updating TidyFork to be written in Aurelia 2. As such, I took the opportunity to change how the repositories were loaded in the UI. There are numerous Octokit libraries provided by GitHub which let you make requests to the GitHub API. Using the request.js package, I make calls to the GitHub API. I also use the Parse Link Header package to parse the pagination headers that GitHub returns on its API responses.

How To Calculate A Javascript Date X Months Ago With Vanilla Javascript

Working with dates in 2020 are still a mess. Presumably, they’ll also be a mess to work within 2021, 2022 and for a good while after that. Many (myself included) reach for a date library to fill the gaps. For years Moment.js reigned supreme and for good reason, it can do everything with dates, including working with different time zones. Unfortunately, Moment can also result in bundle bloat. And then came along date-fns. It could do almost everything Moment did and was good enough for 95% of all date and time related use cases. However, depending on the task, you can still use native vanilla Javascript to work with dates.

Protected User Uploadable Files With Firebase Storage

Recently, while I was building an application on Firebase and implementing Firebase Storage, I realised that I have to always consult old Firebase projects I have built or scour the web for blogs and documentation that explain not only how to do uploads to Firebase Storage but also write rules to protect them. My use-case is as follows: Users can create listings A listing can have one or more images An image is uploaded to Firebase Storage in the form of listing-images/userId/filename.extension I only want to allow users to write to this folder if they are that user currently logged in. This folder becomes a bucket for all of the users listing images. Uploading Files const storage = firebase.storage().ref(\`listing-images/${this.auth.currentUser.uid}/${image.name}\`); const upload = storage.put(image); upload.on('state\_changed', // Uploading... (snapshot) => { this.frontImageUploading = true; }, // Error () => { this.frontImageUploading = false; }, // Complete () => { this.frontImageUploading = false; } ); Uploading files with Firebase’ Javascript SDK could not be any easier. You create a reference to where you want to store a file and then you call the put method providing a file to upload.

How To Convert An Object To An Array In Vanilla Javascript

I do quite a lot of work with Firebase and when you are working with authentication claims, they will be returned as an object containing your simple values (usually booleans). Thankfully, since ES2015 landed, each Javascript release has introduced a new and easier way to work with objects and convert them into arrays. You don’t need any libraries like Lodash, this is all native and well-supported vanilla Javascript. To convert an object of properties and values, you can use Object.entries however, it will return an array of arrays, which isn’t terrible but might confuse Javascript novices as to how you would even work with these.