Skip to content

Instantly share code, notes, and snippets.

View fdemmer's full-sized avatar
🌱
developing

Florian Demmer fdemmer

🌱
developing
  • Vienna, Austria
  • 04:53 (UTC +02:00)
View GitHub Profile
@s3i7h
s3i7h / AnyUri.py
Last active April 2, 2024 17:14
a class that handles uri
import re
from re import Pattern
from typing import Dict, Any, cast
from pydantic.utils import update_not_none
from pydantic.validators import constr_length_validator
class RFC3986Regex:
ALPHA: Pattern = r"[a-zA-Z]"
from django.conf import settings
def SessionCookieSameSiteWorkaround(get_response):
def middleware(request):
# See:
# https://blog.chromium.org/2019/10/developers-get-ready-for-new.html
# https://github.com/django/django/pull/11894
# https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
# https://www.chromium.org/updates/same-site/incompatible-clients
@asfaltboy
asfaltboy / responses-mixin.py
Last active February 22, 2019 14:24
A responses TestCase Mixin
"""
A unittest.TestCase mixin that allows using the
responses (https://pypi.python.org/pypi/responses/) package in tests.
Usage
-----
Install responses with `pip install responses`.
Add `ResponsesMixin` to your `TestCase` parent classes instead of using
@Valian
Valian / profile_middleware.py
Created May 6, 2017 14:13
Detailed Hotshot profiler middleware for Django
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
# Further modified by: Jakub Skalecki (https://rock-it.pl)
import hotshot
import hotshot.stats
import textwrap
import os
@nagelflorian
nagelflorian / buckets.tf
Last active February 12, 2024 07:44
Terraform config for static website hosting on AWS
# AWS S3 bucket for static hosting
resource "aws_s3_bucket" "website" {
bucket = "${var.website_bucket_name}"
acl = "public-read"
tags {
Name = "Website"
Environment = "production"
}
from django.views.generic import TemplateView
if settings.DEBUG:
# enable local preview of error pages
urlpatterns += patterns('',
(r'^403/$', TemplateView.as_view(template_name="403.html")),
(r'^404/$', TemplateView.as_view(template_name="404.html")),
(r'^500/$', TemplateView.as_view(template_name="500.html")),
@jsmits
jsmits / flake8.xml
Last active August 2, 2018 16:52
PyCharm 3.x Flake8 Configuration XML
<toolSet name="Code Checking">
<tool name="Flake8" showInMainMenu="true" showInEditor="true" showInProject="true" showInSearchPopup="true" disabled="false" useConsole="true" showConsoleOnStdOut="false" showConsoleOnStdErr="false" synchronizeAfterRun="true">
<exec>
<option name="COMMAND" value="/usr/local/bin/flake8" />
<option name="PARAMETERS" value="--max-complexity 10 $FilePath$" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$" />
</exec>
<filter>
<option name="NAME" value="Filter 1" />
<option name="DESCRIPTION" />