Skip to content

Instantly share code, notes, and snippets.

@Foxonn
Foxonn / scratch_2.py
Last active March 8, 2025 17:18
Расчета вклада с капитализацией процента
def calculate_deposit(
month: int,
iterations: int,
start: int,
interest_deposit: float,
) -> None:
"""
Расчет вклада с капитализацией процента. Пополнение вклада происходит после первой итерации
:param month: Срок вложения
import typing as t
import datetime as dt
from asyncio import sleep
from functools import wraps
from aiologger import Logger
__all__ = ['exception_backoff']
@Foxonn
Foxonn / lru_cache_manager.py
Last active June 28, 2023 12:06
Кэш управляемый единым классом
import time
import typing as t
from _functools import _lru_cache_wrapper
from functools import lru_cache
class LruCacheStorage(t.Dict[str, _lru_cache_wrapper]):
pass
from shelve import DbfilenameShelf
from typing import Any
from typing import Type
from typing import TypeVar
T = TypeVar('T')
__all__ = ['ObjectsLocalStorage']
class ObjectsLocalStorage(DbfilenameShelf):
@Foxonn
Foxonn / gist:e7fa8d645c662a703b28d984db2d48c4
Last active March 10, 2021 11:39
Prepare linux before psycopg2 install
Прежде чем вы сможете установить psycopg2, вам нужно установить пакет python-dev.
Если вы работаете с Linux (и, возможно, с другими системами, но я не могу сказать по своему опыту), вам нужно быть очень точным в том, какую версию python вы используете при установке пакета dev.
Например, когда я использовал команду:
sudo apt-get install python3-dev
Я все еще сталкивался с той же ошибкой при попытке
pip install psycopg2
@Foxonn
Foxonn / tor_test_429_error.py
Created October 21, 2020 11:04
python tor requests
import requests
import socks
import socket
from fake_useragent import UserAgent
from stem import Signal
from stem.control import Controller
controller = Controller.from_port(port=9051)
@Foxonn
Foxonn / change_ip.py
Created October 7, 2020 06:57 — forked from tarcisio-marinho/change_ip.py
change IP address using tor with Python3
# change IP via tor with python
import requests
from stem import Signal
from stem.control import Controller
import socks, socket
import time
# tuts
# https://www.torproject.org/docs/faq.html.en#torrc
# https://stem.torproject.org/tutorials/the_little_relay_that_could.html

In your models.py put:

from django.db import models

@classmethod
def model_field_exists(cls, field):
    try:
        cls._meta.get_field(field)
 return True
@Foxonn
Foxonn / scratch.py
Last active January 20, 2020 11:40
Python | Build tree from list [(parent, child),]
def to_tree(source):
parents = sorted([pair[1] for pair in source if pair[0] is None])
mod_source = sorted([pair for pair in source if pair[0] is not None])
def compile_branch(parent):
batch = []
for pair in mod_source:
_parent, _child = pair
@Foxonn
Foxonn / scratch.py
Last active January 21, 2020 09:12
Python | My variation binary search
def my_binary_search(_array, item):
n = 0 # iteration
i = 0 # finding index
array = _array[:]
if item > _array[-1] or item < _array[0]:
return None
while len(array) != 1:
n += 1