Skip to content

Instantly share code, notes, and snippets.

View jmvrbanac's full-sized avatar

John Vrbanac jmvrbanac

View GitHub Profile
@jmvrbanac
jmvrbanac / unused.py
Created January 20, 2020 22:22
Get Unused Port
def get_unused_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
sock.close()
return port
This is the baseline
@jmvrbanac
jmvrbanac / meinheld_gunicorn.py
Created January 22, 2019 02:40
Custom Gunicorn App that supports both meinheld and sync
from gunicorn.app.base import BaseApplication
from gunicorn.workers.sync import SyncWorker
from meinheld.gmeinheld import MeinheldWorker
class CustomWorker(object):
def handle_quit(self, sig, frame):
self.app.application.stop(sig)
super().handle_quit(sig, frame)
@jmvrbanac
jmvrbanac / theme.css
Last active September 26, 2018 04:39
Slack Theme
body {
background: #222;
color: #a1a1a1;
}
a {
color: #949494;
}
a:link, a:visited {
@jmvrbanac
jmvrbanac / docker_cheatsheet.sh
Created September 19, 2018 15:32
Docker Cheatsheet
# Remove all exited containers
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
# Remove all images by repository name
docker rmi $(docker images -q <repo_name>)
# Remove dangling images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
# Remove all networks that start with (older docker)
@jmvrbanac
jmvrbanac / cleanup.sh
Created August 28, 2018 21:05
Cleanup Docker Networks by name
docker network rm `docker network ls --filter name=tests-* -q`
@jmvrbanac
jmvrbanac / kube_dict_config.py
Last active July 17, 2018 18:07
Python Kubernetes use dictionary config
from kubernetes.client import ApiClient, Configuration, CoreV1Api
from kubernetes.config import kube_config
def build_k8_client(cfg_dict):
loader = kube_config.KubeConfigLoader(cfg_dict)
config_cls = type.__call__(Configuration)
loader.load_and_set(config_cls)
Configuration.set_default(config_cls)
@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}
@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 / 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('.')