Skip to content

Instantly share code, notes, and snippets.

View vovavili's full-sized avatar
🎯
Focusing

Vladimir vovavili

🎯
Focusing
  • Paris, France
View GitHub Profile
@GhostofGoes
GhostofGoes / pyproject.toml
Last active January 31, 2025 22:28
Example pyproject.toml
# This example pyproject.toml is for a basic pip+setuptools setup.
# If you use a project management tool (like Poetry), then
# those tools will have slightly different configurations or additions.
# I highly recommend using a project management tool for your project.
# Project management is a highly opinionated subject.
# There are a lot of good, robust tools in this space now (as of 2023)
# Two that I've used and recommend are Poetry and PDM.
# Poetry is more mature, PDM is recent, both work well.
# - Poetry: https://python-poetry.org/
@hofrob
hofrob / dict_perf.py
Last active September 24, 2024 10:21
Compare timings of dict constructor with literal dict
import random
import string
import time
values = []
for i in range(10):
values.append("".join(random.choices(string.ascii_letters + string.digits, k=10)))
n = 500000
print(f"Construct {n=} dicts with these random values: {values=}")
@vovavili
vovavili / time_script.py
Last active August 30, 2024 10:10
Time Python scripts
"""Time functions using a decorator."""
import time
from collections.abc import Callable
from functools import wraps
def time_function[**P, R](func: Callable[[P], R]) -> Callable[[P], R]:
"""
Time functions using a decorator.
@nymous
nymous / README.md
Last active April 22, 2025 21:37
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

# -*- coding: utf-8 -*-
import os
from html.parser import HTMLParser
import dash
import pandas as pd
import plotly.express as px
import requests
from dash import html, dcc, dash_table, Input, Output

The issue

When a fixture is not used but needs to be included for some reasons, pylint will rightfully issue a warning. For instance, a fixture setup a specific database state and another fixture include it to ensure database is in a specific state.

@pytest.fixture
def init_database():
    """Setup database state"""
    ...
@danielwetan
danielwetan / nodejs-cicd-github-actions.md
Last active April 25, 2025 16:39
Deploy Node.js to VPS using Github Actions

Deploy Node.js to VPS using Github Actions

Steps to deploy Node.js to VPS using PM2 and Github Actions

1. Clone repo to VPS folder

@kgriffs
kgriffs / results.py
Created May 21, 2021 23:05
Benchmarking Python JSON libs: std vs. orjson vs. simdjson - simple encode/decode tests
# ----------------------------------------------------------------------------
import json
import simdjson
import libpy_simdjson
decoder_std = json.JSONDecoder()
encoder_std = json.JSONEncoder(ensure_ascii=False)
p = simdjson.Parser()
p2 = libpy_simdjson.Parser()