Skip to content

Instantly share code, notes, and snippets.

@jacinator
jacinator / app.py
Last active June 21, 2022 21:26
Example: verify HMAC authorization header with Python and Flask
"""Verify a HMAC authorization header using Flask
This is how to verify an HMAC authorization header against the body of
a request using Flask.
When I was creating a Flask app to support a Microsoft Teams outgoing
webhook I had some difficulty finding examples or tutorials. I found
some example code from Microsoft in Node.js and one in C#. I spent a
few hours carefully reading through it and converting the process to
Python. Hopefully my posting this as a gist can save some other people
@jacinator
jacinator / connect4.py
Created June 10, 2022 14:33
Determine if a connect four board is completed
class Cell:
ADJACENT = [
(x, y)
for x in range(-1, 2)
for y in range(-1, 2)
if x or y
]
EMPTY = '_'
BLACK = 'B'
@jacinator
jacinator / admin.py
Last active November 3, 2020 22:12
This is the code needed to create a custom Django authentication system which trims out username and name fields an uses the email field for authentication.
from django.contrib import admin
from django.contrib.auth.admin import GroupAdmin, UserAdmin as BaseUserAdmin
from django.contrib.auth.models import Group as BaseGroup
from django.utils.translation import gettext_lazy as _
from .models import Group, User
admin.site.unregister(BaseGroup)
admin.site.register(Group, GroupAdmin)