I Am Starting To Lose Respect For Elon Musk; Has He Become Unhinged?

The signs have been there for a while now. Elon Musk is the eccentric real life version of Tony Stark, who some believe is going to save the world with his forward thinking investments and ideas like making electric vehicles cool or making his own rockets.

But, for all of Elon’s great and commendable achievements, come some highly questionable decisions and remarks. Known for his non-corporate approach to communication, he has landed himself into hot water a few times now.

One of the most notable instances is when he called a scuba diva who helped rescue some kids trapped in a Thai cave a “pedo” it landed him in court.

Then there is Elon’s run ins with the SEC for his Tweets which has been perceived as market manipulation.

The Coronavirus panic is dumb, will go down as one of the stupidest things such an intelligent person has ever said. Then he voiced his doubts on the connection between COVID-19 and the deaths in Italy.

And more recently, Musk called for America to be “freed” in a Boomer style all-caps Tweet, FREE AMERICA NOW. The kind of remark that wouldn’t sound out of place at a Trump MAGA rally or pro-gun lobby funded event deriding legislation to take away their guns. You only have to look at some of the responses agreeing with Elon affiliated with the “right” many who are self described patriots according to their bios.

Many would argue that Elon has never been completely hinged to begin with. The awkward genius that seemingly can do no wrong amongst with die-hard fanbase.

The New Imgflip AI Meme Generator Is Fun (and dark)

I love a good meme and when I encountered Imgflip’s AI meme generator recently, even more so. As I cycled through the generator I noticed that it started producing some interesting memes.

The site describes the process for obtaining data to produce some of the AI memes:

The network was trained using public images generated by users of the Imgflip Meme Generator for the top 48 most popular Meme Templates. Beware, no profanity filtering was done on the training data so you may encounter vulgarity.

I have spent a lot of time just randomly generating memes, more than I would like to admit. It produces some questionable memes and some good ones as well.

The Eric Andre “why would” meme perhaps produced some of the darkest memes of all.

One of my favourite of the bunch is this one, which seems quite accurate:

And finally, one of my favourites:

You will never be a good communist.

How To Centre Columns In Bootstrap 4

It’s 2020 and while there are many things I do know, there are still some trivial silly things I do not or always forget. Case in point being, how to centre columns in a Bootstrap 4 layout.

Unlike Bootstrap 3, Bootstrap 4 uses Flexbox and therefore, you have more options for centring your layouts. One such method is the justify-content-center class defined on the row which will align the columns center. Finally, you use the text-center class to middle align the content of the column.

<div class="container">
    <div class="row justify-content-center">
        <div class="col-6 text-center">
            <p>My content</p>
        </div>
    </div>
</div>

This works by using the Flexbox property for justifying the content. We can also specify a column is display: flex; and align its contents like so as well, which can work well in certain situations.

<div class="container">
    <div class="row">
        <div class="col d-flex justify-content-center">
            <p>My content</p>
        </div>
    </div>
</div>

In the above, you might notice we don’t use text-center to center the text, we just make the column d-flex which makes it a flex element and its children and be aligned.

Nothing overly fancy. This post serves as more of a reminder to myself, but if you find it useful then that is a win as well.

Level Up Your Aurelia Applications With Router Layouts

When it comes to building applications, inevitably you will encounter situations where the base markup of your page is different than other parts of your site. The base structure of your front-facing pages like the homepage might be different from your administration panel or user dashboard, which might look similar but work very much differently.

Surprisingly, I don’t see a lot of developers who work with Aurelia opting to use them. I think Router Layouts are a forgotten feature to some, requiring a little upfront work which can net you a long-term negation of pain when trying to make your markup work.

A layout at its core is a dynamic template with one or more &lt;slot&gt; elements inside of it acting as content projectors. You have the one base &lt;router-view&gt; element like you usually would, except on your routes you can define a new layout.

Inside of your app.html or whatever file is your main application entry point template, you start off with something like this:

<template>
    <div>
        <router-view layout-view="default-layout.html"></router-view>
    </div>
</template>

Now, create our default layout and call it default-layout.html

<template>
    <slot></slot>
</template>

Now, inside of our app.js file we want to define a couple of routes:

export class App {
  configureRouter(config, router) {
    config.map([
        { route: '', name: 'home', moduleId: 'home' },
        { route: '404', name: '404', moduleId: '404', layoutView: 'error-layout.html' }
    ]);

    this.router = router;
  }
}

Now, let’s create our 404 view and view-model pairs. Firstly, 404.js:

export class FourOhFour {
}

Then, 404.html:

<template>
    <h1>404</h1>
    <p>Page not found</p>
</template>

Now, we need our layout for error pages which we will call error-layout.html

<template>
    <div class="h-100">
        <div class="center">
            <slot></slot>
        </div>
    </div>
</template>

By default, our app will use the default view layout supplied on the router-view element, but we can override this on a per-route basis. Furthermore, you can also supply a view-model as well as data to pass through and even define viewports.

Rather than going through it all, the official documentation does a great job explaining these other properties and concepts for you here. In most cases, a basic HTML only view template is what you want, but for more complicated scenarios the view-model and data properties are helpful.

I Used To Hate Using Reduce In Javascript, And Now I Can’t Stop

I used to be vehemently against using `reduce` in Javascript. It wasn’t because I thought there was a better way, I actually think the functional programming purists and their aggressive approach to advocacy are what really turned me off. That and those who advocate for using it over a basic for loop as well.

Now, there are instances where I truly believe that filter, map and reduce should not be used. If you’re just wanting to quickly iterate over a collection of values, in many instances. a for..loop will beat all of those aforementioned methods in performance every single time. And if you’re dealing with large collections of items, you will notice.

The reduce method is great for reducing values to either a singular value or manipulating the shape of data from one form to another. If you want to flatten an array, look no further than reduce. Want to average out a bunch of numbers and return a singular value? Oh, hi there reduce.

Here is an actual snippet of code I wrote not long before writing this post:

return rows.reduce((arr, row) => {
    row.contractPayload = JSON.parse(row.contractPayload) ?? {};
    arr.push(row);
    return arr;
}, [])

I am taking a bunch of rows from an SQLlite database, iterating over them and parsing a property which is stringified JSON, parsing it into an object or empty object if it doesn’t parse properly.

If I was one of those fancy developers that used shorthand for everything, I could have used the spread operator to really condense this code down into a one liner (inside the callback), but I am far too practical and prefer writing readable verbose code in most situations.

For a long time I used to be the type of developer who would create a variable with an empty array inside of it and use a for loop to push into the array, which gives you the same result.

I instinctively find that I naturally will reach for reduce over a traditional for loop whenever possible. In instances where I notice substantial performance issues, I’ll write a loop.

The real power and value of reduce is that it negates the need for unnecessary code. I guess they call it reduce because it reduces the amount of code you need to write as well. Neat.

I downloaded the Australian government’s CovidSafe Tracking App (so you don’t have too if you don’t wanna)

The controversial Australian government contact tracing application based on the Singapore version has finally been released for Australians. Understandably, a lot of people are concerned about their privacy and whether or not the government messed this up.

I had a spare phone lying around, so I installed the application for the lols. I decided to see if I could find anything nefarious with the app or if it drains my battery like Singaporeans reported their app did.

I am talking about the Android version in this article, presumably the Apple version is also the same, albeit when we speak about permissions, iOS offers its own set of permissions that developers can request.

Firstly, I commend the Australian government to an app which doesn’t look terrible. Usually, government built apps look terrible and work terribly, probably because it’s not a from-scratch application and based on Singapore’s app TraceTogether.

This is not going to be a technical deep-dive on the application or decompiling it and discussing lines of code. If you’re looking for the decompiled source, the community has already started doing that here. Although, the Australian government says the code will be made open source, who knows if or when that will be happening.

It appears on the surface the app is quite unremarkable. Like the Singapore version, it encrypts your data locally on your device and only through a request can you allow your data to be decrypted. Right now as the app currently stands, it seems safe. However, I have valid concerns which you should also have.

Does CovidSafe Drain My Battery?

From what I could see running it for a few hours, no. While I did not go out and try and get it to make a “trace handshake” with anyone else, it appears the app doesn’t use that much battery. In the few hours I used it, I saw a few percent drop which is nothing compared to Spotify, Pokemon Go or YouTube.

The application also appears to work fine in the background on Android as well. You get a notification telling you the app is active in the background and that’s it. There is no need to run the app and have it the only one open meaning you can interact and use other apps and features on your phone.

ACCESS_FINE_LOCATION

While the app only appears to access Bluetooth right now and uses it to determine the vicinity you are in relation to other app users, the app asks for the ACCESS_FINE_LOCATION permission on Android. If you read up on this permission here in the Android documentation, pay close attention to what it provides.

Allows the API to determine as precise a location as possible from the available location providers, including the Global Positioning System (GPS) as well as WiFi and mobile cell data.

Without fearmongering, I want to point out that the application at the time of writing this only ever uses Bluetooth. The ability to use GPS or anything else for location does not appear to be in the current application.

In theory, there is nothing stopping the Australian government from making an update which allows them to also track your location via GPS. This permission gives the app the ability to track GPS data if it wanted too, but I want to stress again, the app does NOT currently do this.

Concerns About Privacy

The CovidSafe application as far as I can see is safe. It does everything that the government said it would and it also appears to not be sending anything off in secret to the government or tracking your movements. However, I implore you the reader to be sceptical for a few reasons.

The first reason relates to the government’s mandatory data retention legislation. Law enforcement agencies are being given browser history of people under investigation, despite the fact the legislation specifically excluding it.

Given the LNP passed such legislation in 2015 and ever since there have been numerous reports and instances of metadata being incorrectly given to agencies, people and agencies getting access to data that they shouldn’t and overall confusion around how the scheme and subsequent legislation works.

Since the introduction of this legislation, there has also been significant scope creep where more and more agencies and bodies are able to access metadata. (from Greyhound Racing Victoria to Consumer Affairs and various local councils). If you think only law enforcement and national security agencies can access your metadata, think again.

A very real scenario

The second and most important reason relates to the controversial encryption weakening legislation that was passed in 2018. Given everything that has happened since then, it’s easy to forget this legislation passed and still exists.

If you think that the concerns around privacy and data are invalid, looking no further than law enforcement agencies asking for added capabilities to be added into the application. A request which the Morrison government knocked back, but the fact they even asked in the first place should concern you.

Here is where things get muddy and it’s a concern that not even the government can reassure citizens on. The encryption weakening legislation passed in 2018 could in theory, allow the government to add in a backdoor or added features to the application in a stealth update and nobody would be allowed to say anything.

All of the legal provisions are there to allow the Morrison government to enable this application (with a few lines of added code) to become something that can track your location through GPS given the permission to do so has already been granted.

Legally speaking (I am not a lawyer) the interpretation of all of this is the promised safeguards for the CovidSafe app would NOT override the backdoor encryption legislation or any other established legislation if they were to ever conflict with one another. As such, the reassurances and promises that protections are in place for CovidSafe are nothing more than empty words.

While I do not doubt that this app could be incredibly effective in helping trace COVID-19 infections and spread, there are just too many unknowns for me to consider installing this app. At the end of the day, make the decision that feels right to you and do not let this post or anyone else’s opinion do anything more than inform you and allow you to make your own decisions.

How To Mock uuid In Jest

When it comes to mocking dependencies in Jest, it couldn’t be easier. You can create an actual mock module that gets loaded in place of the dependency in your app or you can do it manually by mocking the implementation or module.

import uuid from 'uuid';
import { SomeClass } from './some-file'; 

describe('Test Case', () => {
    let sut;

    beforeEach(() => {
        sut = new SomeClass();
    });

    test('My Test', () => {
        jest.spyOn(uuid, 'v4').mockReturnValue('hjhj87878');

        expect(sut.returnUuid()).toReturn('hjhj87878');
    });

});

We need to import the library that we want to mock a specific method for, in this case it is the uuid library and the v4 method specifically. Inside of our test case we spy on the uuid class and v4 method.

We are assuming in this example that our returnUuid method is calling the v4 method in the uuid package to get a random guid. The above allows us to override the implementation on a test-by-test basis and choose what value is returned.

Dinnerly Australia — COVID-19 Review

As I explained in my HelloFresh review here, we have been trying out at home meal kits because of the shortages of basics in the grocery stores here in Australia such as; mince, flour, eggs and so on.

After trying HelloFresh, we decided to try out Dinnerly which markets itself as, “Australia’s most affordable home dinner kit” it’s actually owned by Marley Spoon, just a cheaper version for those who cannot afford Marley Spoon which is one of the more expensive options.

First Impressions

The ordering experience itself was smooth. Enter your details and then choose your meals, it’s a similar story to HelloFresh and presumably every other meal kit service out there.

The menu we were shown for the week we were ordering was a stark contrast to HelloFresh. The affordability aspect of Dinnerly is most of their meals have just six ingredients and basic ones.

We got a box with four meals, and two portions in each. We assumed like HelloFresh, the portions would be massive and feed my wife and I as well as our two young kids.

On the surface, this all looks great. I was particularly excited for the tacos and if you’re wondering why I rated them 1 star, keeping reading because I explain why further down.

You get what you pay for

Like anything in life, when you pay less you get less. With Dinnerly the meals are the kinds of things that anyone with a copy of Jamie Oliver’s cheap meal recipe books would expect to make. Chillis, curries and chicken/veg.

The first sign you have ordered a cheap meal kit is the packaging. This is no HelloFresh, the ingredients are kind of just thrown into the small box that ships to your door. Nothing is categorised by colour or any system, you have to dig through and find what you’re looking for.

Quality-wise, the produce just didn’t look that good. The vegetables and salads just looked less fresh than what you might find in a supermarket. Allegedly they come straight from the farm, which is maybe an acronym for some large freezer where they keep everything stored.

Our favourite meal by far was the parmesan meatloaf, it was a pleasant surprise given we are not big meatloaf eaters. It was actually a really nice meal, we had this on the first day. It was a nice introduction to Dinnerly, until the subsequent nights.

Weird pantry staples

Because you get less in the box, you’re required to provide more pantry staples beyond oil, salt and pepper. For the Chimichurri Chicken recipe, this is what the recipe asks you to provide; red wine vinegar, 1 garlic clove, honey and olive oil from the pantry. The Indian Halloumi Curry required; 2 garlic cloves, olive oil and tomato paste.

Perhaps the most demanding of all of the recipes in terms of pantry staples was the Beef and Parmesan meatloaves. This recipe required you to provide; 1 egg, olive oil, tomato paste, Worcestershire sauce and tomato sauce.

This is a recurring theme with Dinnerly. They might ship you 6 ingredient meals, but they require you to have another six ingredients in your pantry. The oil is a common staple, but tomato paste not so much.

I am looking at this through a distorted HelloFresh lens and with HelloFresh they required pantry staples as well, but never to this degree. At most HelloFresh required oil, butter and an occasional egg. Never tomato paste, tomato sauce or anything else. They also always provided garlic when needed.

The Ranchero Taco Incident 2020

This is the recipe we were looking forward to the most. After eating our way through the collection of so-so meals, the tacos seemed like the redeeming meal of the week (or so we thought).

After meticulously following the steps, as the mince was cooking a noticeable amount of fat was present. The recipe calls for 1 tsp of olive oil added to the pan before cooking the mince, we didn’t do that and it was a good call considering the pan was incredibly oily, it didn’t need any more.

The disappointment of these tacos emanated around the dining table. Our kids who love tacos and were excited for these as well barely ate any. My wife and I were similarly disgusted with the amount of fat dripping onto the plate.

There was so much oil on our plates, I was convinced that the USA was preparing to invade our dining room.

This incident really cemented that Dinnerly was not for us. We are not food snobs, we just don’t like being drowned in copious amounts of oil and meals that have some semblance of taste in them.

Maybe we got a bad box or maybe Dinnerly is so focused on cutting costs and being affordable they’re willing to send inferior meat and produce to their subscribers.

I was so disappointed I contacted Dinnerly to let them know of my disappointment and frustration. I felt misled, these tacos were meant to taste good, how hard is it to make tacos? While they apologised, they said they would pass on my feedback to the “culinary team” which is probably code for, “We’re not going to do anything”

We will not be paying to try Dinnerly again. I wouldn’t recommend Dinnerly to my friends, family or even my enemies. It was subpar and disappointing, really not that much cheaper than HelloFresh. Save your money and get a HelloFresh box instead or just buy your own ingredients, your chances of disappointment will be so much lower.

How To Develop A Seedable Dice Roll/Number Guess In JavaScript

Recently whilst working on some blockchain specific code, I needed to write a random number generator to simulate generating a range of numbers, except it needed to be predictable. The same input values produce the same output when provided.

In my case, I used values from immutable blockchain data such as the blockchain number, reference block number and transaction ID. I then allow the user to provide a client seed and generate a unique server seed on each roll as well.

For this, we will use the tried and tested and ever-versatile Seedrandom library by David Bau. It provides a wide variety of different algorithms for producing random numbers.

In this post, we won’t do anything outside of the norm. We will just use the default algorithm which for most purposes does what you would expect it to do.

For this example, we are going to assume the random number generator lives on the server in a Node.js environment. This would also work in a browser, but when generating numbers for a game or any serious application, you would never do it server side.

Firstly, make sure you install the seedrandom package by running: npm install seedrandom

const seedrandom = require("seedrandom");

const rng = (seed1, seed2) => {
  const random = seedrandom(`${seed1}${seed2}`).double();
  const randomRoll = Math.floor(random * 100) + 1;

  return randomRoll;
};

The seedrandom method accepts a seed string. This value produces a deterministic result, meaning if our rng function above is provided the same values for seed1 and seed2, the result is the same.

We then use Math.floor to take our random number and multiply it by 100 (the largest number we want to allow) and plussing it by one means the number starts at 1 instead of 0. This will produce a number between 1 and 100. You can change these values to suit.

For example, if you wanted to generate a number between 1 and 2 (for some kind of seedable coin flip) you would do something like this:

const randomRoll = Math.floor(random * 2) + 1;
const headsOrTails = randomRoll === 1 ? 'heads' : 'tails';

You can make your seed as long as you like. I highly suggest allowing the user to provide their own client seed as well as randomly generating a client seed which you reveal to the user after the fact.

With all of these values, users should be able to produce the same result independent of your site, this results in a provably fair algorithm for producing numbers.

A working code sample of what we did above can be found here on Codesandbox.

COVID-19 Remote Is Not Working Real Remote Work

Globally, many of us are all in the same unfortunate and unprecedented situation because of the Novel Coronavirus COVID-19. I am fortunate to both work in an industry where I still have a job and for a company mostly unaffected by COVID-19.

Sadly, for many, this is not the case as people find themselves out of work through no fault of their own. For others, they find themselves working remotely; for many, it’s their first time.

With many countries in some kind of lockdown, unnecessary travel has meant we can only leave the house for essential purposes like food and exercise. It’s a difficult time for everyone for a multitude of reasons.

I have been fortunate to already work remotely for the last two-and-a-half years. Working remotely is not a new experience to me, but working remotely during the COVID-19 pandemic is a unique and trying experience.

I want you to know as someone who worked remotely before this, that if you’re finding remote work difficult right now, this is not what is usually looks like. It’s not this difficult or stressful; it’s terrific if done right.

I am not the most outgoing person in the world, but not being able to go out for dinner, to a Cafe, for a nice breakfast somewhere or catch up for a beer with a friend. You do not realise you are more social than you are until you can’t be.

Right now, there is no separation of work and life. We work at home, and then we stay at home. We sleep and wake up at home, and we work at home. The need to run errands and other non-essential activities have taken a backseat for us all for the time being.

We are all stressed. We’re currently experiencing COVID-19 news fatigue, distant from friends and family. For those of us who have kids, they’re probably at home and causing some new logistic problems to work around.

For many suddenly forced to work from home, it sucks for you right now. Many are probably begging to go back into the office and have some kind of colleague interaction. The situation you find yourself in right now is not remote work; this is self-imprisonment. People shouldn’t be forced to work remotely, merely given the option to take it or leave it.

For our family, we have two young kids at home. My wife is studying to be a nurse, and she relied on our 4.5-year-old energetic sun going to kindy so she could study and complete all of the extra subjects she took on to finish her degree faster. All of a sudden, he is home, and our 1.5-year-old daughter exploring cupboards and draws is as well.

The house is chaotic at the best of times, sometimes it’s Armageddon as our son, in particular, is used to playing with other kids, playing on the playground or doing things outside. He loves the science centre and Dreamworld theme park, both of which are not possible right now.

Don’t let this pandemic warp your perspective or make you think that working remotely is always this stressful and terrible; it’s not. When all of this passes, I hope many give it another go and realise that working from home during a pandemic versus not working during a pandemic are two different experiences.

If you are struggling to work remotely right now, that’s to be expected given the circumstances. But, when things go back to normal (whenever that is) you will appreciate the flexibility and cost-savings of working remotely versus an office and commute.

Times are tough for everyone right now. We will get through this.