Skip to content

Instantly share code, notes, and snippets.

@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
@alecordev
alecordev / 0.py
Last active February 1, 2023 09:56
pycurl examples with Kerberos/NTLM
import io
import json
from pprint import pprint
import pycurl
def post(url, data):
buffer = io.BytesIO()
@alecordev
alecordev / .py
Last active April 27, 2018 11:17
Decorator and Context Manager simple examples
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
print('Wrapping')
return f(*args, **kwargs)
return wrapper
@decorator
def f():
print('Function f')
@alecordev
alecordev / index.html
Created June 7, 2017 11:35
Example vanilla JS WebSocket
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// use vanilla JS because why not
window.addEventListener("load", function() {
// create websocket instance
var mySocket = new WebSocket("ws://localhost:8080/ws");