Skip to content

Instantly share code, notes, and snippets.

@alecordev
alecordev / pdf_to_html.py
Created July 8, 2025 16:04
Python PDF to HTML
#!/usr/bin/env python3
"""
PDF to HTML Converter Module
A reliable Python module for converting PDF files to standalone HTML with embedded resources.
Uses PyMuPDF (fitz) for maximum compatibility and reliability.
PyMuPDF>=1.23.0
Pillow>=9.0.0
"""
@alecordev
alecordev / client.py
Created December 18, 2024 10:17
Python simple socket
import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
local_hostname = socket.gethostname()
ip_address = socket.gethostbyname(local_hostname)
server_address = (ip_address, 23456)
sock.connect(server_address)
print('Connecting')
@alecordev
alecordev / Dockerfile
Last active December 7, 2024 12:34
Python Dockerfile
FROM python:3.12 as builder
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc \
libpq-dev
RUN python -m venv /opt/venv
@alecordev
alecordev / schemas.py
Last active June 9, 2024 14:05
Python model
import uuid
from sqlmodel import Field, Session, SQLModel, create_engine, select
# class Hero(SQLModel, table=True):
# id: uuid.UUID = Field(default=uuid.uuid4(), primary_key=True)
# # id: int | None = Field(default=None, primary_key=True)
# name: str = Field(index=True)
# secret_name: str
# age: int | None = Field(default=None, index=True)
@alecordev
alecordev / executor2.py
Created May 12, 2021 22:05
Process pool with concurrency io loops thread pool
import time
import asyncio
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, as_completed
class SyncWork:
def __init__(self):
self.active_tasks_limit = 10
def __call__(self, *args, **kwargs):
@alecordev
alecordev / notes.md
Created December 13, 2018 12:35
Benchmarking and Profiling Python

High Performance Python

Overview

Performance?

  • Memory
  • CPU/GPU
  • I/O
@alecordev
alecordev / bootstrap-local.html
Created August 3, 2018 15:31
Bootstrap Local HTML skeleton
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/*!
@alecordev
alecordev / bootstrap-remote.html
Created August 3, 2018 15:30
Bootstrap Remote HTML skeleton
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
@alecordev
alecordev / .txt
Created July 30, 2018 09:35
HTTP Error codes
Exception
HTTPException
HTTPSuccessful
* 200 - HTTPOk
* 201 - HTTPCreated
* 202 - HTTPAccepted
* 203 - HTTPNonAuthoritativeInformation
* 204 - HTTPNoContent
* 205 - HTTPResetContent
* 206 - HTTPPartialContent
@alecordev
alecordev / .py
Created October 3, 2017 15:41
Simple mouse example
import time
import logging
import pyautogui
logging.basicConfig(level=logging.DEBUG,
format='[%(asctime)s] - %(message)s')
pyautogui.FAILSAFE = False
pyautogui.PAUSE = 2.5