Skip to content

Instantly share code, notes, and snippets.

View jmvrbanac's full-sized avatar

John Vrbanac jmvrbanac

View GitHub Profile
@jmvrbanac
jmvrbanac / falcon_perf.rst
Last active September 12, 2016 16:31
Performance numbers for Falcon with different servers

Setup

  1. apt-get update
  2. apt-get upgrade -y
  3. apt-get install -y apt-transport-https ca-certificates
  4. apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  5. echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list
  6. apt-get update
  7. apt-get install -y docker-engine
@jmvrbanac
jmvrbanac / convert_metrics.py
Created September 13, 2016 21:17
Quick and dirty converter for falcon metrics
def get_results():
lines = []
while True:
try:
line = raw_input()
except EOFError:
break
if line:
lines.append(line)
@jmvrbanac
jmvrbanac / __main__.py
Created September 14, 2016 15:41
Example Custom Gunicorn Application
"""
Sample Application
Usage:
sample [options]
Options:
-h --help Show this screen.
"""
import aumbry
@jmvrbanac
jmvrbanac / validate.py
Created September 20, 2016 04:44
Example JSON Parse and Validation Decorator for Falcon
def validate(schema):
def decorator(func):
def wrapper(self, req, resp, *args, **kwargs):
try:
raw_json = req.stream.read()
obj = json.loads(raw_json.decode('utf-8'))
except Exception:
raise falcon.HTTPBadRequest(
'Invalid data',
'Could not properly parse the provided data as JSON'
@jmvrbanac
jmvrbanac / rethink_runner.py
Created October 7, 2016 20:18
RethinkDB Process Runner
import os
import subprocess
import shutil
import signal
import tempfile
import time
class RethinkProcess(object):
def __init__(self):
@jmvrbanac
jmvrbanac / gist:8e2e820e673f2be5e05aa8f6b7da8651
Created December 1, 2016 17:20
FeedReader build deps for Debian
sudo apt install libjson-glib-dev libgee-0.8-dev libsecret-1-dev libnotify-dev \
librest-dev libwebkit2gtk-4.0-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
libgoa-1.0-dev libpeas-dev
@jmvrbanac
jmvrbanac / gunicorn_options.yml
Last active August 26, 2023 18:13
Capture Client Certificate CN from Gunicorn
bind: 0.0.0.0:8000
workers: 1
worker_class: "example.worker:CustomWorker"
timeout: 30
ca_certs: ca.crt
certfile: server.crt
keyfile: server.key
cert_reqs: 2
do_handshake_on_connect: true
@jmvrbanac
jmvrbanac / middleware.py
Created September 9, 2017 04:31
Middleware plugins for a service
from pike.discovery import py
class MiddlewarePlugin(object):
def __init__(self, config):
self.config = config
@classmethod
def qualified_name(cls):
__, __, module_name = cls.__module__.rpartition('.')
@jmvrbanac
jmvrbanac / subtracted_time.py
Created March 26, 2018 19:42
Quick and dirty way to help find the right point in time for a reconcile
import maya
from datetime import timedelta
def lookup_subtracted_time(days, hours, minutes):
delta = timedelta(days=days, hours=hours, minutes=minutes)
backdate = (maya.now() - delta).datetime()
localtime = backdate.astimezone(maya.get_localzone())
return localtime.isoformat(), delta.total_seconds() / 60
@jmvrbanac
jmvrbanac / version.sh
Created April 12, 2018 22:23
Adding git log to bumpversion tag commits
#!/bin/bash
export MESSAGE=$(echo -e "\n\n$(git log `git describe --tags --abbrev=0`..HEAD --oneline)")
bumpversion \
--message 'Bump version: {current_version} → {new_version}{$MESSAGE}' \
${@:1}