Skip to content

Instantly share code, notes, and snippets.

View Brymes's full-sized avatar

Timothy Odebunmi Brymes

View GitHub Profile
@Brymes
Brymes / thread_example.py
Created March 4, 2024 09:31
Python Threading Snippet
import threading
import time
# Function to be executed concurrently
def print_after_delay(text, delay):
time.sleep(delay)
print(text)
@Brymes
Brymes / README.md
Created April 3, 2023 08:02 — forked from nymous/README.md
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

@Brymes
Brymes / 1.srp.py
Created November 13, 2022 09:01 — forked from dmmeteo/1.srp.py
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
@Brymes
Brymes / IP WhiteIisting.md
Last active May 9, 2023 15:32
IP WhiteIisting with Golang(Go) Gin

IP WhiteIisting with Golang(Go) Gin

Securing endpoints to specific IP addresses to prevent unauthorized access is a common practice in Backend engineering particularly for sensitive endpoints.

An Example is Securing Webhook endpoints E.g. Paystack

The files Attached

  • main.go :: Houses the server
  • middleware.go :: Houses the IP whitelisting function
@Brymes
Brymes / main.go
Created September 7, 2022 14:45
Sample Gin Application
package main
import (
"github.com/gin-gonic/gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
"net/http"
)
@Brymes
Brymes / tee.go
Created May 17, 2022 15:35 — forked from jerblack/tee.go
Golang: Mirror all writes to stdout and stderr in program to log file
package main
import (
"fmt"
"io"
"log"
"os"
)
func main() {
@Brymes
Brymes / SmartMatrixForsage.sol
Created May 2, 2022 18:24
Deploy Forsage Clone on Remix
/**
*Submitted for verification at Etherscan.io on 2020-01-31
*/
/**
*
* ,d8888b
* 88P'
*d888888P
* ?88' d8888b 88bd88b .d888b, d888b8b d888b8b d8888b