Skip to content

Instantly share code, notes, and snippets.

@gunzip
gunzip / Terraform Managed Identity
Last active March 17, 2025 09:56
Trial System Alternative
resource "azurerm_role_assignment" "cosmosdb_reader" {
scope = azurerm_cosmosdb_account.cosmos.id
role_definition_name = "Cosmos DB Built-in Data Reader"
principal_id = azurerm_api_management.apim.identity[0].principal_id
}
import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
class RemoveQueryParamsProcessor implements SpanProcessor {
onStart(span: Span): void {
// No action on span start for this processor
}
onEnd(span: ReadableSpan): void {
// Check if the span has an attribute that represents a URL
const url = span.attributes['http.url'] as string | undefined;
#!/bin/bash
# Directory dei moduli
MODULES_DIR=".terraform/modules"
HASHES_FILE="tfmodules.lock.json"
# Scaricare i moduli
terraform init
# Funzione per calcolare l'hash di un modulo
import appinsights from 'applicationinsights';
import winston from 'winston';
import { transports, format, Logger } from 'winston';
// Configura Application Insights
appinsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY)
.setAutoCollectConsole(false)
.start();
const aiClient = appinsights.defaultClient;
Analytics Analytics/Analytics.puml
Athena Analytics/Athena.puml
AthenaDataSourceConnectors Analytics/AthenaDataSourceConnectors.puml
CleanRooms Analytics/CleanRooms.puml
CloudSearch Analytics/CloudSearch.puml
CloudSearchSearchDocuments Analytics/CloudSearchSearchDocuments.puml
DataExchange Analytics/DataExchange.puml
DataExchangeforAPIs Analytics/DataExchangeforAPIs.puml
DataPipeline Analytics/DataPipeline.puml
DataZone Analytics/DataZone.puml
terraform {
required_version = ">= 1.0.0"
backend "s3" {}
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 4.63.0"
configuration_aliases = [aws.alternate]
# Create the whole infrastructure to run the Strapi CMS webserver
# and the static frontend that uses nextjs.
# Terraform provider configuration
variable "db_name" {
description = "The name of the database"
default = "my_database"
}
@gunzip
gunzip / refactor.ts
Last active August 9, 2022 16:59
refactor using io-ts types
import { identity, pipe } from "fp-ts/lib/function";
import * as E from "fp-ts/lib/Either";
import * as t from "io-ts";
import { WithinRangeInteger } from "./numbers";
const _isNonEmptyUint8Array = (u: unknown): u is Uint8Array =>
Array.isArray(u) && u.length > 0 && t.array(WithinRangeInteger(0, 256)).is(u);
export const NonEmptyUint8Array = new t.Type<Uint8Array, Uint8Array, unknown>(
"NonEmptyUint8Array",
import { pipe } from "fp-ts/lib/function";
import * as E from "fp-ts/lib/Either";
import * as t from "io-ts";
import { WithinRangeInteger } from "./numbers";
export const NonEmptyUint8Array = new t.Type<Uint8Array, String, Array<number>>(
"NonEmptyUint8Array",
(u): u is Uint8Array =>
t.array(WithinRangeInteger(0, 256)).is(u) && u.length > 0,
(u, c) =>
@gunzip
gunzip / mobile.test.ts
Last active September 30, 2021 07:29
MobileNumberT
import { isRight } from "fp-ts/lib/Either";
import { MobileNumberFromString, PatternString } from "../strings";
describe("MobileNumberFromString", () => {
it("should fail", () => {
const ps = MobileNumberFromString.decode("ABCD");
expect(isRight(ps)).toBeFalsy();
});
it("should success", () => {
const ps = MobileNumberFromString.decode("123456789");