Skip to content

Instantly share code, notes, and snippets.

View FluffyDietEngine's full-sized avatar
🤓
Grateful

Santhosh Solomon FluffyDietEngine

🤓
Grateful
  • Advarisk
  • Pune
View GitHub Profile
@FluffyDietEngine
FluffyDietEngine / app.py
Created December 5, 2023 04:02
Celery settings for better performance and reliability
from celery import Celery
app = Celery('myapp', broker='pyamqp://guest@localhost//')
# Configure MySQL as the result backend
app.conf.result_backend = 'db+mysql://user:password@localhost/mydb'
# Set the default queue, exchange, and routing key
app.conf.task_default_queue = 'default_queue'
app.conf.task_default_exchange = 'default_exchange'
@FluffyDietEngine
FluffyDietEngine / custom_session.py
Created December 1, 2023 04:26
Bypass `[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1006)` with custom `requests.adapters.HTTPAdapter`
from requests import Session
from requests import adapters
from urllib3 import poolmanager
from ssl import create_default_context, Purpose, CERT_NONE
class CustomHttpAdapter (adapters.HTTPAdapter):
def __init__(self, ssl_context=None, **kwargs):
self.ssl_context = ssl_context
super().__init__(**kwargs)
@FluffyDietEngine
FluffyDietEngine / connect-to-openai-assistant.py
Last active December 1, 2023 04:22
How to connect to OpenAI assistant through API?
from time import sleep
from openai import OpenAI
question_to_be_asked = "add exception for `a = 1/0`"
assistant_id = "asst_sniCqROg8nEFXNBwYoz2sE64"
client = OpenAI(api_key="your_key_here")
@FluffyDietEngine
FluffyDietEngine / pydantic_timestamp.py
Last active October 26, 2023 17:52
behavioural confusion of default value
from pydantic import BaseModel
from datetime import datetime
from time import sleep
print(datetime.now()) # 2023-10-26 22:43:50.878798
class TestClass(BaseModel):
attribute_1: str
timestamp: datetime = datetime.now() # taking time from here
//[dependencies]
// reqwest = { version = "0.10.0-alpha.2", features = ["blocking"] }
// tl = "0.7.7"
extern crate reqwest;
extern crate tl;
use std::time::Instant;
// need to add return type
fn main() {
@FluffyDietEngine
FluffyDietEngine / exception_handle.py
Last active October 20, 2023 06:26
exception handler - advalearn 20 Oct
'''
1. Create a function for addition
2. expect an error
3. Handle the error
4. write a condition if there is no error
5. write a block of code if there is no error
'''
import logging
from enum import Enum
from fastapi import FastAPI
from aenum import extend_enum
from coolname import generate_slug
from models import DropDownChoices
class DropDownChoices(str, Enum):
...