Skip to content

Instantly share code, notes, and snippets.

# ================
# PRODUCTION IMAGE
# ================
FROM YOUR-BASE-IMAGE
ARG GIT_HASH
ENV GIT_HASH ${GIT_HASH:-dev}
WORKDIR /src
@barrachri
barrachri / main.py
Created November 24, 2019 18:41
Python application
######### Cloud Run
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
@barrachri
barrachri / main.py
Last active November 8, 2019 20:14
Schema-less serializazion in Python
import pickle, json, msgpack
data = {"device_id": "499675491", "s_10": 10}
# using the pickle module
pickle.dumps(data)
# using the json module
json.dumps(data)
events = {}
data = [1, 2]
if "id" in events:
events["id"].extend(data)
else:
events["id"] = [*data]
############## 🔥 setdefault ##############
import datetime as dt
ISO_8601_UTC = "%Y-%m-%dT%H:%M:%S.%fZ"
previous_date = dt.datetime.strptime("2018-09-06T13:34:30.168Z", ISO_8601_UTC)
dt.datetime.utcnow() - previous_date <= dt.timedelta(minutes=10)
version: '3'
services:
airflow:
image: barrachri/pyconde2018_airflow:latest
restart: always
depends_on:
- postgres
environment:
- POSTGRES_USER=airflow
- POSTGRES_PASSWORD=airflow
import uuid
from psycopg2 import IntegrityError
from sqlalchemy import (
Boolean,
Column,
DateTime,
Integer,
String,
Table,
"""Needs Python 3.7"""
import asyncio
import time
def blocking():
print("\tStarting sleeping")
time.sleep(5)
print("\tSleeping completed")
return "Hello World"
"""Small comparison between append VS insert and pop() VS pop(0)"""
SIZE_OF_THE_LIST = 1000
ELEMENTS_TO_BE_REMOVED = 500
def test_append():
my_list = []
for i in range(SIZE_OF_THE_LIST):
my_list.append(i)
return my_list
[flake8]
ignore = E265,E501,D203
max-line-length = 100
max-complexity = 10
inline-quotes = double
exclude =
.tox,
.git,
__pycache__,
docs/source/conf.py,