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 / cleanup-with-trap.sh
Last active January 10, 2022 14:25
Clean up with trap
#!/bin/bash
set -e # will stop the script if any command fails with a non-zero exit code
function cleanup {
./teardown.sh || true # keep tearing down, even if file does not exist
echo "🧹 Cleaned up."
}
trap cleanup EXIT
@adrienjoly
adrienjoly / fix-dyld-missing-symbol-called-errors-on-m1-macs.md
Last active April 28, 2025 08:29
Fix `dyld[]: missing symbol called` errors when running Node.js programs on M1 Macs (apple silicon)

Problem

If you're getting this kind of error when running Node.js programs with binary dependencies that don't support M1 yet, e.g.:

$ yarn test
dyld[51175]: missing symbol called
dyld[51176]: missing symbol called
@adrienjoly
adrienjoly / symmetric-encryption-with-gpg.sh
Created December 12, 2021 09:51
Commands to archive, encrypt and decrypt secret files using gpg's symmetric encryption.
TAR_FILE="secret-archive.tgz"
DEST_FILE="crypted-secret-archive.tgz.gpg"
# Archive
tar cvzf "${TAR_FILE}" ${SECRET_FILES_PATH}/*
# Encrypt
echo "${GPG_PASSPHRASE}" | gpg --batch --yes --passphrase-fd 0 -o "${DEST_FILE}" --symmetric "${TAR_FILE}"
# Decrypt
@adrienjoly
adrienjoly / before-deleting-a-local-git-repository.sh
Last active December 5, 2021 11:13
Commands to run in order to make sure that you're not going to delete changes or files that were not pushed yet to your remote git repository.
git fetch
echo "\nStashes:"
git stash list | cat
echo "\nLocal branches + their associated remote:"
git branch -vv | cat
echo "\nCommits not yet pushed, from all branches that are already on remote:"
git log --branches --not --remotes | cat
@adrienjoly
adrienjoly / github-actions-ci-with-sonarcloud.yml
Created October 25, 2021 09:30
Example of how to analyze code and send coverage report to SonarCloud from a GitHub Actions CI workflow.
# [...]
sonarcloud:
needs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting, cf https://sonarcloud.io/project/configuration?analysisMode=GitHubActions
@adrienjoly
adrienjoly / get-last-active-gcp-secret-revision.sh
Last active February 23, 2022 16:25
This script returns the value of the latest enabled revision of the requested GCP secret.
# This script returns the value of the latest enabled revision of the requested secret.
# Usage: get-last-active-gcp-secret-revision.sh <secret-name>
SECRET_NAME=$1; shift;
if [ -z ${SECRET_NAME} ]; then
echo "Error: please specify the name of the secret to get."
echo "Available secrets:"
gcloud secrets list
@adrienjoly
adrienjoly / nodejs-type-extensions.d.ts
Last active September 8, 2021 13:28
This shows how to type and extend Node.js-native's `process`
/// <reference types="node" />
declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV: 'development' | 'production' | undefined;
}
export interface Process {
env: ProcessEnv
@adrienjoly
adrienjoly / cache-docker-layers-on-github-actions.yml
Last active October 14, 2021 09:24
Cache Docker layers when (re)building a Docker image on GitHub Actions.
# source: https://github.com/docker/buildx/pull/535#issuecomment-869022231
e2e:
name: End-to-end tests against Docker containers
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: '1' # to enable persistent docker cache
COMPOSE_DOCKER_CLI_BUILD: '1' # so docker-compose commands benefits from buildkit/buildx's docker cache
steps:
- uses: actions/checkout@v2
@adrienjoly
adrienjoly / use-nvm-version-on-github-actions.yml
Created June 26, 2021 15:55
Use the expected version of Node.js on GitHub Actions, based on the project's .nvmrc file
steps:
- uses: browniebroke/read-nvmrc-action@v1 # Read node version from `.nvmrc` file
id: nvmrc
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: '${{ steps.nvmrc.outputs.node_version }}'
@adrienjoly
adrienjoly / extractTypeKeys.js
Created June 22, 2021 08:54
Node.js code to extract the keys of a TypeScript type programatically
const ts = require("typescript")
/**
* Extract the keys of a type defined in a .d.ts file.
* @param filename - name of the .d.ts file
* @param namespace - namespace where the type is defined
* @param typeName - name of the type
* @param options - options to pass to the TypeScript parser
* @returns an array of keys, expressed as strings
*/