Skip to content

Instantly share code, notes, and snippets.

View jelloslinger's full-sized avatar

Michael Copeland jelloslinger

View GitHub Profile
from typing import Optional, Generator
from dataclasses import dataclass, field
from enum import auto, Enum
import asyncio
from collections import defaultdict
class State(Enum):
OBSERVING = auto()
OBSERVED = auto()
@akshaykarnawat
akshaykarnawat / dagster_docker.md
Last active February 28, 2024 19:18
Running dagster inside a docker container

Dagster Installation in Docker

Dagster provides a mechanism to create pipeline DAGs which can be executed in a reproducible way. The DAGs can be visualized and run through a UI.

Details here: https://docs.dagster.io/getting-started

In order to run dagster, we first need to make sure we run python in a docker container.

The following code will create the python env in a docker container and will be removed right after we exit.

@jeffposnick
jeffposnick / fallback-on-error-plugin.js
Last active February 28, 2025 07:20
Example Workbox plugin that fallsback to a cached HTML page when there's a non-200 OK navigation response.
export class FallbackOnErrorPlugin {
constructor(fallbackURL) {
this.fallbackURL = fallbackURL;
}
// This is called whenever there's a network response,
// but we want special behavior for non-2xx statuses.
fetchDidSucceed({response}) {
if (response.ok) {
// If it's a 2xx, it can be used as-is.
@leimao
leimao / chat_client.py
Created August 30, 2020 19:57
EdgeDB AsyncIO Tutorial ChatBot: https://youtu.be/SyiTd4rLb2s
from __future__ import annotations
from typing import IO
import asyncio
import sys
import contextlib
import aiofiles.threadpool
from chat_streams import split_lines, write, handle_writes
async def handle_reads(reader: asyncio.StreamReader) -> None:
@glenfant
glenfant / a_G_for_FastAPI.md
Last active June 29, 2024 06:21
A simple POC that mimics in FastAPI the "g" request lifecycle pseudo global

Like Flask "g". Good news you can do the same with FastAPI

"g" is a threadlocal magic object that lets developer add / change / remove attributes during the request lifecycle. Learn more about this "g" here.

There is no OTB equivalent in FastAPI, but thanks to the new contextvars Python 3.7+ module, I made this simple demo.

Any comment or help to improve yhis recipe is welcome.

@gene1wood
gene1wood / aws-lambda-relative-import-no-known-parent-package.md
Last active August 20, 2025 06:59
Python relative imports in AWS Lambda fail with `attempted relative import with no known parent package`

Python relative imports in AWS Lambda fail with attempted relative import with no known parent package

The Problem

In AWS Lambda if I attempt an explicit relative import like this

.
├── lambda_file.py
└── example.py
@dmontagu
dmontagu / docker-compose.deploy.volumes-placement.yml
Last active October 12, 2021 03:33
Elasticsearch config files for use with FastAPI generated project
version: '3.3'
services:
db:
volumes:
- app-db-data:/var/lib/postgresql/data/pgdata
deploy:
placement:
constraints:
- node.labels.${STACK_NAME}.app-db-data == true
es01:
@1st1
1st1 / example.py
Last active January 22, 2026 19:09
asyncio queues example
import asyncio
import random
import time
async def worker(name, queue):
while True:
# Get a "work item" out of the queue.
sleep_for = await queue.get()
@mphuie
mphuie / index.html
Last active November 1, 2025 21:25
pyqt webview javascript -> python example
<html>
<head>
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
<style>
::selection {
background:transparent;
}
</style>
</head>
@milesjordan
milesjordan / vpc.yaml
Last active September 26, 2024 20:08
Cloudformation template for a VPC with ipv6, with public and private subnets, calculating the subnet ipv6 CIDR blocks on the fly.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Public VPC and subnets
Resources:
#
# Public VPC
#
PublicVpc: