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 May 4, 2024 12:42
Add doker-compose as a systemd unit

Docker compose as a systemd unit

Create file /etc/systemd/system/docker-compose@.service. SystemD calling binaries using an absolute path. In my case is prefixed by /usr/local/bin, you should use paths specific for your environment.

[Unit]
Description=%i service with docker compose
PartOf=docker.service
After=docker.service
@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

@mosquito
mosquito / aio_pipe.py
Last active March 1, 2024 16:46
Asyncio PIPE
import asyncio
import fcntl
import os
from functools import partial
class AsyncPIPE:
@staticmethod
def create_pipe():
read_fd, write_fd = os.pipe()
def ip2hex(cidr, router):
addr, mask = cidr.split("/")
mask = int(mask)
addr = [("%2s" % hex(int(i))[2:]).replace(" ", "0") for i in addr.split(".") if i != "0"]
parts = mask/8 - len(addr)
if mask%8 > 0:
parts += 1
if parts > 0:
for i in range(int(parts)):
addr.append("00")
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':
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
# /etc/screenrc
#
# This is the system wide screenrc.
#
# You can use this file to change the default behavior of screen system wide
# or copy it to ~/.screenrc and use it as a starting point for your own
# settings.
@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 / nodeproxy.py
Last active March 6, 2023 11:23
Python Nodejs Proxy
#!/usr/bin/env python
# encoding: utf-8
import json
from subprocess import Popen, PIPE
wrapper = u'''
(function run(globals) {
try {
var result = (%(func)s).apply(globals, %(args)s);
@mosquito
mosquito / requirements.txt
Last active February 7, 2023 16:10
RTSP to HTTP python proxy
tornado>4
construct