Skip to content

Instantly share code, notes, and snippets.


Brian Jinwright bjinwright

View GitHub Profile
bjinwright /
Created Aug 1, 2021
Create Role in Fauna
result = real_client.query(
"name": "new-role-c",
"privileges": [
"resource": q.function("create_user"),
"actions": {
"call": True
bjinwright /
Created Nov 16, 2017
Permutations based on range
from itertools import permutations
xlist = ["word1", "word2", "word3"]
def perm_range(obj_list,num):
for perm in permutations(obj_list, num):
bjinwright /
Last active May 26, 2017
Django Theme Switcher that does not use Django Sites and doesn't use Thread.local
from django.core.exceptions import SuspiciousFileOperation
from django.template import Origin
from django.template.loaders.filesystem import Loader
from django.conf import settings
from django.utils._os import safe_join
class ThemeLoader(Loader):
themes = [theme.get('theme') for theme in settings.SITE_CONFIGS.values()]
current_theme = ''
bjinwright /
Last active May 17, 2017 — forked from beaufour/
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 '' would
make the language French (fr).
bjinwright /
Created Feb 16, 2017
Example Click CLI with Callback and Prompt
import click
from .cli import CappyCLI
def cappy():
def use_apigw(ctx, param, value):
bjinwright /
Created Jan 13, 2017
Create super user with management command
from import BaseCommand
from django.contrib.auth import get_user_model
class Command(BaseCommand):
help = 'Echoes AWS Creds'
def handle(self, *args, **options):
get_user_model().objects.create_superuser(username='your_user', password='your_password', email='')
bjinwright /
Last active Mar 21, 2021
Example of how to make an authorized call to API Gateway using Boto3, Requests, and AWS4Auth.
import boto3
import datetime
import json
from requests_aws4auth import AWS4Auth
import requests
identity = boto3.client('cognito-identity', region_name='us-east-1')
bjinwright / zappa_settings.json
Last active Dec 8, 2016
Zappa settings file with remote environment vars and VPC support
View zappa_settings.json
"dev": {
"aws_region": "us-east-1",
"s3_bucket": "yourcode-bucket",
"django_settings": "yourapp.settings",
"use_precompiled_packages": true,
"domain": "",
"lets_encrypt_key": "s3://yourcode-bucket/openssl.key",
bjinwright / zappa-iam.json
Created Dec 8, 2016
Zappa IAM policy - Replace all the references to yourblog (your app name), your-function-bucket (the bucket that Zappa stores your code), and your-static-and-media-files-bucket (where you store your static files)
View zappa-iam.json
"Version": "2012-10-17",
"Statement": [
"Action": [
"Resource": [
bjinwright /
Created Dec 7, 2016
Custon S3 Django-Storages backend made for use with CloudFront with multiple origins
from django.conf import settings
from django.utils.encoding import filepath_to_uri
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(S3BotoStorage):
location = settings.STATICFILES_LOCATION
def url(self, name, headers=None, response_headers=None, expire=None):
return '{}{}'.format(settings.STATIC_URL,filepath_to_uri(name))