Code snippets

You will find here 31 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.

This snippet shows how to enable the HTML design mode on the fly in the browser with JavaScript. You must open the browser console...

JavaScript

Published on 2024-03-24 • Modified on 2024-03-24

 View the code


This snippet shows how to display the status code of the last executed command in the terminal. It can be helpful in shell scripts...

terminal

Published on 2023-10-21 • Modified on 2023-10-21

 View the code


This snippet shows how to execute a given Make target inside a target. When you want to run a target before another, you can put a...

make

Published on 2023-03-15 • Modified on 2023-03-15

 View the code


This snippet shows how to anonymize an IP address with Symfony. We can use the IpUtils class which handles both V4 and V6 addresse...

Symfony

Published on 2022-10-23 • Modified on 2022-10-23

 View the code


This snippet shows how to compare two DateInterval objects. We can't directly use the spaceship operator on DateInterval objects o...

PHP

Published on 2022-07-13 • Modified on 2022-07-13

 View the code


In this snippet, we see how to use the Abstract geolocation API with the Symfony HTTP client. I use a factory to create the clien...

Symfony

Published on 2022-02-01 • Modified on 2022-02-01

 View the code


In this snippet, we see how to test if a block in a Twig template exists. It's sometimes helpful to know if one of the parent temp...

Twig

Published on 2021-05-22 • Modified on 2021-05-22

 View the code


In this snippet, we see how to get the current environment in a Twig template with Symfony. This is simple to do thanks to the twi...

Twig

Published on 2021-05-05 • Modified on 2021-05-05

 View the code


It's something to know about Yarn. When running install (when a previous install has already be done), it doesn't check that every...

yarn

Published on 2021-02-17 • Modified on 2021-02-17

 View the code


In this snippet, we will see how to use the JavaScript Fetch API asynchronously. Open your JavaScript console and click on the "fe...

JavaScript

Published on 2020-10-25 • Modified on 2020-10-25

 View the code