Skip to content

Instantly share code, notes, and snippets.

View mosquito's full-sized avatar
✍️
just writing some code

Mosquito mosquito

✍️
just writing some code
  • Nebius
  • Netherlands
View GitHub Profile
@mosquito
mosquito / README.md
Last active March 27, 2024 10:44
BOOBEN is a system boot notifier

BOOBEN

BOOBEN is a Python script that notifies you when your system starts or stops, using your system's Mail Transfer Agent (MTA) to send out emails. Right out of the box, it includes useful info like server status, the time of the event, ZFS pool status, network interface details, and logs from journald and dmesg. Feel free to tweak it by adding what you need or removing what you don't. It's made to be easy to customize to your liking.

Requirements

  • Python 3
  • A configured system MTA (like sendmail) that respects /etc/aliases.

Installation

import platform
from pathlib import Path
match platform.system():
case 'Linux':
CACHE_PATH = Path(os.getenv("XDG_CACHE_HOME", '~/.cache'))
case 'Darwin':
CACHE_PATH = Path('~') / 'Library' / 'Caches'
case 'Windows':
@mosquito
mosquito / Dockerfile
Created July 20, 2023 12:42
Asterisk 20 with opus g729 on archlinux
##############################################################################
FROM archlinux as build
RUN pacman -Syyu --noconfirm
RUN pacman -S --noconfirm git base-devel
RUN useradd -m builder
RUN mkdir -p /root/packages
USER root
RUN pacman -S --noconfirm \
alsa-lib curl jansson libedit libvorbis libxml2 libxslt \
@mosquito
mosquito / progress.py
Last active April 10, 2023 09:28
Pure python progressbar without dependencies
import sys
from os import get_terminal_size
from typing import Sequence, TypeVar, Generator, Any
__license__ = "MIT"
__doc__ = """
The point of this project is to give you some code you can easily copy and paste
into your own stuff so you don't have to go through the trouble of dragging in
an any dependency like tqdm or rich.
@mosquito
mosquito / autoindex.py
Created December 25, 2022 07:31
Static generated index
from argparse import ArgumentParser
from os import walk, chdir, getcwd
from pathlib import Path
from contextlib import contextmanager
from datetime import datetime
from jinja2 import Environment, BaseLoader, select_autoescape
env = Environment(
loader=BaseLoader,
autoescape=select_autoescape(['html', 'xml'])
@mosquito
mosquito / asyncio_rlock.py
Created April 18, 2022 10:10
RLock for asyncio
from typing import Any
import asyncio
class RLock(asyncio.Lock):
""" RLock like threading.RLock but use asyncio tasks as an ident """
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.loop = asyncio.get_event_loop()
self._owner: Optional[asyncio.Task] = None
@mosquito
mosquito / README.md
Last active November 15, 2022 08:33
Wireguard client config python generator

Wireguard client config generator

Generates config files for mobile apps (qr code) and text configs

Installation

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
long_description_content_type='text/markdown'
import asyncio
from concurrent.futures._base import Executor
from multiprocessing import Pool, cpu_count
class ProcessPoolExecutor(Executor):
def __init__(self, max_workers=max((cpu_count(), 4)), **kwargs):
self.__futures = set()
self.__pool = Pool(processes=max_workers, **kwargs)