edit test not real snippet
@app.route('/add', methods=['POST'])
def add_snippet():
    category = request.form['category']
    title = request.form['title']
    content = request.form['content']
    description = request.form['description']
    add_new_snippet(category, title, content, description)
    return redirect(url_for('index'))
SQLite3 Context Manager

context manager class for SQLite3 db connection

class SQLite():
    ''' Class is a wrapper for sqlite3 context manager. 
        Returs sqlite3.connection().cursor object ready to execute query
        Usage: with SQLite() as c:
                  c.execute('SELECT * FROM table')
    '''

    def __init__(self, db):
        self.db = db

    def __enter__(self):
        self.conn = sqlite3.connect(self.db)
        return self.conn.cursor()

    def __exit__(self, type, value, traceback):
        self.conn.commit()
        self.conn.close()
RGB Colors for VBA
def _rgb_to_interior(rgb):
    '''returns value of color for "Interior" property'''
    return (rgb[2] << 16) + (rgb[1] << 8) + rgb[0]
Intercept keypressed

this is base for macro keyboard to intercept Fx keys under Windows 10/11

import psutil
import keyboard
import pygetwindow as gw
import time

def is_teams_open():
    # Check if Microsoft Teams process is running
    for process in psutil.process_iter(['name']):
        if 'Teams' in process.info['name']:
            return True
    return False

def activate_teams():
    # Activate Microsoft Teams if open
    if is_teams_open():
        windows = gw.getWindowsWithTitle("Microsoft Teams")
        if windows:
            teams_window = windows[0]
            if teams_window.isMinimized:
                teams_window.restore()
            teams_window.activate()
            print("Microsoft Teams activated.")
        else:
            print("Teams is running but no window found.")
    else:
        print("Microsoft Teams is not running.")

# Bind F20 key to activate Teams if it is open
keyboard.add_hotkey('f20', activate_teams)

print("Listening for F20 to activate Teams...")
keyboard.wait('esc')  # Press 'Esc' to exit