Einenlum.

This Week I Learned: 2022W36

Wed Sep 14 2022

After a few weeks of holidays, I’m back! :)

CSS

You can now control how the page breaks during scrolling only with CSS (no Javascript needed), thanks to scroll-snap-type and scroll-snap-align. Source here .

Randomness

The pseudorandom number generator used by PHP, Python, Ruby, Matlab or Excel is the same. It’s called Mersenne Twister . I still struggle to understand 1% of the Wikipedia article because of my total lack of Math knowledge.

Airtags - Apple - Privacy

I just heard about Airtags . Supposedly launched to help you find your keys or other items. It seems like it has been used for malevolant purposes. You can check this Guardian article here . I find it really disturbing.

Git

Git History allows you to easily see the changes in a Git file. Just replace github (or gitlab) in the URL with githistory.xyz. For example: This Symfony file and its history . Obviously doesn’t work with private repositories, but quite interesting! I like the visual representation.

Partial - Currying

When diving into the Python functools module, I realized I stumbled upon the partial function. I was a bit confused because I thought partial was the same as currying.

It seems it’s two different concepts (even if it’s still quite narrow to me).

You can check an article about the differences here .

PHP - Partial Function Application

There is no way to easily make a partial function in PHP. An RFC was proposed but was rejected.

If you want to achieve it, you will need to create your own partial application. One implementation example:

<?php

function add(int $x, int $y, int $z) {
    return $x + $y + $z;
}

function partial(callable $fn, ...$args) {
    $newCallable = function (...$newArgs) use ($fn, $args) {
        $finalArgs = array_merge($args, $newArgs);

        return $fn(...$finalArgs);
    };

    return $newCallable;
}

$add2 = partial(add(...), 2);
$add3 = partial($add2(...), 1);

$add3(2); // 5

Here we use the (...) notation, introduced in PHP 8.1 .

Feed