Skip to content

Instantly share code, notes, and snippets.

View tirinox's full-sized avatar
🎯
Focusing

TRX1 tirinox

🎯
Focusing
View GitHub Profile
@tirinox
tirinox / my_tee.py
Created August 2, 2019 08:54
My implementation of itertools.tee function
from itertools import tee
def source():
for i in range(5):
print(f'next is {i}')
yield i
@tirinox
tirinox / commit-ago.py
Created December 26, 2019 12:53
This script allows you to commit in the past!
#!/usr/local/bin/python3
from datetime import datetime, timedelta
import sys
import os
def git_commit_ago(days, message):
date = datetime.now() - timedelta(days=days)
# метакласс наследуется от Type
class Final(type):
def __new__(mcls, name, bases, attrs):
"""
:param name: Имя нового класса
:param bases: Список его базовых классов
:param attrs: Набор атрибутов класса
:return: новый класс
"""
for base in bases:
@tirinox
tirinox / bf.py
Last active April 2, 2020 16:24
Python brainfuck interpreter
import sys
def run(code, mem_size=256):
# 1. этап составим карту скобок
# ключ и значения - индекс байта в коде
# по любой скобке находим ей пару
bracket_map = {}
stack = []
for pos, symbol in enumerate(code):
@tirinox
tirinox / class-as-decorator.py
Created October 21, 2019 08:52
Класс в роли декоратора. Для канала PyWay.
# copyright https://t.me/pyway
from functools import wraps
class Repeater:
def __init__(self, n):
self.n = n
def __call__(self, f):
@wraps(f)
def wrapper(*args, **kwargs):
for _ in range(self.n):
@tirinox
tirinox / corona.csv
Last active April 15, 2020 18:13
Предсказание числа заболевших коронавирусом из Китая
day infected dead
20.01.2020 278 4
21.01.2020 326 6
22.01.2020 547 8
23.01.2020 639 14
24.01.2020 916 25
25.01.2020 2000 40
26.01.2020 2700 57
27.01.2020 4400 64
28.01.2020 5970 87
@tirinox
tirinox / mandel_animation.py
Created April 29, 2020 11:47
Dive into Mandelbrot fractal (GIF, Python)
from PIL import Image
from tqdm import tqdm
import math
W, H = 200, 200 # размеры картинки
ITER = 255
FRAMES = 100
# это пример показывает применение __matmul__ и __imatmul__ для пользовательских классов
class MyMatrix:
def __init__(self, data):
self.data = data
# для получения элементов матрицы как A[строка, столбец]
def __getitem__(self, pos):
i, j = pos
return self.data[i][j]
@tirinox
tirinox / MaxFeeTxHandler.java
Created October 24, 2020 17:03
This is a solution of week 1 for the Bitcoin and Cryptocurrency Technologies course (scrooge coin)
/**
* This is a solution of week 1 for the Bitcoin and Cryptocurrency Technologies course (scrooge coin)
* https://www.coursera.org/learn/cryptocurrency
* Please, try yourself before looking this code
* I was able to get 100/100 score!
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@classmethod
def register(cls, cfg: Config, db: DB, dp: Dispatcher, loc_man: LocalizationManager, **kwargs):
members = cls.__dict__.items()
for name, f in members:
if not hasattr(f, 'handler_stuff'):
continue
handler_stuff = f.handler_stuff
@dp.message_handler(*handler_stuff['custom_filters'],
commands=handler_stuff['commands'],