Skip to content

Instantly share code, notes, and snippets.

@thoroc
thoroc / inspect_object.ts
Created July 21, 2023 13:28
Demonstration of how wrangling ChatGPT for 3 hours gave code that compile ....
import * as util from 'util';
const url = 'https://bitbucket.org/example-org/example-repo';
let address = new URL(url);
console.log(address);
class BitbucketRepo extends URL {
public readonly organisation: string;
@thoroc
thoroc / merging_string_array.ts
Created July 21, 2023 10:50
Merging string[] in Typescript
interface MyOptions {
dirs: string[];
length?: number;
yaml?: boolean;
name?: string;
}
const options1: MyOptions = {
dirs: ['src', 'test'],
length: 88,
@thoroc
thoroc / click_debug.py
Created April 14, 2023 07:38
How to set the cli app to show debug logs with loguru
import click
from loguru import logger
@click.command()
@click.option(
"-d",
"--debug",
is_flag=True,
help="Enable debug mode. Prints debug messages to the console.",
)
@thoroc
thoroc / convert_from_aws.py
Created April 14, 2023 07:02
cloudformation template to terraform template
import sys
import json
from pathlib import Path
from collections import OrderedDict
from typing import Optional
import boto3
from botocore.exceptions import ClientError
import click
from loguru import logger
import oyaml as yaml
@thoroc
thoroc / data_validation_example.md
Last active January 13, 2023 12:27
validation examples in python

NOTE: This was written in late 2022 with py3.9 in mind, so visitors of the future should take the follow with a pinch of salt.

Testing different validation library with the follow:

  • User object
    • first name
    • last name
    • date of birth (validate over 18 years old)
    • contact (see below)
    • address (see below)
@thoroc
thoroc / evolution_of_a_se.md
Last active December 2, 2022 10:43
The Evolution of a Software Engineer

First year

class HelloWorld
{
    public static void main(String args[])
    {
        // Display "Hello world!" on the console.
        System.out.println("Hello World!");
    }
@thoroc
thoroc / class_decorator.py
Last active December 1, 2022 13:41
Inheritance vs Class Decorator in python
from dataclasses import dataclass, field
from faker import Faker
from faker.providers import BaseProvider
class CustomProvider(BaseProvider):
__provider__ = "message"
def message(self):
return self.generator.sentence()
@thoroc
thoroc / 1_providers.py
Last active November 29, 2022 20:47
Example: FactoryBoy use with Faker Custom Provider
# 1. Create custom provider
from datetime import datetime
from faker.providers import BaseProvider
class PersonProvider(BaseProvider):
__provider__ = "person_title"
__provider__ = "person_first_name"
__provider__ = "person_email"
__provider__ = "person_dob"
@thoroc
thoroc / event_source_mapping_class.py
Last active December 1, 2022 15:40
storing EventSourceMapping values in a dataclass and passing it as argument when calling AWS boto3 lambda.create_event_source_mapping
# external dependencies: luguru and caseconverter.
# tested on python 3.9
from dataclasses import dataclass, field
import datetime
from caseconverter import pascalcase
from loguru import logger
@dataclass
class OnFailure:
@thoroc
thoroc / WelcomeToCodeWhisperer.md
Created July 20, 2022 13:59
AWS Code Whisperer readme

How to Use Amazon CodeWhisperer

Welcome to the Amazon CodeWhisperer preview! CodeWhisperer uses machine learning to generate code suggestions from the existing code and comments in your IDE. Supported languages include: Java, Python, and JavaScript.

TAB. Left Arrow. Right Arrow. That’s all!

You should automatically see inline code suggestions. Use the TAB key to accept a suggestion. CodeWhisperer may provide multiple suggestions to choose from, use [left arrow] and [right arrow] to navigate between suggestions.