Skip to content

Instantly share code, notes, and snippets.

View bjinwright's full-sized avatar

Brian Jinwright bjinwright

View GitHub Profile
@bjinwright
bjinwright / encode.py
Created July 16, 2024 20:44 — forked from cameronmaske/encode.py
base64 that actually encodes URL safe (no '=' nonsense)
"""
base64's `urlsafe_b64encode` uses '=' as padding.
These are not URL safe when used in URL paramaters.
Functions below work around this to strip/add back in padding.
See:
https://docs.python.org/2/library/base64.html
https://mail.python.org/pipermail/python-bugs-list/2007-February/037195.html
"""
@bjinwright
bjinwright / language.py
Last active May 17, 2017 15:43 — forked from beaufour/language.py
Django Middleware to choose language based on subdomain
import logging
from django.utils import translation
from django.conf import settings
class DomainBasedLanguageMiddleware(object):
"""
Set the language for the site based on the subdomain the request
is being served on. For example, serving on 'fr.domain.com' would
make the language French (fr).