Skip to content

Instantly share code, notes, and snippets.

View adriaanbd's full-sized avatar
🚀
Remote

Adriaan Beiertz adriaanbd

🚀
Remote
View GitHub Profile
@adriaanbd
adriaanbd / flask_database_adapter.py
Created December 14, 2021 23:38
Database adapter to work with both flask-sqlachemy and sqlalchemy
View flask_database_adapter.py
import abc
from sys import stderr
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
class DatabaseAdapter(abc.ABC):
@adriaanbd
adriaanbd / better.py
Last active December 30, 2020 02:01
From a service layer that uses a domain object (OrderLine) vs primitives
View better.py
def allocate(orderid:str, sku: str, qty: int, repo: AbstractRepository, session) -> str:
"""
Obtains a list of Batches from data layer, validates OrderLine,
calls the allocate domain service, and commits to database.
"""
batches = repo.list()
if not is_valid_sku(sku, batches):
raise InvalidSKU(f'Invalid SKU: {sku}')
ref = model.allocate(orderid, sku, qty, batches)
session.commit()
@adriaanbd
adriaanbd / coupled_allocate_service.py
Last active December 30, 2020 01:51
Allocate method coupled with OrderLine vs decoupled
View coupled_allocate_service.py
# SERVICE LAYER
# we have to send an OrderLine to the domain service allocate, thus still coupled
def allocate(orderid:str, sku: str, qty: int, repo: AbstractRepository, session) -> str:
"""
Obtains a list of Batches from data layer, validates OrderLine,
calls the allocate domain service, and commits to database.
"""
batches = repo.list()
if not is_valid_sku(sku, batches):
raise InvalidSKU(f'Invalid SKU: {sku}')
@adriaanbd
adriaanbd / providers.tf
Created December 29, 2020 00:29
Terraform aws provider
View providers.tf
provider "aws" {
region = "us-east-1"
}
@adriaanbd
adriaanbd / versions.tf
Created December 29, 2020 00:26
Terraform required providers
View versions.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
@adriaanbd
adriaanbd / pascal_voc_generator.py
Last active October 5, 2020 05:09
Pascal VOC builder generator
View pascal_voc_generator.py
# annotation tags
XML = '<?xml version="1.0" encoding="UTF-8"?>'
ANNOTATION = 'annotation'
FOLDER = 'folder'
FILENAME = 'filename'
PATH = 'path'
SEGMENTED = 'segmented'
SOURCE = 'source'
DATABASE = 'database'
WIDTH = 'width'
@adriaanbd
adriaanbd / remove_sensitive_data_from_gh.md
Created October 1, 2020 19:47
Remove sensistive data from git commit history
View remove_sensitive_data_from_gh.md

Step 1

$ git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \
  --prune-empty --tag-name-filter cat -- --all
  > Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (266/266)
  > Ref 'refs/heads/master' was rewritten
@adriaanbd
adriaanbd / get_pdfs.py
Created July 18, 2020 05:38
Gets a list of of paths of all pdf files under target directory
View get_pdfs.py
from pathlib import Path
def get_pdfs(path: str) -> list:
"""Returns a list of paths of all pdf files under a target directory."""
assert isinstance(path, str), 'Path must be a string'
path_obj = Path(path)
assert path_obj.is_dir(), 'Path must be an existing directory'
path_iter = path_obj.rglob('*.pdf')
View react-redux-app-component-minimal.js
import React, { Component } from 'react';
import { connect } from 'react-redux';
const mapStateToProps = state => ({
appName: state.appName
})
class App extends Component {
render() {
View react-redux-app-index-minimal.js
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { Provider } from 'react-redux'
import App from './components/App';
import './style.css';
const defaultState = {
checked: false,