Skip to content

Instantly share code, notes, and snippets.

View bjinwright's full-sized avatar

Brian Jinwright bjinwright

View GitHub Profile
"""
@author Jay Taylor [@jtaylor]
@date 2010-11-01
Copyright Jay Taylor 2010
"""
#import socks
import socket
@pgolding
pgolding / dynamo_expression_builder.md
Last active August 22, 2017 15:40
DynamoDB Expression builder for update_item method in Boto3 (Python)

The update_item method in Boto3 requires preparing something like this:

try:
    result = table.update_item(
        Key={
            'id': event['pathParameters']['id']
        },
        ExpressionAttributeNames=attr_names,
        ExpressionAttributeValues=expression_vals,
@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 / settings.py
Created February 15, 2013 16:36
So part of being a 12-factor app is storing your config in your environment (http://12factor.net/config). This is how I do that using Django settings files. This is the code companion for a blog post (http://blog.ipoots.com/post/43154090079/how-to-achieve-12-factor-app-config-glory-with-django). A similar blog post is http://www.wellfireinteract…
# Django settings for dnsly project.
from unipath import FSPath as Path
import os
def env(key, default=None):
"""Retrieves env vars and makes Python boolean replacements"""
val = os.getenv(key, default)
if val == 'True':
val = True