Skip to content

Instantly share code, notes, and snippets.

@adtac
adtac / Dockerfile
Last active May 28, 2024 01:38
#!/usr/bin/env docker run
#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')"
# syntax = docker/dockerfile:1.4.0
FROM node:20
WORKDIR /root
RUN npm install sqlite3
@nguqtruong
nguqtruong / fastapi_app.py
Created April 8, 2021 16:21
Integrate Sentry to FastAPI
import os
from fastapi import FastAPI
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
import sentry_sdk
sentry_sdk.init(
dsn='your Sentry dns', # CHANGE HERE
environment=os.getenv('ENV', 'dev'), # You should read it from environment variable
@Dminor7
Dminor7 / azure_blob_storage_dataframe.py
Last active November 11, 2023 23:09
Upload DataFrame to Azure Blob Storage as CSV file and Download CSV file as dataframe. Azure Python v12.5.0
import os, uuid
from io import BytesIO
from datetime import datetime
from urllib.parse import urlparse
from azure.storage.blob import BlobServiceClient
import pandas as pd
def azure_upload_df(container=None, dataframe=None, filename=None):
"""
Upload DataFrame to Azure Blob Storage for given container
@srameshr
srameshr / gist:d6778ffdcb8ad805f29c4e3826c060f9
Created September 7, 2020 15:03
Installing latest version of FFMPEG and FFPROBE on AWS ElasticBeanstalk via .ebextensions
Create a folder at the root of your app or project called ```.ebextensions```
Inside the folder ```.ebextensions``` create a file called ```01_ffmpeg.config```
Inside this file paste in the below contents:
```
commands:
command1:
command: ls
command2:
command: "cd /usr/local/bin"
@aaronpolhamus
aaronpolhamus / redis_handlers.py
Created August 9, 2020 02:06
task locking with redis + celery
"""Task locking with redis in celery is hard, and good examples are tough to come by. This is the approach that's
worked for me, based on great work that other folks have posted:
* https://breadcrumbscollector.tech/what-is-celery-beat-and-how-to-use-it-part-2-patterns-and-caveats/
* http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
* https://redis.io/topics/distlock
This isn't polished,but hopefully it's useful. To verify it in our local test env we register the following test task in
our definitions file:
*** definitions.py ***
@djm
djm / AuthorizerConfigurationException-problem.txt
Last active July 1, 2024 15:27
Fix for AWS API Gateway Custom Authorizer Error => AuthorizerConfigurationException (message: null)
Problem: you've created a Custom Authorizer Lambda and have hooked it up with Amazon AWS's API Gateway.
But now all of your responses return the following HTTP response with the "AuthorizerConfigurationException"
and your Cloudwatch logs for your Authorizer function are next to useless..
-----
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Length: 16
Content-Type: application/json
@danilop
danilop / template.yaml
Last active February 29, 2024 12:50
Sample AWS SAM Template using Provisioned Concurrency with Application Auto Scaling
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sample SAM Template using Application Auto Scaling + Provisioned Concurrency
Globals:
Function:
Timeout: 30
@VictorGob
VictorGob / Dockerfile_postgresql_plpy3
Last active October 30, 2023 08:46
Dockerfile for Postgresql + PLpython3
FROM postgres:12
# Create plpython3u when the db starts.
RUN echo 'CREATE EXTENSION IF NOT EXISTS plpython3u;' > /docker-entrypoint-initdb.d/py3.sql
# Installing last python and plpython3 for current version
RUN apt update && apt install python3 python3-pip postgresql-plpython3-${PG_MAJOR} -y
@gerardev
gerardev / database.py
Created November 15, 2019 21:41
Connect to AWS Document DB using SSH Tunnel in python
from sshtunnel import SSHTunnelForwarder
from pymongo import MongoClient
ssh_tunnel_host = 'our-ec2-hostname.compute-1.amazonaws.com'
ssh_tunnel_port = 22
ssh_tunnel_user = 'ubuntu'
ssh_tunnel_pkey = 'ec2-hostname.pem'
db_user = 'database-user'
db_pass = 'database-pass'
@jefftriplett
jefftriplett / python-django-postgres-ci.yml
Last active March 27, 2024 04:27
This is a good starting point for getting Python, Django, Postgres running as a service, pytest, black, and pip caching rolling with GitHub Actions.
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services: