Skip to content

Instantly share code, notes, and snippets.

View nukdokplex's full-sized avatar

NukDokPlex nukdokplex

View GitHub Profile
@nukdokplex
nukdokplex / telegram_webapp_validator.py
Created April 4, 2024 18:08
Telegram WebApp init data validator on Python
from hmac import new as hmac_new
from hashlib import sha256
from urllib.parse import unquote
def validate(init_data: str, token: str, c_str="WebAppData") -> None | dict[str, str]:
"""Validates init data from webapp to check if a method was received from Telegram
Args:
init_data (str): init_data string received from webapp
@nukdokplex
nukdokplex / dnsmasq_get_ipsets.py
Created March 17, 2024 18:33
Generates dnsmasq config file that consists of lines like "ipset=/example.com/ipset", bases on text file you providing. Basically adds "ipset=/" + your line + "/" + $ipsetName. Supports comments "#"
import argparse
def main(input_filename: str, output_filename: str, ipset_name: str, is_file_append: bool) -> None:
input_file = open(input_filename, "r", encoding="utf-8")
output_file = open(output_filename, "a" if is_file_append else "w", encoding="utf-8")
while True:
line = input_file.readline()
if not line:
@nukdokplex
nukdokplex / sources.list
Created February 2, 2024 02:38
Debian 12 Bookworm repo list (/etc/apt/sources.list)
deb https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware
deb https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
deb https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
deb https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
@nukdokplex
nukdokplex / kutana-utils.py
Created November 16, 2022 21:08
Utility decorators for ekonda/kutana
import functools
import kutana
from kutana import RequestException
from kutana.update import ReceiverType
async def wrong_receiver(message: kutana.Message, context: kutana.Context, expected: ReceiverType):
if expected == ReceiverType.MULTI:
await context.reply("This command is available only in multi chat.")
@nukdokplex
nukdokplex / 100_hirkn-ipsets.sh
Created October 9, 2022 04:16
Selective routing to WireGuard on Keenetic
#!/bin/sh
# /opt/etc/ndm/fs.d/100_hirkn-ipsets.sh
[ "$1" != "start" ] && exit 0
echo " --- HIRKN ENTRY POINT --- "
RKN_SET_FILE="/opt/root/rkn.lst"
GOOGLE_SET_FILE="/opt/root/google.lst"
CUSTOM_SET_FILE="/opt/root/custom.lst"
# Task 1
def get_spec_digit_count(number, digit):
if digit > len(str(number)):
return 0
if digit < 0:
digit = -digit
return int(str(number)[-digit])
xdvxdvxdv