Skip to content

Instantly share code, notes, and snippets.

@thoroc
thoroc / appl.csv
Created February 25, 2024 20:13
just so I can call it and not host it directly.
date close
2007-04-23 93.24
2007-04-24 95.35
2007-04-25 98.84
2007-04-26 99.92
2007-04-29 99.8
2007-05-01 99.47
2007-05-02 100.39
2007-05-03 100.4
2007-05-04 100.81
@thoroc
thoroc / get_resolvers.sh
Created January 29, 2024 16:18
Example on how to fetch all the functions resolver for an GraphQL API on AWS and output them per template (dealing with VTL)
#!/bin/sh
# set the table list for "DrawTable" "GameTable" "PlayroundTable"
TABLE_NAMES="DrawTable GameTable PlayroundTable"
# API_ID="asdasdadajsdljalskdjalksdj"
# use the following command to get the list of functions
# FUNCTION_FILE=$(aws appsync list-functions --api-id "$API_ID")
FUNCTION_FILE="list_functions_full.json"
rm -rf resolvers
@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"