Filter a csv file with nodejs streams

So we have a CSV file with a member list and we want to filter all empty emails.


With nodejs streams this is almost a one liner.

We will use the csv package from the CSV project which has some sophisticated packages to parse and transform csv data with nodejs streams.

npm install csv

We will further use node as ESM (ECMAScript modules) to be shiningly modern and so lets create a file: index.mjs
Note the .mjs extension, which will tell node to interprete this as ESM. (Since nodejs v12.20.0 && v14.13.0)

We import the packages and create the filesystem streams to read the file, then built a pipeline with the streams and the single steps to process the data and write the results into a new file.
Ok let’s go:

Continue reading “Filter a csv file with nodejs streams”

Migrating user table from Mysql to Postgres with Symfony and Doctrine

When using bin/console make:entity on Mysql and then later you switch your application to Postgres and you have a table called user, which you most likely have when using security component of Symfony.
Then you will receive an error because user is a reserved word in Postgres!

An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "", "[]", "your-encrypted-password", 0]:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"
LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...

Continue reading “Migrating user table from Mysql to Postgres with Symfony and Doctrine”

Recreate pruned docker networks with docker-compose

So here is nice chain of docker errors and its solution.

1. Docker has reached its maximum of created networks and errors like this:

ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

The easiest (and most brute though) solution to this is to prune all networks, as suggested here on SO.

docker network prune

This will delete all networks that are not connected to currently active containers.
But this also means it will delete all networks of your not runnning dev projects.
(Which might be numerous as in my case.)

Continue reading “Recreate pruned docker networks with docker-compose”

Migrating from gulp to esbuild

Esbuild is the new cool kid in the bundler world.
It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development.

So i wanted to try it myself and migrated a former gulp build to esbuild.

But as it showed the gulp build was not so modern, as it was just Sass and Javascript minification. No ES6, No React, no JSX with inline styles.

So Esbuild was not working out of the box but needed some extra config and the Sass plugin.

npm i -d esbuild esbuild-plugin-sass

Also I had to rewrite the Javascript to use ES6 modules, but this was fortunatly easy.

Continue reading “Migrating from gulp to esbuild”

Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated

You might encounter this deprecation message after your upgrade to symfony 5.1 in your symfony project:

Since symfony/dotenv 5.1: Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated, use “Dotenv::usePutenv()

To fix this, go to config/bootstrap.php and remove the false from the Dotenv constructor:
(new Dotenv(false))->loadEnv(dirname(DIR).'/.env');
(new Dotenv())->loadEnv(dirname(DIR).'/.env');

Actually the file config/bootstrap.php has been removed from symfony 5.1 and was replaced in public/index.php.

But since the project was updated from an symfony 4 version the bootrap file is still present.

So another option would be to remove the boostrap file and update the project entirely to symfony 5.1 recipe.
This is not trivial though as you can see in this corresponfing PullRequest.

EU/VAT – Mehrwertsteuer Madness

Calculating European VAT Rates with PHP – the easy way.

Disclaimer: No legal advice, just a little experience report.

If you sell digital things (services, digital goods etc.) to EU countries, you might have to calculate the VAT at the rate of the customer’s country (and even pay it there afterwards).
The latter is even the more inconvenient part, but at least the first part can be done quite easily with good old PHP.

Continue reading “EU/VAT – Mehrwertsteuer Madness”

Docker-compose and Unknown MySQL server host

In case you encounter this error with mysql and your docker-compose setup:

Unknown MySQL server host <mysql-service-name>
Code language: HTML, XML (xml)

… and you dont know why because everything seems to be correct.

Then you might have an upgrade problem with mysql because you are reusing an old volume that was created for another mysql version.
This can happen when you use a unspecified tag as mysql:latest (not recommended anyway) and there was a version bump in the official mysql image.
Or you upgraded the mysql container yourself, f.e. from mysql:5.6 to mysql:5.7 and you are reusing the data volume with the mysql files.

Continue reading “Docker-compose and Unknown MySQL server host”

Psalm Static Analyzer fails with Symfony’s builtin preloading file

So i updated a symfony app the other day to version 5.1.6 and suddenly the static code analyzer psalm ran appearently in an hangup loop and never terminated.

After some investigation it showed that symfony added a .preload.php file to the src directory to enable the new PHP7.4 preloading feature.

Unfortunatly psalm parsed this file and followed all includes.
This took it so long that i took it for an endless loop.

There is some discussion in symfony github issues about this and the conclusion was to replace src/.preload.php with config/preload.php which happens now in a recipe.

Continue reading “Psalm Static Analyzer fails with Symfony’s builtin preloading file”