View release.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
tags: | |
- "v*.*.*" | |
jobs: | |
build: | |
runs-on: ubuntu-latest |
View run_with_wait.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncio import coroutines, events, tasks | |
def run_with_wait(main, *, debug=None): | |
""" | |
Difference from asyncio.run(): | |
- asyncio.run() cancels all tasks when `main` is completed. | |
any tasks created using `asyncio.create_task()` will hence be cancelled. | |
- run_with_wait() waits for all tasks to be completed using | |
`run_until_complete()` and `asyncio.tasks.gather()` |
View Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.10 AS base | |
WORKDIR /app | |
RUN curl -sSL https://install.python-poetry.org | python3 - | |
COPY ./poetry.lock /app/poetry.lock | |
COPY ./pyproject.toml /app/pyproject.toml |
View introspect_model_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from sqlalchemy import MetaData, Table | |
from sqlalchemy.ext.asyncio import AsyncSession as _AsyncSession | |
from sqlalchemy.ext.asyncio import create_async_engine | |
from sqlalchemy.orm import sessionmaker | |
logger = logging.getLogger(__name__) | |
meta = MetaData() |
View poetry_to_lambda.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OLDPWD=$(pwd) \ | |
&& cd "$(poetry env info --path)/lib/python3.9/site-packages" \ | |
&& zip -r9 ./app.zip . -x "*.pyc" \ | |
&& mv ./app.zip $OLDPWD \ | |
&& cd $OLDPWD \ | |
&& zip -rg ./app.zip ./app \ | |
&& aws lambda update-function-code --function-name my_function --zip-file fileb://app.zip | |
# A better alternative is to first upload to an S3 bucket, then update the function |
View to_snake_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import unidecode | |
def to_snake_case(text): | |
""" | |
Convert unicode text to snake case | |
>>> to_snake_case("My favourite dish was raclette.") |
View fastapi_test_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlette.testclient import TestClient | |
class CookieConfigurableTestClient(TestClient): | |
_access_token = None | |
def set_access_token(self, token): | |
self._access_token = token | |
def reset(self): |
View craft_lambda_trigger_event.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import gzip | |
import json | |
event = { | |
"logGroup": "/ecs/melvin-dev", | |
"logStream": "ecs/melvin-dev/XXXXXXXXXX", | |
"owner": 100000000000, | |
"logEvents": [{ |
View main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ref: https://github.com/terraform-providers/terraform-provider-aws/pull/3485#issuecomment-397918310 | |
resource "aws_ecs_service" "web" { | |
name = "web_service_${var.environment}_${replace(timestamp(), ":", "-")}" | |
cluster = aws_ecs_cluster.web.id | |
task_definition = aws_ecs_task_definition.web.arn | |
desired_count = 1 | |
force_new_deployment = true |
View celery_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
from celery import Celery | |
from celery.schedules import crontab | |
from celery.signals import after_setup_logger, after_setup_task_logger | |
from django.conf import settings | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") |
NewerOlder