Dario Turchetto

Software developer.

Read this first

HTTP GET Bad Request

I hope this will be a time saver for some of you.

The Mozilla documentation (MDN Web Docs) defines HTTP response 400 Bad Request as such:

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Which is obviously the right definition but it may be a little vague. Practically speaking, this might mean that you’re trying to send a payload (body) to the server using a GET request.

This is technically not forbidden by the HTTP specification but some servers throw a Bad Request response when receiving a body within a GET request, so if you need to send the server some payload please consider using a POST request instead.

Continue reading →

Quarantine tip #1: stop checking your phone

I get it: the world is in lockdown, you’ve probably been sheltering in place for more than a month now and the only way to get in touch with your family and friends is through your phone or your tablet/pc. In times like these it’s important not to lose contact with the people you care about, they might be feeling lonely and a quick chat goes a long way to keep morale high.


If you want to make something out of this lockdown, besides saving lives just by staying at home (which doesn’t happen very often, I have to admit), you probably want to do something productive with your free time. Maybe you want to get the dust off some books that you bought years ago but never had the chance to read, or maybe you have a side project to work on, or you want to learn how to play an instrument… Whatever the items in your to-do list, it’s important to reserve some quality time for those activites...

Continue reading →

Quality is non-linear

A friend of mine, a hard-worker who had very high standards for his own work, told me a few years ago: “I don’t understand why people don’t polish the details of their projects, it only takes a few hours more to go from decent to good”.

I think I fall in the set of people who try to get a working version of what they’re doing as fast as possible and not spend a lot of time after that refining things (if it’s “presentable” then it’s usually good enough for me). Sometimes it’s pure lazyness because it’s true than a couple hours more would take the work on a whole different level, but from my experience that’s not typically the case.

I’m looking at this from a programmer perspective, but I would say there’s a kind of 80-20 rule at work here: if you already know what you’re doing, it usually doesn’t take much time to get a very basic version, but from there to a “presentable” version it...

Continue reading →

Design for errors

I’ve been recently working on the frontend of a web application, basically I had to add a tab to a tab panel and do some stuff there. One of the requirements was, of course, “be careful not to break the other tabs because they’ve been in production for some months now and the user is happy with those”.

So I got to work and when I had the basic skeleton of my new tab I opened the browser to test it. One of the first thing I’ve tried was randomly clicking on all the tabs to see if my tab would correctly reload the interface without glitches. But in doing so I noticed that the other tabs where showing some problems, so I thought I had broken something in the old code, although I barely touched it. I switched to the test environment (which didn’t have any of my changes) and did the same thing, which got me basically the same results.

So I opened the DevTools console to see what was going...

Continue reading →

Interviewing is hard

Interviewing people for technical positions is hard, we all know that. In fact, I’ve been knowing that for some time, mainly because I was reading about it in various blogs. What I didn’t realize was how much difficult it was until I had to be the guy asking the questions.

Fast forward a few years and there I am, sitting with a candidate in front of me, trying to understand if I want to be working with this guy for the next months or even years. The interview typically lasts about one hour, during which we give the candidate the time to explain us his background, what he’s looking for in a new job (even though the answer is pretty much always “to work on interesting projects and learn new stuff”); then we set off to ask some technical questions.

In our work environment, where we manage a couple of mission-critical web apps for a big bank, there are no particular separations between...

Continue reading →

Array left and right sums

Let’s consider the following problem:

You are given an array of N integers. Determine whether there’s an element x in the array such that the sum of the elements to the left of x equal the sum of the elements to its right.

The first solution that comes to mind is to iterate on the array, picking the item at index i, calculating the sum A[0, i - 1], the sum A[i + 1, N - 1] and checking their equality. This means that for every element of the array you need to do a pass of the whole array, which is N * (N - 1) operations, this resulting in a O( N2 ) time complexity.

Can we do better? Let’s say we try to limit the number of passes of the array and use some extra variables to keep track of the values that we need to compare. We do one pass to calculate rigthSum, which at the beginning will contain the sum of all the values of the array. We initialize another variable, leftSum, to zero.


Continue reading →

Fast JavaScript array concatenation

Suppose we want to write a concat() function in JavaScript that takes as input a variable number of elements, which can be either simple elements (like a number or a word) or arrays. We want that function to return an array that contains the concatenation of all the simple elements or arrays passed as input parameters.

First of all, we know we can iterate on the arguments implicit parameter, which is an array containing all the arguments passed as input to the function. As we said, each of these parameters can be a simple element or an array; thus we perform a check to determine the type of the element we are dealing with and, in the case of an array, we iterate on it.

Now, the important part. The easiest way to concatenate the elements would be to create an empty array and then call push() on it to insert every element at the end of it. The problem with this approach is that it forces...

Continue reading →

using f.lux

I was very skeptical at first about f.lux: I didn’t see how turning my display colors towards red could help my eyes be less strained while programming late in the evening. After some time I decided to give it a try and here I am, after four days, loving f.lux and testifying that it actually works.

What it does is very simple: it sets the colour temperature of your screen based on the current time. If it’s in the middle of the day you will see your display as you’re used to seeing it, with the usual color tones; but as time passes and the evening comes, your screen will begin to turn to red-ish tones, so gradually that maybe you’ll recognize only after a while.

That’s the magic of f.lux and the reason why it’s so effective: research has shown that blue light – such as the one emitted by your usual display – interferes with the normal sleep cycle and has the tendency of keeping you...

Continue reading →