Skip to content

Instantly share code, notes, and snippets.

View florimondmanca's full-sized avatar
🌱

Florimond Manca florimondmanca

🌱
View GitHub Profile
@florimondmanca
florimondmanca / server.js
Last active July 15, 2018 07:59
Lightweight Angular production server
/*
npm install --save express morgan
*/
const express = require('express');
const morgan = require('morgan');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.use(morgan('combined'))
app.get('*', function(req, res) {
@florimondmanca
florimondmanca / nginx.conf
Created July 15, 2018 08:01
Simple Nginx configuration for serving an Angular build
server {
listen 80;
# server_name YOUR_SERVER_NAME;
root /path/on/server/to/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
@florimondmanca
florimondmanca / set-env.js
Created July 15, 2018 08:09
Build-time environment variable injection script for Angular apps
/* Generate environment.ts file using environment variables
Requires:
npm install --save yargs
npm install --save dotenv
Usage:
node set-env.js --env=dev
Put variables in a local .env file so they can be
@florimondmanca
florimondmanca / makemigrations.py
Created July 28, 2018 17:19
Script to run a stand-alone equivalent of Django's `manage.py makemigrations`
"""Script to run a stand-alone equivalent of Django's `makemigrations`."""
import sys
import django
from django.conf import settings
from django.core.management import call_command
def makemigrations(app_name: str):
@florimondmanca
florimondmanca / serializers.py
Last active September 21, 2024 10:34
DRF-inspired ModelSerializer implementation backed by Pydantic and Tortoise ORM
import datetime
import decimal
import json
from typing import Any, Optional, Type, Union, Dict, Tuple
from pydantic import BaseModel, ValidationError, create_model
from tortoise import fields as tortoise_fields
from tortoise.fields import Field
from tortoise.models import Model as TortoiseModel
@florimondmanca
florimondmanca / task_id_contextvars_demo.py
Created September 8, 2019 18:21
Sharing a task ID across coroutines using contextvars (Trio-based)
import trio
import contextvars
LAST_TASK_ID = 0
TASK_ID: contextvars.ContextVar[str] = contextvars.ContextVar("task_id")
async def producer(num_items: int, send_channel: trio.MemorySendChannel) -> None:
task_id = TASK_ID.get()
iden = f"Producer {task_id}"
@florimondmanca
florimondmanca / asgi-packages.md
Last active July 25, 2024 23:53
ASGI Packages

A list of ASGI-related Python packages I maintain:

@florimondmanca
florimondmanca / README.md
Last active August 22, 2024 15:05 — forked from imbolc/httpx_aiohttp.py
HTTPX vs aiohttp (over HTTPS)

Usage

  • Generate TLS certificates for localhost:
pip install trustme-cli
trustme-cli
  • Run wrk on each endpoint, eg:
@florimondmanca
florimondmanca / example_httpcore.py
Last active August 4, 2020 06:34
Proof of concept for an `httpcore` Unix Domain Socket (UDS) transport, compatible with asyncio and trio. Also contains an anyio implementation example.
"""
Example using the transport directly.
"""
import json
from httpcore_uds import AsyncUDSTransport
async def main() -> None:
"""
@florimondmanca
florimondmanca / httpx-urllib3.md
Last active September 3, 2024 20:47
URLLib3 transport implementation (Extracted from HTTPX)

Changelog:

  • 2024-07-15: updated to support recent HTTPX versions, based on @karpetrosyan's comment.
  • 2021-01 (ish): initial version

urllib3-transport

An HTTPCore transport that uses urllib3 as the HTTP networking backend. (This was initially shipped with HTTPX.)