How To Fix HiveJS AssertionError “Expected version 128, instead got 149” and “Expected version 128, instead got 38”

If you are trying to use any methods in the HiveJS client which require the use of a private key, you might have encountered one or both of these errors.

In my case, I was using the memo encode method which takes a private key as the first argument, unfortunately, pass it the wrong key and you’ll get a non-helpful AssertionError about an expected version.

You’re seeing the error because you’re providing the wrong key. If you get the error, “AssertionError: Expected version 128, instead got 38” it means you are trying to use a public key when you need to use a private key.

In my instance, the error, “AssertionError: Expected version 128, instead got 149” was because I was attempting to use my account password instead of my private memo key to encode the memo string.

These errors really need to be changed to be more helpful, right now they’re as cryptic as the functionality itself.

Forget CSS-In-JS: Combine Sass With CSS Modules Using Webpack

I really dislike the CSS-In-JS trend. Nothing against anyone who is a fan, but writing CSS inside of Javascript doesn’t feel natural and honestly, it’s just an unnecessary abstraction. I understand why it became a thing, but the problems CSS-In-JS promises to solve have already been solved thanks to CSS Modules and Shadow DOM.

As usual, the front-end development community are focused on tooling and not on the end-user experience. Numerous benchmarks have proven CSS-In-JS can introduce performance issues into your application.

For cross-platform development, I will not dispute CSS-In-JS solutions can be useful, but many of us only target one platform most of the time. The thought of having to write components for even the most simple of UI tasks sounds daunting.

I am a big fan of using CSS Modules in my projects. They solve the naming issue in CSS giving you the same result as something like Styled Components, only you get to write CSS inside of CSS files. In combination with a pre-processor, even better.

Separating module and non-module SCSS

When using CSS Modules in your application, it is considered best practice to separate your module and non-module CSS styles. If you treat all CSS/SCSS as a CSS Module, when working with third-party packages with CSS/SCSS such as Bootstrap, you will run into problems.

I like to treat all CSS/SCSS as non-module by default. For CSS Modules, you want to specifically opt-in to use the modules functionality. This way you can have traditional global CSS and when you want localised component styles, you opt-in.

For module styles I like to use the .module.scss or .module.css naming convention. Inside of my components I will do something like this:

import styles from './mycomponent.module.scss';

In my case, I am using autoprefixer as well as cssnano to add browser prefixes and de-duplicate my CSS styles when imported. Your webpack.config.js configuration might look slightly different to this, alter to your taste.

Define the loaders

const cssModuleRules = [{
        loader: 'css-loader',
        options: {
            importLoaders: 2,
            sourceMap: true,
            modules: {
                localIdentName: '[name]__[local]____[hash:base64:5]',
            },
        }
    },
    {
        loader: 'postcss-loader',
        options: {
            plugins: () => [
                require('autoprefixer')(),
                require('cssnano')()
            ]
        }
    }
];

const cssRules = [{
        loader: 'css-loader'
    },
    {
        loader: 'postcss-loader',
        options: {
            plugins: () => [
                require('autoprefixer')(),
                require('cssnano')()
            ]
        }
    }
];

We have two CSS Loader configurations here, one for CSS Modules and one for standard CSS.

The following loader configurations going inside of the module rules property.

{
    test: /\.css$/i,
    use: extractCss ? [{ loader: MiniCssExtractPlugin.loader }, ...cssRules] : ['style-loader', ...cssRules]
},
{
    test: /\.scss$/,
    exclude: /\.module\.scss$/,
    use: extractCss ? [{ loader: MiniCssExtractPlugin.loader }, ...cssRules, ...sassRules] : ['style-loader', ...cssRules, ...sassRules],
},
{
    test: /\.module\.scss$/,
    use: extractCss ? [{ loader: MiniCssExtractPlugin.loader }, ...cssModuleRules, ...sassRules] : ['style-loader', ...cssModuleRules, ...sassRules]
}

We have a CSS rule for being able to deal with standard CSS, not using modules. Then we have a scss rule for non-module scss styling. And lastly, we have a rule for module styles using our CSS Modules configuration.

If you wanted to use CSS Modules with standard CSS, you could easily add another rule testing for .module.css to allow that as well.

That is all there really is to it. Now, you have CSS Modules allowing locally scoped CSS that will have randomly generated class name strings, allowing you to write specific CSS without global naming conflicts.

The Australian CovidSafe App Doesn’t Even Work On iOS Properly

And the government wonders why people were sceptical of the CovidSafe rollout (besides the very real safety concerns). It seems the CovidSafe rollout is flawed, with the discovery that the iOS version doesn’t even work properly.

Software developer Joshua Byrd recently posted his findings on Twitter and they’re pretty damning. Basically, the app will only ever work in the foreground with the screen on for iOS users.

On a technical level as explained in further Tweets, the phone will not broadcast UUID’s unless it is open. Coincidentally, the same issue was reported with Singapore’s app which CovidSafe is based upon and seemingly, nobody learned their lesson from.

Basically, unless you are aware of the power saving mode which just makes you leave the app open in your pocket upside down meaning you can’t use any other apps, the app itself is useless for a majority of iOS users.

Apple and Google have been working on their own OS level contact tracing API’s and presumably, it would be in the interest of the Australian government to migrate over to these API’s asap. Not only from a technical perspective, but also to alleviate privacy concerns users have over the app being used in the future as a surveillance tool.

Why Is Voat Still A Thing?

Remember Voat? The non-censored alternative to Reddit that saw an influx of users in 2015 after Reddit started cleaning up its house a bit and claims of censorship became a hot button issue that drove people away from Reddit.

The site has now become an anti-vaxxer, conspiracy theorist platform that resembles an uncontrollable raging dumpster fire. Although to be fair, the site was always teetering on the edge even in the beginning.

After Reddit started banning subreddits such as those dedicated to PizzaGate, many moved over to Voat. And when the whole QAnon thing came to be and Reddit subsequently banned that community, they also moved to Voat.

As you can see, Voat sure knows how to attract the right people to its platform. I haven’t been to the site in years, so it was an interesting experience to go and see what constitutes front-page material these days and well, the screenshots speak for themselves.

Given the COVID-19 pandemic is a hot button issue right now, it is not unexpected to see a tonne of paranoid conspiracy theories surrounding vaccinations and COVID-19.

My question is, how is Voat even still alive? Many of its subverses (sub communities) seem to be completely dead like /v/javascript and the only ones that seem to be thriving are the conspiracy theory sub communities.

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.