Skip to content

Instantly share code, notes, and snippets.

View cofob's full-sized avatar
🏳️‍🌈

Egor Ternovoy cofob

🏳️‍🌈
View GitHub Profile
@cofob
cofob / migrate.py
Last active March 29, 2024 15:54 — forked from chirauki/migrate.py
KVM migration script
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3Packages.libvirt python3Packages.paramiko python3Packages.urllib3
import logging
import argparse
import libvirt
import sys
import os
import subprocess
import paramiko
import xml.etree.ElementTree as ET
@cofob
cofob / arduino.ino
Last active March 29, 2024 09:27
Accelerometer + button
#include <Wire.h> // Wire library - used for I2C communication
int ADXL345 = 0x53; // The ADXL345 sensor I2C address
float X_out, Y_out, Z_out; // Outputs
const int BUTTON_READ_PIN = 5;
const int BUTTON_POWER_PIN = 6;
void setup() {
@cofob
cofob / install_nixos.sh
Created March 18, 2024 14:30
Aeza install NixOS
#!/usr/bin/env bash
curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-23.11 doNetConf=y bash -x

Автоматическая отправка результатов генерации Eris в телеграм чат

Копируем скрипт ниже, заменяем на второй строке PATH на путь до родительской папки, где лежит SD. TGTOKEN и TGCHATID на 6 строке меняем на токен бота и на ID чата, куда будут отправляться дампы.

После можно добавить скрипт в crontab через команду crontab -e и вставив туда * * * * * PATH/send_to_tg.sh. (Предварительно поставив флаг +x на файл, чтобы сделать его исполняемым)

@cofob
cofob / 1_log_handler.py
Last active December 3, 2023 04:31
Taskiq async log collection
"""Taskiq log handler."""
import asyncio
from logging import Handler, LogRecord
from sys import stderr
from traceback import print_exc
from typing import Callable
class TaskiqHandler(Handler):
@cofob
cofob / 0_README.md
Last active July 24, 2023 09:06
Taskiq routing support

This code does roughly the same thing as this example, but in a more optimized and flexible way, because:

  1. it does not open channels for each node on both client and server. In the example there were 3 queues and each vorker would open all 3 channels that it never used. This is achieved by separating the brokers into Listener and Sender (Routed).
  2. it supports dynamic sending to the specific node, the code from the example only supported predefined queues.
  3. Added more convenient aliases to remove the duplication of with_broker(broker).with_labels(node=node_name) on each task call.

It also breaks compatibility with taskiq_aio_pika a bit, since it uses a different Exchange type and uses the node name as routing_key.

But despite the pros it doesn't support some taskiq features and is more complex to use. For example worker will not be able to call context.requeue because listener broker has no write channel.

The startup is almost the

__version__ = (1, 0, 1)
#
# █░░ █ ▀█▀ █▀▀
# █▄▄ █ ░█░ ██▄
#
# © Copyright 2023
#
# Licensed under the GNU GPLv3
# https://www.gnu.org/licenses/agpl-3.0.html

Настройка GRE

GRE (Generic Routing Encapsulation) туннели позволяют оборачивать пакеты одной сети внутри пакетов другой сети. Вот пошаговая инструкция по созданию GRE туннеля на Linux Ubuntu между двумя серверами (1.1.1.1 и 2.2.2.2) с использованием внутреннего адреса из подсети 10.100.0.1/24.

Сервер 1.1.1.1

  1. Откройте терминал и введите следующую команду для создания GRE туннеля:

    sudo ip tunnel add gre1 mode gre remote 2.2.2.2 local 1.1.1.1 ttl 255
__version__ = (1, 0, 0)
# meta developer: @cofob
from telethon.tl.types import Message
import logging
from .. import loader, utils # noqa
logger = logging.getLogger(__name__)
__version__ = (2, 0, 0)
import contextlib
# meta developer: @cofob
# meta banner: https://i.imgur.com/H1vPM6U.jpg
from telethon.tl.types import Message
import requests
import logging