Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Betz Markbnj

View GitHub Profile
View validator.py
import json
import os
from bravado_core.spec import Spec
from bravado_core.validate import validate_object
from yaml import load, Loader, dump, Dumper
def validate_car(car):
validate_object(spec, Car, car)
View mycars_app.py
import json
import os
import syslog
import validator
from flask import Flask, request, make_response
from jsonschema.exceptions import ValidationError
class BadRequestError(Exception):
""" Signals a malformed request body
View swagger-spec-4.yaml
paths:
/swagger:
get:
summary: Return swagger API specification
description: |
Returns the My Cars API spec as a json swagger doc.
tags:
- Meta
responses:
'200':
View swagger-spec-3.yaml
Car:
type: object
required:
...
properties:
...
registration:
$ref: '#/definitions/Registration'
View swagger-spec-2.yaml
definitions:
Registration:
type: object
required:
- state
- plate_number
properties:
state:
type: string
description: Two letter state abbreviation code
View swagger-spec-1.yaml
swagger: '2.0'
info:
title: My Cars API
description: Simple API for demonstrating json validation
version: 1.0.0
host: localhost
schemes:
- http
produces:
- application/json
View download.py
import threading
from contextlib import closing
import requests
from Queue import Queue
input_file = u"test_input.txt"
def on_download_complete(url, file_name):
@Markbnj
Markbnj / check_docker.sh
Created Oct 17, 2015
Check kernel configuration for docker compatibility
View check_docker.sh
curl https://raw.githubusercontent.com/docker/docker/master/contrib/check-config.sh | bash
# yes, I know
@Markbnj
Markbnj / gce_project.sh
Created Oct 9, 2015
Grab Google compute engine project ID into environment variable
View gce_project.sh
export GCLOUD_PROJ=$( gcloud info | awk '$1 == "Project:" {print $2}' | tr -d '[][:space:]' )
@Markbnj
Markbnj / update-policy.sh
Created Sep 15, 2015
Allow services to start in an Ubuntu 15.04 Docker container
View update-policy.sh
# By default the /usr/sbin/policy-rc.d script in the ubuntu:15.04 docker image is set to return 101
# (action forbidden by policy) every time it is invoked. This prevents systemctl start requests for
# services from completing succesfully. The following command overwrites the contents of policy-rc.d
# to allow service starts.
#
# Note that this won't work right under bash due to expansion of the '!' character. Docker uses sh
# by default when executing the commands in the dockerfile, so this will work there, and you can
# also use sh interactively to run this.
echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
You can’t perform that action at this time.