Skip to content

Instantly share code, notes, and snippets.

View cbonesana's full-sized avatar
👾
bip bip bip

Claudio Bonesana cbonesana

👾
bip bip bip
View GitHub Profile
@cbonesana
cbonesana / Dockerfile
Created June 11, 2024 21:32
Federated Learning is just a glorified chat
FROM python:3.12.3
RUN pip install \
pandas \
scikit-learn \
fastapi \
aiofiles
@cbonesana
cbonesana / main.py
Created October 19, 2023 20:39
Pydantic and how to manage subclasses
from typing import Any
from pydantic import BaseModel, root_validator
import json
# this dictionary will collect all classes constructors
class_registry: dict[str, Any] = dict()
# base class
class Creature(BaseModel):
@cbonesana
cbonesana / main.py
Created September 28, 2023 14:02
Run ray multi threading with sqlalchemy and sqlite database, in python.
from sqlalchemy import create_engine
from sqlalchemy import select, insert, func
from tables import Base, Record
from time import time
import ray
import uuid
@cbonesana
cbonesana / resources.py
Created March 7, 2023 12:41
Producer and consumer using python, with KeyboardInterrupt ctrl+c
from multiprocessing import Queue, Process
import random
import time
import signal
stop_sentinel = "STOP"
@cbonesana
cbonesana / pydantic_enum.py
Last active October 3, 2022 14:04
Working with string enums and pydantic objects in python
from pydantic import BaseModel
from enum import Enum
import json
class Season(str, Enum):
SPRING = 'spring'
SUMMER = 'summer'
AUTUMN = 'autumn'
@cbonesana
cbonesana / esperiment.py
Created August 5, 2022 09:37
Experimenting using multiprocessign and signals in python.
import time
import multiprocessing
import signal
from multiprocessing import Event
class W(multiprocessing.Process):
def __init__(self, i: int, event: Event) -> None:
super().__init__()
@cbonesana
cbonesana / shared_pointers.cpp
Created January 13, 2022 11:05
C++ Shared pointers
#include <iostream>
#include <memory>
#include <string>
// This is just an example object with a text field.
class Content {
public:
std::string txt;
Content(std::string txt) : txt(txt){};
};
@cbonesana
cbonesana / ProgressBar.java
Created October 6, 2021 14:08
A class for a Progress Bar in Java
package utility;
import java.time.Duration;
import java.util.Collections;
/**
* Author: Claudio "Dna" Bonesana
* Project: SimpleProgressBar
* Date: 06.10.2021 14:27
*/
@cbonesana
cbonesana / exec.sh
Created April 1, 2020 15:58
Run a python scirpt inside docker 🐳
#!/bin/bash
docker run -it --rm -v "$(pwd)":"/w" -w "/w" python:3.8-slim python scripty.py
import logging
import os
import sys
import lxml.etree as etree
from openpyxl import load_workbook
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)