Skip to content

Instantly share code, notes, and snippets.

View DBoyara's full-sized avatar
🏠
Working from home

DBoyara

🏠
Working from home
View GitHub Profile
@DBoyara
DBoyara / aiohttp_to_curl.py
Created September 3, 2024 05:04
generate curl command from aiohttp
async def generate_curl_command(method, url, **kwargs):
curl_cmd = f"curl -X {method.upper()} '{url}'"
headers = kwargs.get('headers')
if headers:
for k, v in headers.items():
curl_cmd += f" -H '{k}: {v}'"
params = kwargs.get('params')
if params:
@DBoyara
DBoyara / true_adx_as_in_QUIK.py
Last active February 20, 2024 11:35
True ADX indicator like in QUIK
import numpy as np
def adx(high, low, close, window=14):
"""Функция для вычисления Average Directional Index (ADX)
Аргументы:
high: Список или массив значений High цен
low: Список или массив значений Low цен
close: Список или массив значений Close цен
window: Период для вычисления ADX (по умолчанию 14)
@DBoyara
DBoyara / simple_console_alarm.py
Created July 4, 2022 15:00
Simple console alarm with schedule and tkinter
import tkinter as tk
import time
from argparse import ArgumentParser
from logging import getLogger
from tkinter import messagebox
import schedule
logger = getLogger(__name__)
@DBoyara
DBoyara / mp4_to_mp3.py
Created September 19, 2021 11:50
Python mp4 to mp3 with moviepy
import os
from moviepy.editor import VideoFileClip
def main():
video = VideoFileClip(os.path.join("path_to", "movie.mp4"))
video.audio.write_audiofile(os.path.join("path_to", "audio.mp3"))
if __name__ == '__main__':
@DBoyara
DBoyara / async_decorator.py
Created September 8, 2021 14:46
Python Simple Async-Decorator
from functools import wraps
def dec(fn):
@wraps(fn)
async def wrapper(*args, **kwargs):
print(fn.__name__, args, kwargs)
await asyncio.sleep(5)
await fn(*args, **kwargs)
return wrapper
@DBoyara
DBoyara / async_gen.py
Created July 5, 2021 05:33
Async generator
import asyncio
async def ticker(delay, to):
for i in range(to):
yield i
await asyncio.sleep(delay)
async def run():
async for i in ticker(1, 10):
@DBoyara
DBoyara / conftest.py
Last active March 29, 2021 13:53
practice pytest
import pytest
import sqlalchemy
@pytest.fixture
def engine():
return sqlalchemy.create_engine('sqlite://')
@pytest.fixture
def engine_with_table_users(engine):
@DBoyara
DBoyara / mass-change-file-name.py
Last active February 25, 2021 09:28
Changing the names of files and directories in the specified directory
import os
def main(my_path: str, replace_name: str):
for dirpath, dirnames, filenames in os.walk(my_path):
for dirname in dirnames:
dir_old_name = os.path.join(dirpath, dirname)
if dir_old_name.find(replace_name) != -1: