oooops.dev

DevOps is hard

Serializing and de-serializing ES6 class instances recursively — September 30, 2022

Serializing and de-serializing ES6 class instances recursively

We have all been warned not to use ES6 classes. Perhaps by our colleagues, or perhaps by the endless amount of scary blog posts that show up if you dare Google the subject. However, if you thought you had a use case for them you might have used them anyway (or perhaps you are in too deep and cannot rewrite your entire codebase). And now you stumbled upon this serialization problem and need to quickly find a solution that isn’t “just use TypeScript instead”.

The gist of it is: JavaScript is not a typed language, although sometimes it is pretending to be. When we make use of type-y features like classes and interfaces, some behaviors might occur that are be a bit puzzling if you are coming from, say, Java or Kotlin. One such behavior is how class instances get converted to and from JSON.

Or rather, how they don’t.

Continue reading
Visualising distance from the main sequence and other Clean Architecture metrics in Java — February 21, 2021

Visualising distance from the main sequence and other Clean Architecture metrics in Java

Image result for clean architecture zone of uselessness

I must not have been the only one to read “Clean Architecture” by Uncle Bob (Robert Martin) and be immediately sold on the abstractness, instability, coupling and main sequence metrics.
I must not have been the only one to immediately Google for tools to generate them for whichever codebase I happened to be working on at the moment, anxious to see if my refactoring instincts could be backed by a pretty diagram.
And yet, based on the very disappointing (lack of) results, it seems like that might be the case.

There are a few tools for the job yes, but they are clunky to run at best, and they definitely do not produce a visual output to quickly get insights from.

After hours of tinkering and getting a result, I thought I would share and write this guide for others like me who might have gone through the same experience. Hopefully it will spare some time to the next person.

Continue reading
The same code with Callbacks vs Promises vs Async/Await — February 13, 2021

The same code with Callbacks vs Promises vs Async/Await

Sometimes in JavaScript to have to deal with different flavours of asynchronous code, so it is handy to be able to map back and forth between them.

Callback

Functions that do something asynchronously are typically implemented using the callback pattern, and their implementation might look like this:

const myAsyncFunction = (parameter, callback) => {
    const result = //do something async here...
    callback(result, error);
};
Continue reading
One line Bash HTTP Server — January 16, 2021

One line Bash HTTP Server

Here is a quick snippet I use all the time when I want to set up an HTTP server on the fly, without leaving the comfort of my terminal.

This is the command:

$ while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; echo "Hello World"} | nc -l 3000; done

Warning: this will block your current terminal.

You will see the following output as you receive requests:

GET / HTTP/1.1
Host: localhost:3000
User-Agent: curl/7.54.0
Accept: */*

If you want your terminal back, or for any other reason want to put the command in the background while it is running, simply press ctrl+z.

When you are done and want to kill the background process, you can do so with

$ kill %1
Super Quick Node.js HTTP Server —