Skip to content

Instantly share code, notes, and snippets.

View chrimaho's full-sized avatar

Chris Mahoney chrimaho

View GitHub Profile
snippet func
${1:FunctionName} <- function(${2:Input1Name}=${3:Input1Default}, ${4:Input2Name}=${5:Input2Default}) {
#' @title ${6:Add function title}
#' @description ${7:Add function description}.
#' @note ${8:Add a note for the developer}.
#' @param ${2:Input1Name} `${9:Input1Type}`. ${10:What is Input1?}. Default value `${3:Input1Default}`.
#' @param ${4:Input2Name} `${11:Input2Type}`. ${12:What is input2?}. Default value `${5:Input2Default}`.
#' @return ${13:What is being returned?}.
#' @seealso
#' @author chrimaho
snippet fun
${1:name} <- function (${2:variables}) {
${3:code}
}
{
"New Function": {
"scope": "python",
"prefix": "def",
"description": "New Function",
"body": [
"def ${1:name}(${2:variables}):",
" ${3:code}"]
}
{
"Function": {
"scope": "python",
"prefix": ["fun","def"],
"description": "Insert new function.",
"body":
[ "def ${1:function_name}(${2:param_1_name}:${3:param_1_type}=${4:param_1_default}, ${5:param_2_name}:${6:param_2_type}=${7:param_2_default}):"
, " '''"
, " # ${1:function_name}()"
, " "
fastapi
gitpython
python-decouple
# Base image
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
# Load requirements
COPY requirements.txt .
# Install dependencies
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --upgrade uvicorn[standard]
version: "3.8"
name: update-from-git
services:
listener:
build:
context: ../
dockerfile: docker/uvicorn.Dockerfile
container_name: listener
environment:
- GIT_URL=https://github.com/chrimaho/code-snippets.git
# Import Libraries ----
from sys import exc_info
from decouple import config
from fastapi import FastAPI, Query
from pydantic import BaseModel
from fastapi.responses import PlainTextResponse, JSONResponse, HTMLResponse
from git import Repo
from os.path import exists
from shutil import rmtree
# Compile Variables ----
TITLE = config(option='TITLE', default='Update from Git', cast=str)
DESCRIPTION = config \
( option='DESCRIPTION'
, default='Automated update process for pulling from Git repo upon webhook call.'
, cast=str
)
VERSION = config(option='VERSION', default='0.0.1', cast=str)
GIT_URL = config(option='GIT_URL', cast=str)
API_ENDPOINT = config(option="API_ENDPOINT", cast=str, default="/api/webhook")
# Set Landing Page ----
with open("./templates/landing_page.html") as file:
LANDING_PAGE = file.read() \
.format \
( TITLE = TITLE
, DESCRIPTION = DESCRIPTION
, VERSION = VERSION
, GIT_URL = GIT_URL
, API_ENDPOINT = API_ENDPOINT
, REPO_DIR = REPO_DIR