Skip to content

Instantly share code, notes, and snippets.

@skamensky
skamensky / plpython_type_definitions.py
Last active February 21, 2023 10:00
Python type hinting for the PL/Python language module. Module documentation can be found in various subpages of the plpython docs https://www.postgresql.org/docs/15/plpython.html
"""Python type hinting for the PL/Python language module. Module documentation can be found in various subpages of the plpython docs https://www.postgresql.org/docs/15/plpython.html
This file was written by investigating the runtime plpy attributes and by reading the source code https://github.com/postgres/postgres/tree/master/src/pl/plpython
"""
from contextlib import contextmanager, AbstractContextManager
from typing import Union, Optional, Literal, List, Any, Dict, Iterable, ContextManager
# spi vals taken from https://github.com/postgres/postgres/blob/8028e294b456bf1539649527fd98b3985fa4752a/src/include/executor/spi.h
SPI_ERROR_CONNECT = -1
SPI_ERROR_COPY = -2
@skamensky
skamensky / find_decorator_limit.py
Last active September 19, 2021 14:10
How many times can you decorate a function in python?
from functools import wraps
import timeit
MAX_DEC_FUNCTION = None
def do_nothing_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
@skamensky
skamensky / uwsgi.ini
Created August 25, 2021 15:12
A good default uwsgi setup for gevent+ flask-socketio
[uwsgi]
# thanks to https://www.techatbloomberg.com/blog/configuring-uwsgi-production-deployment/
strict = true
socket = :5000
http-websockets = true
master = true
die-on-term = true
memory-report = true
wsgi-file = main.py
callable = app
@skamensky
skamensky / is_asyncio_worth_it.py
Created June 6, 2021 13:48
Is asyncio worth it if you're only doing http requests?
import asyncio
from concurrent.futures import ThreadPoolExecutor
from functools import wraps
from threading import Thread
from time import monotonic,sleep
import aiohttp
import requests
# taken from https://gist.githubusercontent.com/demersdesigns/4442cd84c1cc6c5ccda9b19eac1ba52b/raw/cf06109a805b661dd12133f9aa4473435e478569/craft-popular-urls
from concurrent.futures import ThreadPoolExecutor
import boto3
import traceback
from datetime import datetime
from aws_utils.throttling import throttle_protected
cluster_id = 'j-3KACTKX2AD5D6'
steps = []
step_data = {}
@skamensky
skamensky / detect_online_offline_with_fetch.js
Last active June 9, 2020 16:24
Overwrites fetch in the global window namespace in a "decorator-like". Pings google. If the request fails, we assume we are offline. If the request succeeds, we know we are online. The connect and disconnect checks are dispatched as events. If you want to check if a specific fetch call failed to connect to the internet, the fetch promise will fa…
window._fetchBackup = fetch;
fetch = async (...args)=>{
try{
await window._fetchBackup("https://8.8.8.8");
window.dispatchEvent(new Event('internetConnected'));
return window._fetchBackup(...args)
}
@skamensky
skamensky / clean_ditto_db.py
Last active February 28, 2024 08:05
This script is intended to be used in conjunction with the Ditto clipboard manager (https://ditto-cp.sourceforge.io/). This script queries the ditto.db file for any images, writes the images to disk, and deletes the data from the ditto.db file.
import sqlite3
import os
from io import BytesIO
from PIL import Image
from pathlib import Path
working_directory = Path(__file__).parent
db = sqlite3.connect(Path(working_directory, "Ditto.db"))
cursor = db.cursor()
import os
import traceback
import warnings
'''
inspired by https://gist.github.com/bennylope/2999704
Allows you to write .env files and use the environment variables in your scripts.
Useful for using variable data/secrets during development/staging environment.
'''
NAICS Code Industry Description
541519 Other Computer Related Services
541512 Computer Systems Design Services
322121 Paper (Except Newsprint) Mills
517110 Wired Telecommunications Carriers
511210 Software Publishers
334111 Electronic Computer Manufacturing
541611 Administrative Management and General Management Consulting Services
541511 Custom Computer Programming Services
443120 Computer and Software Stores