Skip to content

Instantly share code, notes, and snippets.

@brianfoody
brianfoody / dataclasses.py
Created October 1, 2020 13:39
Data classes with replace
from dataclasses import dataclass, replace
from typing import List, Optional
@dataclass(frozen=True)
class State:
val1: float
val2: float
@dataclass
class Controller:
@brianfoody
brianfoody / UserEvents.ts
Created August 24, 2020 05:34
User Events Sample
type MembershipType = "Basic" | "Pro" | "Premium";
type SignUp = {
userId: string;
phoneNumber: string;
membershipType: MembershipType;
};
type MembershipUpdate = {
membershipType: MembershipType;
@brianfoody
brianfoody / OrgEvents.ts
Last active August 24, 2020 05:33
Organisational Event typings
import { Events as MarketingEvents } from "./MarketingEvents";
import { Events as SalesEvents } from "./SalesEvents";
import { Events as UserEvents } from "./UserEvents";
type EventsBySource = {
Marketing: MarketingEvents;
Sales: SalesEvents;
User: UserEvents;
};
@brianfoody
brianfoody / schema.ts
Last active August 24, 2020 12:29
Create EventBridge Schema from TypeScript
import * as schemas from "@aws-cdk/aws-eventschemas";
import * as cdk from "@aws-cdk/core";
import { generateOpenApiSchema } from "./generators/schemaGenerator";
...
this.schema = new schemas.CfnSchema(this, "MySchema", {
registryName: props.mlRegistry.attrRegistryName,
type: "OpenApi3",
description: "Schema Definition for my events",
@brianfoody
brianfoody / tsToOpenApi.ts
Last active August 23, 2020 01:19
TypeScript to OpenAPI 3
import * as tsj from "ts-json-schema-generator";
const toOpenApi = require("json-schema-to-openapi-schema");
const defaultConfig: SchemaConfig = {
tsconfig: "./tsconfig-types.json",
type: "*",
};
export const generateOpenApiSchema = (
schemaName: string,
@brianfoody
brianfoody / async_play.py
Last active July 8, 2020 02:35
Typed Asynchronous Python
from influxdb import InfluxDBClient
from influxdb.resultset import ResultSet
import pandas as pd
from typing import Any, List, Optional
import os
client: InfluxDBClient
@brianfoody
brianfoody / Cognito.ts
Created June 28, 2020 10:42
Cognito Mapping
const smsNotificationZones = {
"eu-central-1": "eu-west-1",
"eu-west-1": "eu-west-1",
};
@brianfoody
brianfoody / lambda_handler.py
Last active June 25, 2020 01:22
Pydantic Lambda Validation
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, validator
from random import randint
from typing import List
from re import search
"""
Add this to your mypy.ini
@brianfoody
brianfoody / fnc2.py
Created June 17, 2020 12:43
"Spread" Syntax - assign dataclass to new variable and update
import dataclasses as dc
from typing import List
@dc.dataclass(frozen=True)
class User:
id: float
name: str
email: str
active: bool
@brianfoody
brianfoody / fnc.py
Last active June 17, 2020 12:46
Python Typing
import dataclasses as dc
from typing import List
import fnc
@dc.dataclass(frozen=True)
class User:
id: float
name: str
email: str