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 / 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
*/
@adrienjoly
adrienjoly / sonar-project.properties
Last active June 4, 2021 19:56
Analyse source code and get recommendations using SonarQube and Docker
# This configuration file is intended for local use of SonarScanner.
sonar.organization=mycompany
sonar.projectKey=myproject
# relative paths to source directories. More details and properties are described
# in https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
sonar.sources=.
sonar.sourceEncoding=UTF-8
sonar.inclusions=app/**/*.*
@adrienjoly
adrienjoly / MakeReadOnly.ts
Last active June 25, 2020 16:23
TypeScript helpers
// (from https://dev.to/busypeoples/notes-on-typescript-recursive-types-and-immutability-5ck1)
// Makes a deeply immutable version of Type, using recursion.
type MakeReadOnly<Type> = {
readonly [Key in keyof Type]: MakeReadOnly<Type[Key]>;
};
// Usage / Examples
const shape = {
@adrienjoly
adrienjoly / format-json-with-nodejs-one-liner.sh
Created June 18, 2020 14:40
A one-line node.js program to format JSON from a stdin stream, to include in bash scripts
$ echo '{"a":1}' \
| node -e \
"d=[];process.openStdin().on('data',c=>d.push(c)).on('end',()=>console.log(JSON.stringify(JSON.parse(d.join('')),null,2)));"
# =>
# {
# "a": 1
# }
@adrienjoly
adrienjoly / ssh-tunnel-with-key-from-bitwarden.sh
Created June 15, 2020 11:50
Quick tunnel connection using ssh password stored in bitwarden
#!/bin/bash
set -e
BITWARDEN_ENTRY_ID="TODO" # à remplir depuis `$ bw list items --search name_of_my_entry`
echo "🔒 getting ssh password from bitwarden"
bw get password ${BITWARDEN_ENTRY_ID} | pbcopy
echo "🔑 ssh password can be pasted for 10 seconds, from now"
(sleep 10; echo "🧹 clearing password"; echo -n '' | pbcopy)&