Skip to content

Instantly share code, notes, and snippets.

@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.

@thoroc
thoroc / provider.py
Created April 29, 2022 14:54
Custom Faker Provider
# Based on the following:
# https://www.datainsightonline.com/post/how-to-generate-fake-dataset-with-python-faker-library
# https://deparkes.co.uk/2020/12/28/python-fake-data-with-faker/
from faker.providers import BaseProvider
from faker import Faker
import pandas as pd
from loguru import logger
fake = Faker("en_GB")
@thoroc
thoroc / README.md
Last active April 14, 2022 10:48
mock request object

Simple scenario to demontrate how to mock requests' post

============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.7.10, pytest-6.1.1, py-1.11.0, pluggy-0.13.1 -- /python/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /python, configfile: pytest.ini
plugins: Faker-13.3.3, anyio-3.5.0, mock-3.3.1, cov-2.10.1, icdiff-0.5
collected 2 items
@thoroc
thoroc / README.md
Last active April 15, 2022 15:10
pytest raises example

Simple scenario to demontrate how to assert for custom exception

============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.7.10, pytest-6.1.1, py-1.11.0, pluggy-0.13.1 -- /python/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /python, configfile: pytest.ini
plugins: Faker-13.3.3, anyio-3.5.0, mock-3.3.1, cov-2.10.1, icdiff-0.5
collected 5 items
@thoroc
thoroc / gist:7138b60613f69f835851583075827bbc
Last active April 5, 2022 09:26 — forked from digitaljhelms/gist:1354003
Installing and using Gource on Mac OS X (only tested on Snow Leopard)

Gource

Gource is a software version control visualization tool.

Software projects are displayed by Gource as an animated tree with the root directory of the project at its centre. Directories appear as branches with files as leaves. Developers can be seen working on the tree at the times they contributed to the project.

http://code.google.com/p/gource/

Installing Gource Manually (w/out MacPorts or Homebrew)

@thoroc
thoroc / readme.md
Created February 10, 2022 09:38
Typescript + React primers

JS + Typescript

React

@thoroc
thoroc / check_venv.py
Created February 2, 2022 09:14
Checking if we are in a virutalenv for python
#! /usr/local/bin/python3
import sys
def is_venv():
return (hasattr(sys, 'real_prefix') or
hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
@thoroc
thoroc / convert.py
Created January 12, 2022 12:43
add weekday names to a csv file
import pandas as pd
df = pd.read_csv('message.csv', dtype=str)
# rename columns to lower case and replace spaces with underscores
columns = {col: col.lower().replace(' ', '_').replace('/','_') for col in list(df.columns)}
df.rename(columns, axis=1, inplace=True)
for col in list(df.columns):
# Ensuring that the column is always a string without spaces before or after