Skip to content

Instantly share code, notes, and snippets.

View bjinwright's full-sized avatar

Brian Jinwright bjinwright

View GitHub Profile
@tovbinm
tovbinm / fauna-graphql-relations.gql
Last active March 6, 2022 14:38
FaunaDB Relations: GraphQL schemas, mutations and resulting documents
****************************************************************************
**** FaunaDB Relations: GraphQL schemas, mutations and resulting documents *
****************************************************************************
**** One to One Relation ***************************************************
SCHEMA:
type User { name: String! car: Car }
type Car { plate: String! owner: User }
MUTATION:
mutation Create {
createUser(data: {
@j0lv3r4
j0lv3r4 / Readme.md
Created October 12, 2019 20:19 — forked from colllin/Readme.md
FaunaDB User Token Expiration (for ABAC)

Auth0 + FaunaDB ABAC integration: How to expire Fauna user secrets.

Fauna doesn't yet provide expiration/TTL for ABAC tokens, so we need to implement it ourselves.

What's in the box?

3 javascript functions, each of which can be imported into your project or run from the command-line using node path/to/script.js arg1 arg2 ... argN:

  1. deploy-schema.js: a javascript function for creating supporting collections and indexes in your Fauna database.
@crgimenes
crgimenes / stringToReaderCloser.go
Last active April 11, 2024 15:41
string to io.ReadCloser
package main
import (
"bytes"
"fmt"
"io"
"os"
"strings"
)
@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 = ''
@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,
@marcellodesales
marcellodesales / ec2-host-from-tag-to-env-vars.sh
Last active November 8, 2022 11:49
Create Environment Variables in EC2 Hosts from EC2 Host Tags, just like Beanstalk or Heroku does!
######
# Author: Marcello de Sales (marcello.desales@gmail.com)
# Description: Create Create Environment Variables in EC2 Hosts from EC2 Host Tags
#
### Requirements:
# * Install jq library (sudo apt-get install -y jq)
# * Install the EC2 Instance Metadata Query Tool (http://aws.amazon.com/code/1825)
#
### Installation:
# * Add the Policy EC2:DescribeTags to a User
@simonw
simonw / gist:7000493
Created October 15, 2013 23:53
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
@audreyfeldroy
audreyfeldroy / pypi-release-checklist.md
Last active February 23, 2023 15:03
My PyPI Release Checklist
  • Update HISTORY.md
  • Commit the changes:
git add HISTORY.md
git commit -m "Changelog for upcoming release 0.1.1."
  • Update version number (can also be minor or major)
bumpversion patch
@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