Skip to content

Instantly share code, notes, and snippets.

Avatar
☺️
In the flow

Adrien Joly adrienjoly

☺️
In the flow
View GitHub Profile
@adrienjoly
adrienjoly / Dockerfile
Last active Aug 26, 2022
`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.
View Dockerfile
# 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 turbo@1.4.0 prune --scope='@myorg/api-server' --docker
@adrienjoly
adrienjoly / fastify-server-with-payload-validation.ts
Last active Aug 21, 2022
Fastify server with payload validation, using TypeBox and Ajv.
View fastify-server-with-payload-validation.ts
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 Apr 28, 2022
Generate the tree of callers of a TypeScript function.
View find-function-calls.ts
// 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"
View Shadow-pc-sur-chromecast-avec-google-tv.md

Juste un mot pour dire que – après quelques heures d’essais et bidouillages multiples – shadow marche très bien sur Chromecast avec Google TV ! 👌

Je viens de finir Mass Effect 2, branché sur un écran sans audio + sur un hub USB lui même connecté à la fibre via Ethernet, une manette Stadia et une carte son externe branchée sur mes enceintes.

Les trucs à savoir:

  • l’alimentation USB fournie avec le chromecast ne suffit pas à alimenter tout ça => il en faut un plus puissant
  • au premier démarrage, il faut qu’il n’y ait rien d’autre de branché sur le hub, sinon les périphériques seront ignorés => il faut les brancher une fois que le chromecast a fini de démarrer
  • Windows est galère à utiliser sans clavier, mais ça reste possible: utiliser la télécommande du chromecast pour (via le menu de l’app shadow) afficher/cacher le bureau, puis activer le clavier pour presser la première lettre de l’icône du bureau à lancer, puis la touche entrée pour confirmer, enfin fermer le clavier.

Fonctionnalités qui me manquent

View cleanup-with-trap.sh
#!/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 Oct 5, 2022
Fix `dyld[]: missing symbol called` errors when running Node.js programs on M1 Macs
View fix-dyld-missing-symbol-called-errors-on-m1-macs.md

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 Dec 12, 2021
Commands to archive, encrypt and decrypt secret files using gpg's symmetric encryption.
View symmetric-encryption-with-gpg.sh
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 Dec 5, 2021
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.
View before-deleting-a-local-git-repository.sh
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 Oct 25, 2021
Example of how to analyze code and send coverage report to SonarCloud from a GitHub Actions CI workflow.
View github-actions-ci-with-sonarcloud.yml
# [...]
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 Feb 23, 2022
This script returns the value of the latest enabled revision of the requested GCP secret.
View get-last-active-gcp-secret-revision.sh
# 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