Skip to content

Instantly share code, notes, and snippets.

@dmwyatt
dmwyatt / filetype_types.py
Last active February 21, 2024 21:18
A Union of all file types in `filetype` package
frofrom typing import Union
from filetype.types import application, archive, audio, document, font, image, video
ImageFileType = Union[
image.Dwg,
image.Xcf,
image.Jpeg,
image.Jpx,
image.Apng,
{
"manifest_version": 3,
"name": "Superpower ChatGPT",
"version": "5.1.2",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzG6ZR+j3lpHF0XrDLIXdrk25idObfq+RK7WM+pIaQmDO2nM5Y+SZJJbFwyxjWX+3V6XOgS5v9Lpnqg46OJ/W9Q5i23Usx1MXgaJBTlEFz0XG+PYK6BElhc9itS7m6oCLknin97a533tusXmm8zW7kaDGy8vycMDY6Ffbqa3sn0PqZ8bXUlAjgO91dQcB8EtlT906hwhZjtfEYvp2hdxYkRFxfuaR1WMLkxttVXv506RXJowxq0LO3aqj83QeJoXkQF1wbzCxYO1VpVGEmYIQxIKw/csusZNZs8gwJrIWtOzhMgDNOFzXNeZl0ASgoj2M9UsZp+Dunn57VT8tQyaE6QIDAQAB",
"description": "ChatGPT with superpowers! Sync/search history locally, create folders, export all chats, pin messages, access thousands of prompts",
"icons": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
import ast
import astor
import tkinter as tk
from tkinter import scrolledtext, IntVar, Checkbutton
class EllipsisTransformer(ast.NodeTransformer):
def __init__(self, remove_args, remove_methods):
self.remove_args = remove_args
self.remove_methods = remove_methods
@dmwyatt
dmwyatt / render.schema.json
Created May 7, 2023 19:20
A start at a render.yaml json schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"services": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {"type": "string"},
@dmwyatt
dmwyatt / path_walk.py
Last active October 25, 2023 21:50
[breadth-first path walk] Walk a directory tree yielding all files and directories using a breadth-first algo.
def path_walk(path: str) -> Generator[str, None, None]:
"""Walks a directory tree yielding all files and directories.
This uses a breadth-first algorithm.
"""
queue = deque([path])
while queue:
current = queue.popleft()
for entry in os.scandir(current):
entry: os.DirEntry
@dmwyatt
dmwyatt / knownpaths.py
Created January 28, 2022 17:41 — forked from mkropat/knownpaths.py
Python wrapper around the SHGetKnownFolderPath Windows Shell function
import ctypes, sys
from ctypes import windll, wintypes
from uuid import UUID
class GUID(ctypes.Structure): # [1]
_fields_ = [
("Data1", wintypes.DWORD),
("Data2", wintypes.WORD),
("Data3", wintypes.WORD),
("Data4", wintypes.BYTE * 8)
@dmwyatt
dmwyatt / read_dot_env.py
Created December 25, 2021 19:48
[read dot env] Read a .env file and set the env vars
with suppress(FileNotFoundError):
with open('.env') as f:
line = f.readline()
while line:
k, v = line.split('=', 1)
os.environ[k] = v.strip()
line = f.readline()
@dmwyatt
dmwyatt / setqueue.py
Created October 17, 2021 17:11
[SetQueue] A Queue that behaves like a Set #datastructure
class SetQueue(Queue):
def _init(self, maxsize):
self.queue = set()
def _put(self, item):
self.queue.add(item)
def _get(self):
return self.queue.pop()
@dmwyatt
dmwyatt / monitor.py
Created October 16, 2021 21:13
[monitor windows files] Monitors files and folders or directories. #system #windows
import time
from pathlib import Path
import pywintypes
import win32con
import win32file
import winerror
WATCHED_DIR = str(Path("./").absolute())
@dmwyatt
dmwyatt / docstrings.py
Last active May 25, 2021 20:07
[Sphinx docs as markdown] Parse autodoc as markdown #sphinx
# based on https://stackoverflow.com/a/56428123/23972
import commonmark
def docstring(app, what, name, obj, options, lines):
if len(lines) > 1 and lines[0] == "@&ismd":
md = "\n".join(lines[1:])
ast = commonmark.Parser().parse(md)
rst = commonmark.ReStructuredTextRenderer().render(ast)
lines.clear()