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 / 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 turbo@1.4.0 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"

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

@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 February 3, 2024 18:01
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