Skip to content

Instantly share code, notes, and snippets.

@mattupstate
mattupstate / README.md
Created November 13, 2014 17:14
An example of how to setup streaming replication for PostgreSQL with Docker.

PostgreSQL Streaming Replication With Docker

The *.txt files here hold user and database parameters. Specifically, replication.txt contains the user/role and password to use for replication. Whereas database.txt contains an initial database, user/role and password to create on the master.

Run the master:

$ fig run -d master

Wait for it to start up completely. Start the slave:

@mattupstate
mattupstate / app.py
Created March 15, 2012 19:08
Flask application configuration using an environment variable and YAML
os
from flask_extended import Flask
app = Flask(__name__)
app.config.from_yaml(os.join(app.root_path, 'config.yml'))
@mattupstate
mattupstate / README.md
Last active June 5, 2023 20:50
Decorator vs ASGI spect middleware execution issue with FastAPI

Decorator vs ASGI Spec Middleware with FastAPI and ddtrace Correlation

This illustrates something unexpected about middleware with FastAPI and ddtrace. Below is are two examples of the log output from the minimal application provided here. The first being the log output when the decorator style middleware is added. The second when the decorator style middleware is removed, notice the trace and span ID values are 0. The question is, what is going such that the trace/span ID is only available in the ASGI spec when the decorator style is also applied.

@mattupstate
mattupstate / put-s3-bucket-notification-configuration
Last active January 11, 2022 03:31
Example of how to configure S3 bucket notifications from the command line
#!/usr/bin/env python
import argparse
import sys
try:
import boto3
except ImportError:
print('Please install boto3 to use this tool')
sys.exit(1)
@mattupstate
mattupstate / main.py
Created August 15, 2011 01:55
uwsgi yaml file
#!/usr/bin/env python
import os, web, sys
sys.path.append(os.path.dirname(__file__))
urls = (
r'/', 'Home',
)
@mattupstate
mattupstate / helpers.py
Created June 25, 2013 15:04
Register all Blueprint instances on the specified Flask application found in all modules for the specified package
# -*- coding: utf-8 -*-
"""
helpers
~~~~~~~
helpers module
"""
import pkgutil
import importlib
@mattupstate
mattupstate / example.py
Created February 5, 2015 03:37
JSON Patch SQLAlchemy models w/ Flask
from dictalchemy import make_class_dictable
from flask import Flask, request, jsonify, json
from flask_sqlalchemy import SQLAlchemy
from jsonpatch import JsonPatch, JsonPatchException
app = Flask(__name__)
app.debug = True
db = SQLAlchemy(app)
make_class_dictable(db.Model)
@mattupstate
mattupstate / gather_stack_outputs.py
Created May 19, 2015 18:24
Ansible module to gather a Cloudformation stack outputs into variable scope
#!/usr/bin/python
# -*- coding: utf-8 -*-
try:
import boto
from boto import cloudformation
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
@mattupstate
mattupstate / consul-ssh-configurator.py
Last active September 27, 2020 17:56
A script to generate an SSH config from Consul's HTTP API
#!/usr/bin/env python3
"""
Renders a partial SSH configuration file from Nodes and Services
located in a specified Consul catalog and then merges other partial
config files into the main ~/.ssh/config file. The Consul based SSH
config follows a convention for the SSH host::
Host <consul-cluster-name>-<service-name>-<node-address>
User <ssh-user>
Hostname <consul-node-address>
@mattupstate
mattupstate / resources.tf
Last active July 21, 2020 17:39
Just a clever way to set an RDS master password with Terraform and Ansible to prevent the password from being stored in plain text
resource "aws_db_instance" "core" {
username = "postgres"
password = "changeme"
...
}
resource "null_resource" "master_password" {
triggers {
db_host = "${aws_db_instance.address}"
}