Skip to content

Instantly share code, notes, and snippets.

View erewok's full-sized avatar

Erik erewok

View GitHub Profile
@erewok
erewok / connection_pooling.py
Last active February 20, 2024 20:39
Azure Python SDK Connection Pooling (Sharing)
"""
connection_pooling.py
The idea for our Azure clients is that unlike database connections
*all of our clients can be reused* across multiple requesters.
What we really need to achieve is the following:
- A "pool" of connections, where
- Each connection may be shared by more than 1 requester, and
- Each connection has an idle lifespan.
@erewok
erewok / pyproject.toml
Last active March 7, 2023 22:37
Azure service-bus Receiver with Opentelemetry Tracing Bug
[tool.poetry]
name = "service-bus-otel-test"
version = "1.0.0"
description = "Service Bus otel test"
authors = ["Erik Aker <eraker@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.11"
azure-core = "^1.26.3"
azure-servicebus = "7.8.2"
@erewok
erewok / compose.py
Last active August 17, 2022 20:34
Python function composition
"""compose.py - Function composition in Python
"""
# Python module for function composition
from functools import reduce, wraps
from itertools import chain
from typing import Callable, Generic, TypeVar
#!/bin/bash
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
echo "Cloud Init is still configuring the server."
sleep 1
done
echo "Cloud Init config complete. Lets build some apps!"
@erewok
erewok / Dockerfile
Created August 15, 2020 19:32
Cabal-stack Dockerfile
FROM debian:stretch-slim as base_os
## ensure locale is set during build
ENV LANG C.UTF-8
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
build-essential \
@erewok
erewok / streaming_streaming_base_middleware.py
Last active August 4, 2020 15:32
Example Starlette app to test different scenarios with BaseHttpMiddleware
import asyncio
import json
import uvicorn
from starlette.applications import Starlette
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.background import BackgroundTask
from starlette.responses import JSONResponse, PlainTextResponse, StreamingResponse
class TransparentMiddlewareNoStreaming(BaseHTTPMiddleware):
@erewok
erewok / flask_app.py
Last active March 12, 2024 14:57
JSON Logging Inside a Flask Application: configuration for producing JSON logs under a Flask app running under gunicorn
"""
flask application
"""
import logging
import logging.config
import os
from flask import Flask
import structlog
@erewok
erewok / servant_custom_error.hs
Last active April 28, 2017 14:51
Custom Error as JSON from inside Handler
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Api.Post
(
PostApi
@erewok
erewok / install_stack.sh
Created April 25, 2017 05:10
install stack for travis
set -o errexit -o verbose
if test -f "$HOME/.local/bin/stack"
then
echo 'Stack is already installed.'
else
echo "Installing Stack for $TRAVIS_OS_NAME..."
URL="https://www.stackage.org/stack/$TRAVIS_OS_NAME-x86_64"
curl --location "$URL" > stack.tar.gz
gunzip stack.tar.gz
@erewok
erewok / Api.hs
Last active July 7, 2018 20:08
Haskell Servant Persistent Example
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
module Api where
import Control.Monad.Reader (ReaderT, runReaderT)
import Control.Monad.Trans.Either (EitherT)
import Data.Int (Int64)
import Servant