Skip to content

Instantly share code, notes, and snippets.

View ArthurDelannoyazerty's full-sized avatar

Arthur Delannoy ArthurDelannoyazerty

View GitHub Profile
@ArthurDelannoyazerty
ArthurDelannoyazerty / Postgresql_liten_notify_while_doing_other_synchronous_job.py
Last active January 28, 2025 15:06
Small code to listen to a postgress NOTIFY while doing a normal function at the same time. No async job (except the actual listener). The NOTIFY listener is launched with asyncio in another thread while the normal job is executed in the main thread
import asyncio
import logging
import os
import psycopg2
import threading
import time
from dotenv import find_dotenv, load_dotenv
def listen_to_notifications():
@ArthurDelannoyazerty
ArthurDelannoyazerty / listen.py
Created January 27, 2025 11:05 — forked from kissgyorgy/listen.py
How to use PostgreSQL's LISTEN/NOTIFY as a simple message queue with psycopg2 and asyncio
import asyncio
import psycopg2
# dbname should be the same for the notifying process
conn = psycopg2.connect(host="localhost", dbname="example", user="example", password="example")
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cursor = conn.cursor()
cursor.execute(f"LISTEN match_updates;")
@ArthurDelannoyazerty
ArthurDelannoyazerty / backend.py
Last active January 21, 2025 15:47
A simple example of flask socketIO
import os
from dotenv import find_dotenv, load_dotenv
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
from flask_socketio import SocketIO, emit, send
# LOAD ENV VARIABLES -----------------------------------------------------------------------------------
load_dotenv(find_dotenv())
backend_ip = os.environ.get("BACKEND_IP")
@ArthurDelannoyazerty
ArthurDelannoyazerty / s3.py
Created January 8, 2025 16:21
A small python scirpt that can connect, search and download from a s3 bucket.
import os
import logging
import boto3
from tabulate import tabulate
from dataclasses import dataclass
from dotenv import find_dotenv, load_dotenv
logger = logging.getLogger(__name__)
@ArthurDelannoyazerty
ArthurDelannoyazerty / interface_sql.py
Last active August 25, 2025 09:18
Utils class that connect to a DB (or create on) and send queries
import psycopg2 # pip install psycopg2-binary
from typing import Optional
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
__all__ = ['InterfaceSQL']
class InterfaceSQL:
def __init__(self, database:str, host:str, port:str, user:str, password:str, create_db_if_not_exists: bool=True):
@ArthurDelannoyazerty
ArthurDelannoyazerty / logger.py
Last active March 4, 2025 10:41
Small python logger init.
import logging
from datetime import datetime
def setup_logging(log_name:str,
log_dir:str='logs/',
level_library = logging.INFO,
level_project = logging.DEBUG):
"""Setup the logging global parameters.
:param str log_name: The name of the gile that contains the logs for this session
@ArthurDelannoyazerty
ArthurDelannoyazerty / create_llm.py
Created December 17, 2024 13:59
Code to create a LLM with Ollama and llamaindex.
import logging
import os
from llama_index.embeddings.ollama import OllamaEmbedding
from llama_index.llms.ollama import Ollama
from llama_index.core import Settings
from enum import StrEnum
from dotenv import find_dotenv, load_dotenv
@ArthurDelannoyazerty
ArthurDelannoyazerty / api_python.py
Created December 17, 2024 13:57
Simple code for a request in python
import requests
import logging
from fastapi import HTTPException
logger = logging.getLogger(__name__)
def query_api(link: str) -> dict:
"""Query a given url and return the json response.
:param str link: The url to query

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@ArthurDelannoyazerty
ArthurDelannoyazerty / plot_altitude_gpx.py
Last active June 27, 2024 14:29
Plot the altitude over the distance from GPX files
import gpxpy
import matplotlib.pyplot as plt
import os
import re
from itertools import accumulate
size = 1.2
gpx_folderpath = "gpx/"