Skip to content

Instantly share code, notes, and snippets.

View emeraldsanto's full-sized avatar

Yanick Bélanger emeraldsanto

View GitHub Profile
@emeraldsanto
emeraldsanto / presign-sts-get-caller-identity.ts
Last active June 26, 2024 16:09
Presign an AWS STS GetCallerIdentity request for later use, adapted to JavaScript from https://donchev.is/post/aws-lambda-invoker-identification
import { defaultProvider } from "@aws-sdk/credential-provider-node";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { Sha256 } from '@aws-crypto/sha256-js';
import { SignatureV4 } from "@aws-sdk/signature-v4";
import { stringify } from "qs";
async function main(): Promise<string> {
const signer = new SignatureV4({
credentials: defaultProvider(),
region: process.env.AWS_REGION,
@emeraldsanto
emeraldsanto / sum-compt-claims.js
Last active July 17, 2023 22:16
Script to sum the amount of all Compt claims
[...document.querySelectorAll('#past-expenses-table .td.small:nth-child(5)')].reduce(
(total, cell) => {
const amountWithCurrencyAsString = cell.innerHTML;
const amountWithoutCurrencyAsString = amountWithCurrencyAsString.slice(3); // $CA...
return total + parseFloat(amountWithoutCurrencyAsString);
},
0
);
@emeraldsanto
emeraldsanto / tf-cloud-debug-set-github-token.txt
Created March 10, 2023 17:03
Comparing two Terraform Cloud outputs when providing `owner` and `token` directly to the GitHub provider vs. as environment variables
Terraform v1.3.4
on linux_amd64
# ...
2023-03-10T02:59:18.165Z [DEBUG] provider.terraform-provider-github_v5.18.0: 2023/03/10 02:59:18 [INFO] Selecting owner my-org from GITHUB_OWNER environment variable
2023-03-10T02:59:18.168Z [DEBUG] provider.terraform-provider-github_v5.18.0: 2023/03/10 02:59:18 [INFO] Setting write_delay_ms to 1000
2023-03-10T02:59:18.168Z [DEBUG] provider.terraform-provider-kubernetes_v2.11.0_x5: 2023/03/10 02:59:18 [DEBUG] Enabling HTTP requests/responses tracing
# ...
-----------------------------------------------------: timestamp=2023-03-10T02:59:18.166Z-----------------------------------------------------: timestamp=2023-03-10T02:59:18.290Z
2023-03-10T02:59:18.304Z [DEBUG] provider.terraform-provider-github_v5.18.0: 2023/03/10 02:59:18 [DEBUG] GitHub API Response Details:
2023-03-10T02:59:18.304Z [DEBUG] provider.terraform-provider-github_v5.18.0: ---[ RESPONSE ]--------------------------------------
@emeraldsanto
emeraldsanto / find-k8s-service.sh
Created January 12, 2023 21:59
This script loops over your `kubectl` contexts and logs the ones where the given service is deployed.
#!/bin/bash
service_to_find=$1
context_list_as_string=$(kubectl config get-contexts -o name)
context_list=($context_list_as_string)
for ctx in ${context_list[@]}; do
if kubectl get deploy --context=$ctx | grep -q "$service_to_find"; then
echo "Found $service_to_find deployment in $ctx"
@emeraldsanto
emeraldsanto / vivaldi-theme-verdandi.json
Last active October 1, 2022 13:56
Vivaldi light theme inspired by the Verdandi VS Code theme.
{
"accentFromPage": false,
"accentOnWindow": true,
"accentSaturationLimit": 1,
"alpha": 1,
"backgroundImage": "",
"backgroundPosition": "stretch",
"blur": 0,
"colorAccentBg": "#d8edff",
"colorBg": "#f4f6f9",
@emeraldsanto
emeraldsanto / async-batch.ts
Created February 26, 2022 17:39
Utility function to sequentially run batches of async operations with configurable concurrency.
/**
* Allows for sequentially running batches of async operations.
* @param {number} concurrency The maximum number of operations to run concurrently.
*/
export function batch(concurrency: number) {
return async function <TElement, TResult>(xs: Array<TElement>, handler: (x: TElement) => TResult): Promise<Array<TResult>> {
const results: Array<TResult> = [];
const batches = Array.from({ length: Math.ceil(xs.length / concurrency) }, (_, i) => i)
for await (const batchNumber of batches) {
@emeraldsanto
emeraldsanto / slack-theme-verdandi.txt
Last active August 8, 2022 15:34
Slack light theme inspired by the Verdandi VS Code theme.
#f4f6f9,#e0e5ee,#d8edff,#0070d2,#e0e5ee,#16325c,#4bca81,#000000,#e0e5ee,#16325c
@emeraldsanto
emeraldsanto / swagger-to-express.ts
Last active April 28, 2022 20:43
Define routes according to the Open API / Swagger specification and get a fully typed express resolver.
// === Parameter definition ===
interface RouteParameterBase {
description?: string;
nullable?: boolean;
required?: boolean;
}
interface BooleanRouteParameter extends RouteParameterBase {
type: 'boolean';
@emeraldsanto
emeraldsanto / typesafe-mongo-changestream.ts
Created December 25, 2021 18:29
Type safe MongoDB change stream
import { EventEmitter } from 'events';
import { getInstance } from './core-util/mongo';
import { ChangeEvent, ChangeEventCR, ChangeEventDelete, ChangeEventUpdate, ChangeStream, ObjectId } from 'mongodb';
type ChangeListenerFunction<T> = (payload: T) => void;
interface User {
address: {
city: string
country: string
@emeraldsanto
emeraldsanto / make-navigator-integration-example.tsx
Last active September 4, 2021 03:58
Achieving type safe deep linking in React Native with react-navigation #11
import { LinkingOptions } from '@react-navigation/native';
const linking: LinkingOptions = {
prefixes: ['example://'],
config: {
screens: {
[RootStackConfiguration.name]: RootStackConfiguration.linking,
},
},
}