Skip to content

Instantly share code, notes, and snippets.

View bjinwright's full-sized avatar

Brian Jinwright bjinwright

View GitHub Profile
@bjinwright
bjinwright / ajax-dialog.js
Created September 28, 2023 14:53
Ajax Dialog Web Component
class AjaxDialog extends HTMLElement {
connectedCallback() {
// Store the original children (the slot content)
const originalChildren = this.innerHTML;
this.open = this.getAttribute('open') || false;
this.loaded = this.getAttribute('loaded') || false;
this.content = this.getAttribute('content') || '';
this.url = this.getAttribute('url') || '';
this.button_class = this.getAttribute('button-class') || 'bg-green-600 text-white';
this.dialog_class = this.getAttribute('dialog-class') || 'bg-white';
@bjinwright
bjinwright / .env
Last active March 25, 2022 20:20
Django Settings using Environment Variables via envs (https://github.com/bjinwright/envs) project.
DATABASE_ENGINE=django.db.backends.sqlite3
DATABASE_NAME=db.sqlite3
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_HOST=
DATABASE_PORT=
SECRET_KEY="asdfdfadsflkjsdflkjadsflkasfakl;"
STATIC_URL=/static/
DEBUG=True
@bjinwright
bjinwright / cognito.py
Last active January 18, 2022 00:25
Example of how to make an authorized call to API Gateway using Boto3, Requests, and AWS4Auth. http://stackoverflow.com/questions/37336286/how-do-i-call-an-api-gateway-with-cognito-credentials-in-python
import boto3
import datetime
import json
from requests_aws4auth import AWS4Auth
import requests
boto3.setup_default_session(region_name='us-east-1')
identity = boto3.client('cognito-identity', region_name='us-east-1')
account_id='XXXXXXXXXXXXXXX'
@bjinwright
bjinwright / create_role.py
Created August 1, 2021 23:04
Create Role in Fauna
result = real_client.query(
q.create_role({
"name": "new-role-c",
"privileges": [
{
"resource": q.function("create_user"),
"actions": {
"call": True
}
}
@bjinwright
bjinwright / custom_storages.py
Created December 7, 2016 22:50
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))
@bjinwright
bjinwright / zappa-iam.json
Created December 8, 2016 17:30
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)
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:Describe*"
],
"Resource": [
@bjinwright
bjinwright / permutations_range.py
Created November 16, 2017 18:50
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):
print(perm)
perm_range(xlist,2)
@bjinwright
bjinwright / loader.py
Last active May 26, 2017 17:39
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
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).
@bjinwright
bjinwright / enable_mod_pagespeed.conf
Created May 10, 2013 15:01
Example mod_pagespeed conf for AWS Elastic Beanstalk.
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/x-javascript