Skip to content

Instantly share code, notes, and snippets.

View CheeseCake87's full-sized avatar
🐝
Oh look, a bee.

David CheeseCake87

🐝
Oh look, a bee.
  • Scotland
  • 11:28 (UTC)
View GitHub Profile
import typing as t
from datetime import datetime
def calculate_days_between_dates(date: t.Union[str, datetime]) -> int:
"""
Calculates the days between a date and now
Date format must be in the format of %Y-%m-%d if date is a string
"""
if isinstance(date, datetime):
def money_to_int(value):
"""
Converts a money value, commonly in float format 100.00 to an int value 10000
"""
if not value:
return 0
if isinstance(value, str):
if not value[0].isdigit():
value = value[1:] # Remove potential currency symbol
def reverse_dict(input_dict: dict) -> dict:
"""
Swaps the values with keys of a dict
"""
return {v: k for k, v in input_dict.items()}
@CheeseCake87
CheeseCake87 / UtilityMixin.py
Last active January 6, 2024 09:22
UtilityMixin.py
from datetime import datetime, date
import typing as t
from sqlalchemy import (
Result,
Select,
Insert,
Update,
Delete,
select,
@CheeseCake87
CheeseCake87 / folder_structure.md
Last active November 6, 2023 14:33
Multiloader: Flask, Vite, SocketIO, Gunicorn
project_folder/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ static/
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ extensions/
β”‚   β”‚   └── __init__.py
β”‚ └── __init__.py
@CheeseCake87
CheeseCake87 / enum_colors.py
Last active December 6, 2023 13:12
enum_colors.py
from enum import Enum
class Colors(Enum):
BLACK = '#000000'
NIGHT = '#0C090A'
CHARCOAL = '#34282C'
OIL = '#3B3131'
DARK_GRAY = '#3A3B3C'
LIGHT_BLACK = '#454545'
@CheeseCake87
CheeseCake87 / flask_file_upload_pathlib.py
Last active October 10, 2023 06:59
Flask file upload with pathlib
import pathlib
import random
from textwrap import dedent
from flask import Flask, request, abort
from werkzeug.utils import secure_filename
def create_app():
app = Flask(__name__, static_url_path="/")
// imports here
const server_url = '127.0.0.1:5000';
export default function Client() {
const url_params = useParams();
// places dely on the amount of times a function is called, used in the form input onInput tag.
function debounce(func, timeout = 300) {
let timer;
#
# With help from : https://github.com/jonbiemond
#
# requires:
# pip install flask flask_sqlalchemy
#
# run: flask --app sqlalchemy_to_josnable_dict.py init-db
# run: flask --app sqlalchemy_to_josnable_dict.py test-data
# run: flask --app sqlalchemy_to_josnable_dict.py get-user1
# run: flask --app sqlalchemy_to_josnable_dict.py get-user2
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from pathlib import Path
from smtplib import SMTP
from smtplib import SMTPException
from ssl import create_default_context
from typing import Optional, Union