Skip to content

Instantly share code, notes, and snippets.

Avatar

Adrien Joly adrienjoly

View GitHub Profile
@adrienjoly
adrienjoly / MakeReadOnly.ts
Last active Jun 25, 2020
TypeScript helpers
View MakeReadOnly.ts
// (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 Jun 18, 2020
A one-line node.js program to format JSON from a stdin stream, to include in bash scripts
View format-json-with-nodejs-one-liner.sh
$ 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 Jun 15, 2020
Quick tunnel connection using ssh password stored in bitwarden
View ssh-tunnel-with-key-from-bitwarden.sh
#!/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 Mar 7, 2020
A script that runs a Node.js HTTP server in a container and waits until that server is ready, thanks to Docker Healthcheck.
View wait-for-js-server-ready-in-docker-container.sh
#!/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} .
View algolia-browseall-index-from-dashboard.js
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 Sep 30, 2019
Display `git diff` stats, one line per commit
View git-commit-stats-csv-without-deps-and-releases.sh
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 Jul 26, 2019
A script to paste into the js console of a Facebook note (i.e. blog post) in order to extract its meta-data
View extract-metadata-from-facebook-note-page.js
// 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
Generate HTML with colors from Jest test results
View generate-html-with-colors-from-jest-test-results.sh
#!/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 Apr 2, 2020
List local git branches that were squashed and merged to master
View list-squashed-and-merged-git-branches.sh
# 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") \
@adrienjoly
adrienjoly / select-time-range-from-google-location-history.sh
Last active Apr 10, 2020
Select date/time range from Google Location History JSON, using jq
View select-time-range-from-google-location-history.sh
#!/usr/bin/env bash
# First, download "Location History" from https://takeout.google.com/settings/takeout?hl=en&gl=EN&expflags
# (fr: "Historique des positions" from https://takeout.google.com/settings/takeout?hl=fr&gl=FR&expflags)
#
# => Big "Location history.json" file that looks like that:
#
# {
# "locations": [
# { "timestampMs": "1546415889121" },
You can’t perform that action at this time.