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 / linux_netstats.lua
Created November 13, 2014 00:40
A heka decoder for data available in /proc/net/dev
--[[
Parses a payload containing the contents of a `cat /proc/net/dev | tail -n +3` call into a Heka
message.
Config:
- payload_keep (bool, optional, default false)
Always preserve the original log line in the message payload.
@mattupstate
mattupstate / nginx_status_decoder.lua
Last active August 29, 2015 14:09
heka Nginx status decoder and filter
--[[
Parses a payload containing the contents of the output from the Nginx `stub_status`
module. See: http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
Config:
- payload_keep (bool, optional, default false)
Always preserve the original log line in the message payload.
@mattupstate
mattupstate / diskusage.lua
Last active October 8, 2015 10:25
heka disk usage decoder and filter
--[[
Graphs disk usage data containing fields entield `DiskSize`, `DiskUsed`,
`DiskAvailable`, and `DiskPercentUsed`
Config:
- sec_per_row (uint, optional, default 60)
Sets the size of each bucket (resolution in seconds) in the sliding window.
- rows (uint, optional, default 1440)
Sets the size of the sliding window i.e., 1440 rows representing 60 seconds
@mattupstate
mattupstate / docker-regsitry.conf
Created November 6, 2014 14:54
An example Nginx config for a private Docker registry to enable unauthenticated, read-only access on non-volatile HTTP methods
upstream docker-registry {
leastconn;
server hostname1:port;
server hostname2:port;
}
server {
listen 80;
server_name docker.your.domain;
rewrite ^ https://$server_name$request_uri? permanent;
input {
file {
path => [ "/var/log/*.log", "/var/log/messages", "/var/log/syslog" ]
start_position => "beginning"
}
}
output {
elasticsearch_http {
host => "elasticsearch.company.internal"
@mattupstate
mattupstate / as_blueprint.py
Last active August 27, 2019 02:55
An `as_blueprint` method for Flask MethodView classes
from flask import Flask, Blueprint
from flask.views import MethodView
class ApiResource(MethodView):
endpoint = None
url_prefix = None
url_rules = {}
@classmethod
@mattupstate
mattupstate / uuid_url64.py
Last active July 2, 2020 13:46
Generate unique, URL friendly ID's based on UUID with Python
import re
import uuid
import base64
def uuid_url64():
"""Returns a unique, 16 byte, URL safe ID by combining UUID and Base64
"""
rv = base64.b64encode(uuid.uuid4().bytes).decode('utf-8')
return re.sub(r'[\=\+\/]', lambda m: {'+': '-', '/': '_', '=': ''}[m.group(0)], rv)
@mattupstate
mattupstate / oat.py
Last active August 29, 2015 13:55
Naive attempt at porting Oat (https://github.com/ismasan/oat) to Python
import warnings
from collections import OrderedDict
from itertools import chain
from inflection import pluralize
class Adapter(object):
@mattupstate
mattupstate / app.py
Created January 22, 2014 19:45
Odd behavior regarding ordering_list and association_proxy with SQLAlchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.orderinglist import ordering_list
app = Flask(__name__)
app.debug = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
db = SQLAlchemy(app)