Skip to content

Instantly share code, notes, and snippets.

View adrienjoly's full-sized avatar
☺️
In the flow

Adrien Joly adrienjoly

☺️
In the flow
View GitHub Profile
@adrienjoly
adrienjoly / download-using-puppeteer-and-interceptors.js
Created June 19, 2023 08:30
Login and download a HTTPS response using Puppeteer and request interceptors.
// Note: this script does not work anymore on hackmd.io, because of recaptcha protection.
// But the same logic can be reused on other websites, e.g. for backup automation.
const puppeteer = require("puppeteer");
const { DEBUG } = process.env; // for verbose request logs, pass DEBUG='*'
/** @returns a `untilRequest()` method that resolves when `targetURL` is requested by `page`. */
const interceptRequests = async (page) => {
await page.setRequestInterception(true);
@adrienjoly
adrienjoly / run-npx-with-specific-nodejs-version-thru-nvm.sh
Last active June 19, 2023 08:02
Run a node.js CLI from a github repository, using a specific version of Node.js installed locally with NVM. Addresses `nvm: command not found` error, when `nvm` is invoked from a bash script.
#!/usr/bin/env bash
# Run index.js (or the script specified in package.json's "bin" entry)
# from https://github.com/adrienjoly/notion-backup,
# with the version of 18 of Node.js, installed locally with NVM.
NODE_VERSION=18 ~/.nvm/nvm-exec npx --yes github:adrienjoly/notion-backup
# Why you may need this?
# - If, like me, you have not setup a default version of node.js, on NVM.
# - If you don't want to (or can't) include a `.nvmrc` file.
@adrienjoly
adrienjoly / template-audit-capacités-devops-dora.md
Last active August 23, 2025 10:02
Template que j'utilise pour auditer mes client sur les "capacités DevOps" proposées par le DORA, et leur donner des recommandations pour progresser. C'est en markdown => importable facilement dans Notion.

Audit Capacités DevOps/DORA

Le livre "Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing Technology Organizations" (Gene Kim, Jez Humble, and Nicole Forsgren, 2018) s'appuie sur 5 ans d'études scientifiques pour faire ressortir les pratiques effectivement mises en oeuvre par les sociétés "tech" les plus performantes. (selon la classification de Westrum)

L'équipe de DORA (DevOps Research and Assessment) a identifié et validé un ensemble de capacités permettant d'optimiser les performances organisationnelles et celles de la livraison de logiciels. Ces articles décrivent comment mettre en œuvre, améliorer et mesurer ces capacités.

Source: https://cloud.google.com/architecture/devops/capabilities

Les capacités recommandées sont au nombre de 27, classés en 3 catégories.

@adrienjoly
adrienjoly / jest-test-each.spec.js
Created March 23, 2023 08:56
ways to use Jest's test.each
describe("ways to use Jest's test.each", () => {
test.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
expect(a + b).toBe(expected)
})
@adrienjoly
adrienjoly / cypress.config.ts
Created March 11, 2023 11:02
Logging from Cypress E2E tests, for better troubleshooting
import { defineConfig } from 'cypress'
const cypressConfig = defineConfig({
video: true,
chromeWebSecurity: false,
e2e: {
baseUrl: 'http://localhost:3000',
supportFile: 'cypress/support/e2e/index.js',
setupNodeEvents(on, config) {
require('cypress-terminal-report/src/installLogsPrinter')(on, {
@adrienjoly
adrienjoly / pull_request_template.md
Last active February 6, 2023 17:55
to store in your GitHub repository, in: `.github/PULL_REQUEST_TEMPLATE/pull_request_template.md`

Fixes / contributes to Issue #XXXX.

🎯 Problem / Objective

TODO

💡 Proposed solution

TODO

@adrienjoly
adrienjoly / escape_single_quotes_from_first_line.sh
Last active January 25, 2023 17:57
This script extracts the first line from stdin, then escapes single quotes, so it can be safely passed as an argument.
# This script extracts the first line from stdin,
# then escapes single quotes, so it can be safely passed as an argument.
# get first line from stdin
FIRST_LINE=$(cat - | head -1)
# escape single quotes
echo "${FIRST_LINE}" | sed -e "s/'/'\\\\''/g"
@adrienjoly
adrienjoly / Dockerfile
Last active October 23, 2022 12:34
`Dockerfile` to containerize a server from a Node.js/TypeScript monorepo, using Yarn 3 and Turborepo 1.4. Layers are optimized to reduce rebuild time, using the host's `.yarn` cache.
# Build from project root, with:
# $ docker build -t myorg-api-server .
# pruner stage: Only keep the source code that needs to be built
FROM node:16.16-alpine AS pruner
WORKDIR /app
COPY packages/ packages/
COPY .yarnrc.yml package.json turbo.json yarn.lock .
RUN npx [email protected] prune --scope='@myorg/api-server' --docker
@adrienjoly
adrienjoly / fastify-server-with-payload-validation.ts
Last active August 21, 2022 06:39
Fastify server with payload validation, using TypeBox and Ajv.
import Ajv from "ajv"
import Fastify from "fastify"
import type { TypeBoxTypeProvider } from "@fastify/type-provider-typebox"
import type { Static } from "@sinclair/typebox"
import { Type } from "@sinclair/typebox"
export const payloadSchema = Type.Object({
message: Type.String(),
})
@adrienjoly
adrienjoly / find-function-calls.ts
Created April 28, 2022 10:05
Generate the tree of callers of a TypeScript function.
// This script generates the call tree (a.k.a. call hierarchy, or dependency graph) of a function.
//
// Usage: $ npx node-ts find-function-calls.ts <target-file.ts> <target-function-name>
import util from "util"
import assert from "assert"
import * as ts from "typescript"
import * as tsmorph from "ts-morph"
import type { ReferenceEntry, Node, ReferencedSymbol } from "ts-morph"
import type { StandardizedFilePath } from "@ts-morph/common"