Skip to content

Instantly share code, notes, and snippets.

View arnaudrenaud's full-sized avatar

Arnaud Renaud arnaudrenaud

  • Freelance
  • Paris, France
View GitHub Profile
@arnaudrenaud
arnaudrenaud / articles.json
Last active May 17, 2019 14:16
Articles – sample data
{
"articles": [
{
"id": "3B8A9F8D-8E8D-43D6-BCB8-E136D3AD279D",
"title": "A journey through internet garbage"
},
{
"id": "85D4407D-496C-43BD-9B4D-93B6064B76EA",
"title": "The Cost of Fixing Things"
},
@arnaudrenaud
arnaudrenaud / index.js
Created June 28, 2019 15:59
Jest inline snapshots example
const parseDate = (year, fullDate) => {
if (!year) {
throw new Error('arg year is missing');
}
if (!fullDate) {
return new Date(year);
}
return new Date(fullDate);
};
module.exports = parseDate;
@arnaudrenaud
arnaudrenaud / README.md
Last active July 8, 2021 12:00
Mise en place d'une base de données Postgres

Vérifiez si Postgres est installé sur votre ordinateur :

psql --version

Sinon, installez Postgres.

Lancez la console Postgres en tant que l'utilisateur postgres :

@arnaudrenaud
arnaudrenaud / convert-jpgs-to-smaller.sh
Last active April 11, 2023 18:47
Batch convert videos to 1280x720 H.265
convert *.jpg -resize 50% -set filename:f '%t' smaller/'%[filename:f].jpg'
@arnaudrenaud
arnaudrenaud / app-production.md
Last active April 20, 2024 12:05
Cheatsheet: Prepare your web service for production

Prepare your web service for production

With examples for Node.js services managed with Docker Compose:

  • Make sure you can start each service in non-watch production mode (npm run build followed by npm run start instead of npm run dev)
  • Use environment variables to disable API introspection and debug-level logging (NODE_ENV=production)
  • If services are containerized, expose them to each other on an internal network, leaving only one gateway exposed to the host (in docker-compose.prod.yml, use expose for internal services and ports only for the gateway)
  • Run host-exposed services on a variable port to avoid conflict with other services that may run on the server (if your services are containerized, only the gateway needs a variable port: GATEWAY_PORT=8000)
  • Run the app in background mode to avoid keeping the shell busy (docker compose -f docker-compose.prod.yml up --build --detach)
  • Mark services with restart: always so that Docker will restart them automatically (after a reboot
@arnaudrenaud
arnaudrenaud / set-up-ufw-firewall-linux-web-server.md
Last active April 20, 2024 12:41
Cheatsheet: Set up UFW firewall on a Linux web server

Set up UFW firewall on a Linux web server

For reference: https://www.webservertalk.com/ubuntu-firewall-how-to-configure-ufw/.

Run the following:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22 # ⚠️ Replace by your actual SSH port (22 by default) — otherwise, SSH access will be lost after reboot!
@arnaudrenaud
arnaudrenaud / linux-web-deploy.md
Last active April 24, 2024 09:15
Cheatsheet: Deploy a web service on a Linux server

Deploy a web service on a Linux server

Before deploying your app, make sure it is ready for production (cheatsheet here).

With example commands for Ubuntu:

Make server secure

  • Provision a Linux server (for example, a virtual private server from DigitalOcean or OVH)
  • Log in with SSH as default user: ssh ubuntu@<hostname>
@arnaudrenaud
arnaudrenaud / txt-to-srt.js
Last active April 24, 2024 14:10
Generate subtitles SRT file from raw text file
const { readFileSync, writeFileSync } = require("fs");
function getFormattedTime(timeMilliseconds) {
return new Date(timeMilliseconds).toISOString().substring(11, 23);
}
const REPLACEMENT_PROBABILITY = 0.01;
const REPLACEMENT_CHARACTERS = "✴⦧⦖";
function getRandomlyReplacedText(text) {
if (REPLACEMENT_PROBABILITY === 0) {
@arnaudrenaud
arnaudrenaud / performance.js
Last active April 24, 2024 14:10
Measure execution time in Node.js
const { performance } = require("perf_hooks");
const start1 = performance.now();
JSON.stringify({ emailAddress: "arnaud.renaud@gmail.com" });
const end1 = performance.now();
console.log(
`Time taken to execute JSON.stringify function is ${end1 - start1}ms.`
);
const start2 = performance.now();