information overload

by sebastian de deyne

The window.matchMedia API

5 Apr 2021

To execute a piece of code when the viewport is a certain size, the first thing that comes to mind is adding a resize event listener to the window object. This is one way, but not always the best. Sometimes the lesser known window.matchMedia API is a better fit.

Read more

Clearing personal data from inactive accounts

1 Apr 2021 via freek.dev

Freek wrote about cleaning up inactive user data from Oh Dear:

You want to keep only as little personal data as needed for privacy reasons. You should only collect and keep the absolute minimum of data needed to run your application. This keeps your user’s privacy safe and minimizes the risks for you as a company if a security breach happens.

This is a really good initiative, I can’t even imagine how much data I have scattered across hundreds of trial accounts on the internet…

Information Overload newsletter

I occasionally send out a dispatch with personal stories, things I'm working on, and interesting links I come across.

Only for occasional updates. No tracking.

The Record type in TypeScript

31 Mar 2021

I can’t count the amount of times I’ve defined an object type with unknown string keys and a specific value type.

type Scores = {
    [key: string]: number;
}

And despite using it all the time, I can’t for the life of me remember the [key: string] syntax.

Today, my problems are solved. Apparently TypeScript has a built in Record type that does exactly that:

type Scores = Record<string, number>;

Tim MacDonald on HasOne relationships in Laravel

30 Mar 2021 via timacdonald.me

I’ve used HasOne relationships for 1:1 relationships, but those are rare. I haven’t considered using them to scope down relationships, like having one default payment method in a set of n methods.

<?php

class User extends Model
{
    public function paymentMethods(): HasMany
    {
        return $this->hasMany(PaymentMethod::class);
    }

    public function defaultPaymentMethod(): ?HasOne
    {
        return $this->hasOne(PaymentMethod::class)
            ->whereDefault();
    }
}

$user->defaultPaymentMethod;

After reading Tim’s post, I have a feeling there are some places where I needed this but didn’t think of it at the time…

Antilibrary: the perfect excuse to buy more books

29 Mar 2021 via nesslabs.com

From Anne-Laure Le Cunff:

An antilibrary is a private collection of unread books. […]

The goal of an antilibrary is not to collect books you have read so you can proudly display them on your shelf; instead, it is to curate a highly personal collection of resources around themes you are curious about. Instead of a celebration of everything you know, an antilibrary is an ode to everything you want to explore. […]

An antilibrary creates a humble relationship with knowledge. It reminds us that our knowledge is finite and imperfect.

I have more unread books than read, and at some point I decided to stop buying books until I read more of the ones I owned.

After learning about the antilibrary, I lifted my own restriction and started to buy books again. The result: I’ve been reading more than ever.

Vite with Laravel

22 Mar 2021

I’ve had an eye on Vite for a while. With a stable release out the door (2.0, as 1.0 never left the release candidate stage) it seemed like a good time to give it a shot.

Vite is a frontend build tool like webpack. Instead of bundling development assets, Vite serves native ES modules transpiled with esbuild from the dev server. This means there’s a lot less bundling to do, and results in a very fast developer experience. For production builds, Vite uses Rollup to bundle the assets.

Read more

Self-deprecating comments

10 Mar 2021 via thepugautomatic.com

Henrik Nyh suggests to make comments more resilient to change with double-entry bookkeeping.

- $timeoutMs = 1000; // Equals 1 second
+ $timeoutMs = 1000; // 1000ms equals 1 second

Whether the discrepancy is caught immediately by the author, or in review, or by another developer far down the line, it will be explicitly clear that the comment was not intended for the current value.

This lowers the odds that a comment will get out of sync, especially useful in configuration files.

For more context head to Henrik’s blog, The Pug Automatic.