Skip to content

Instantly share code, notes, and snippets.

@efi-mk
efi-mk / update_environment.sh
Created July 12, 2018 16:59
Serverless testing from the trenches - deployment script
#!/usr/bin/env bash
# Exit on error
set -e
# Update git repository with latest
# Arg 1 - repository name
# Arg 2 - source dir
update_git () {
full_path=${2}/${1}
# If directory exists then run git stuff there
@efi-mk
efi-mk / network.yaml
Last active January 13, 2023 14:52
A cloud formation script to create a vpc with 2 private subnets and 1 public subnet
AWSTemplateFormatVersion: 2010-09-09
Description: My Network Environment
Resources:
# VPC containing 3 subnets, 1 is public, while the other 2 are private for RDS
MyVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
from firebase_admin import auth
from flask import request, abort, current_app
from functools import wraps
from configuration.settings import SHOULD_AUTHORIZE
def validate_token(access_token: str) -> tuple:
"""
Verifies that an access-token is valid and
service cloud.firestore {
match /databases/{database}/documents {
// Allow user to read only his documents. No write allowed
match /users/{user}/{document=**} {
allow read: if request.auth != null && request.auth.uid == user
}
}
}
#!/usr/bin/env bash
set -e
if [ -z "$1" ]
then
echo "Missing project name, please choose one..."
firebase list
exit 1
else
if [ -z "${FIRESTORE_TOKEN}" ]
@efi-mk
efi-mk / s3_events.py
Created August 5, 2018 11:59
S3 scheduler
scheduler = Scheduler(...)
def check_scheduled_events():
scheduler.handle()
import boto3
from s3_scheduler.scheduler import Scheduler
from s3_scheduler.utils import nowut
s3_resource = boto3.resource("s3")
s3_client = boto3.client("s3")
scheduler = Scheduler("bucket", "/path", s3_resource, s3_client)
time = nowut() + timedelta(minutes=10)
upload_to = scheduler.schedule(time, "s3-bucket", "s3_files-important", "content")
scheduler = Scheduler("bucket", "/path", s3_resource, s3_client)
time = nowut() + timedelta(minutes=10)
key = scheduler.schedule(time, "s3-bucket", "s3_files-important", "content")
scheduler.stop(key)
@efi-mk
efi-mk / .pre-commit-config.yaml
Last active September 6, 2018 18:56
pre-commit config file
fail_fast: true
repos:
- repo: https://github.com/ambv/black
rev: 18.6b4
hooks:
- id: black
language_version: python3.6
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.610-1
@efi-mk
efi-mk / .travis.yml
Last active September 7, 2018 14:32
Travis example
sudo: required
language: python
python:
- "3.6"
services:
- postgresql
addons:
postgresql: "9.6"
cache:
- pip