My cool repositories

I’ve written during the past years some repositories. A lot of them are either private or have been deleted, but some of them (the better ones?) are still there, public.

I might shudder if I were to take a look at my old code, but some of those are actually pretty nice, mostly the ones that also became NPM libraries.

Here is a list in no particular order:

Et voila

This is also an NPM library.

It works by returning a promise that resolves when an element appears in the DOM that corresponds to a specific selector that the user gives.

I wrote it to use in a test where I needed to be sure that a modal had appeared before doing anything (in Puppeteer).

Run concurrent Batches

This is also an NPM library.

This one I did while trying to write a stress test on a website that could actually mimic a real browser behaviour: I wanted to test the server when a new user would load the page for the first time but also all of the assets (js/css/images/json).

In order to do so I wanted to be able to keep a number of open connections at the same time (let’s say 20) and then, whenever one of those would close, open a new one. This would happen for a specific amount of time, or until a number of requests had been done.

Therefore I wrote this small library that allows to keep N promises active and always open a new one each time one of the promises resolves until either some time has passed (and therefore repeating the same promise over and over) or an array of promises has been all used.

Look Around You

This does not actually work anymore, sadly.

Where I work we almost always start our frontend project with a boilerplate, that exposes on as default. I wrote this simple web application (only frontend) that would check in the LAN of the visitor if there was any other node of the network that exposed anything on a specific port, and in that case it would be shown in a rotating gallery of Iframes.

While it worked for a while, it used WebRTC to get the local IP of the user, but since late 2019 Chrome & Firefox have blocked this possibility (luckily, since it was not very safe). Now I’d have to try a lot of addresses, while when my own one was known it was as simple as testing all of the 255 - 1 neighbours.

Remote Camera

This one is still available online.

I’ve often found myself in the situation where I needed to take a selfie (never alone, usually with my wife) but also needed to put my phone away from me to include something in the picture. In those situations it’s never easy to check if the picture is right, and one needs to use a timer in order to capture the picture.

I decided to write that web application in order to be able to control from a second phone the camera one. This way I have more control over what is seen by the phone, and also I’m able to decide when to take the picture, or even when to start the timer.

I really thought it would prove to be useful, but I’ve seldom used it myself. I learned how to use WebRTC though, and a lot of other fun stuff.

A modest proposal

This one is still available online.

I wrote this one around march/april 2020, during the Covid pandemic. Here in Italy there was (still is) a problem with tests, as far too few were run. Since the ratio of positives vs negatives was really low, I thought that it could make sense to pool multiple people in the same test, in order to be able to check more people with less tests.

This website will simply show a Monte Carlo simulation of how much it would improve the number of people tested and the downside (more false positives) of a situation by changing the variables.

A few months later I found out that some countries have actually implemented this method, and it made me very happy to know that it actually made some sense.

Chunk by

This is also an NPM library.

It’s something that lodash is missing: it simply chunks an array in sub arrays by checking when an user given function returns true when applied to a growing chunk.

Whatsapp audio transcribe

Pretty sure this one does not work anymore.

It’s actually a 2 part repository: the first one is a bookmarklet, the second one is a small node server.

I hate audio messages. And I double hate them when I’m with other people around (like, when I’m working). Therefore I wrote this simple script that uses a bookmarklet to read the blob of an audio message from whatsapp web, send it to google cloud speech to text service and shows the transcription of the audio message.

You can actually read some of the more technic stuff here, suffices to say that it wasn’t too easy to be able to inject a js script so that it could access the audio blob.

Category Utility

This is also an NPM library.

This is simply the implementation in Typescript of the Category Utility clustering algorithm, useful to clusterize purely categorical datapoints.

Voronoi Creator

This is also an NPM library.

This is a really complex library that barely works, and on which I’d like to write a precise and more specific post. In a nutshell it generates a Voronoi diagram using as input the desired size of all of the cells, and uses a minimization algorithm to find a suitable solution.

Distance from Path

This is also an NPM library.

A simple library that given an SVG path and a point will return the closest coordinates on the path to the point and the distance between the two.

Kmeans ++

This is also an NPM library.

This is simply the implementation in Typescript of the Kmeans++ clustering algorithm.

Hue generator

This is also an NPM library.

After reading cool stuff on φ I either read or noticed that rotating around a circle adding each time a portion of the circle = φ would generate a sequence that maximises the distance between all of the points.

I decided then to use this sequence to generate color palettes (using the HSL colorspace) that would maximise the hue distance between colors.