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 / 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)&
@adrienjoly
adrienjoly / wait-for-js-server-ready-in-docker-container.sh
Created March 7, 2020 10:45
A script that runs a Node.js HTTP server in a container and waits until that server is ready, thanks to Docker Healthcheck.
#!/usr/bin/env bash
REPO_URL="https://gitlab.com/xxx/node_app-web.git"
PORT=3000
echo "Generate Dockerfile from ${REPO_URL}..."
cat > Dockerfile << CONTENTS
FROM node:10
WORKDIR /usr/src/app
RUN git clone ${REPO_URL} .
allHits=[];
algoliaClient
.initIndex(indexName)
.browseAll()
.on('result', ({hits}) => allHits.push(...hits))
.on('end', () => console.log(allHits));
@adrienjoly
adrienjoly / git-commit-stats-csv-without-deps-and-releases.sh
Last active June 16, 2023 12:32
Display `git diff` stats, one line per commit
git log --pretty=format:"@%ad ~~%s~~" --date=short --shortstat \
| tr "\n" " " \
| tr "@" "\n" \
| grep -v 'skip ci' \
| grep -v 'deps' \
| grep -v 'dependencies' \
| sed -En 's/ ~~.*~~ /,/p'
@adrienjoly
adrienjoly / extract-metadata-from-facebook-note-page.js
Created July 26, 2019 04:48
A script to paste into the js console of a Facebook note (i.e. blog post) in order to extract its meta-data
// copy and paste that script in the js console, from a facebook "note" url
permalink = $$('.mts a')[0];
[_, monthName, day, year] = new Date(permalink.innerText.split(' at ')[0]).toString().split(' ');
monthNum = {
Jan: 0,
Feb: 1,
Mar: 2,
Apr: 3,
May: 4,
@adrienjoly
adrienjoly / generate-html-with-colors-from-jest-test-results.sh
Created May 10, 2019 09:48
Generate HTML with colors from Jest test results
#!/usr/bin/env bash
# USAGE: ./generate-html-with-colors-from-jest-test-results.sh <file_name>
# => will create:
# - <file_name>.log (with color codes)
# - <file_name>-plain.log (without color codes)
# - <file_name>.html
FILENAME=$1
@adrienjoly
adrienjoly / list-squashed-and-merged-git-branches.sh
Last active April 2, 2020 14:54
List local git branches that were squashed and merged to master
# List local branches that were squashed and merged to master
$ comm -1 -2 \
<(git remote prune origin --dry-run | sed "s/^.*origin\///g") \
<(git branch | sed "s/^..//") \
| sed "/^$/d"
# List local branches that were squashed and merged to master
# ... then give you the opportunity to edit them before deleting them.
$ comm -1 -2 \
<(git remote prune origin --dry-run | sed "s/^.*origin\///g") \