This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DotNotation(dict): | |
""" | |
Access dictionary attributes via dot notation | |
""" | |
__getattr__ = dict.get | |
__setattr__ = dict.__setitem__ | |
__delattr__ = dict.__delitem__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from random import randrange | |
from time import sleep | |
def retry(retry_limit=3, delay=None, max_random_delay=600): | |
""" | |
Retrying decorator with simple backoff logic. | |
:param retry_limit: amount of retries before throwing exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
def mine_field(size, mines_amount): | |
""" | |
в Revolut оч. любят давать эту задачу (на питоне) на собеседованиях: | |
Create func/class to print matrix size X/X | |
Fill it with Y mines (mark is as 'x') in random way (remember game minesweeper from windows?) | |
mark empty as 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_multiple_from_query(emails: List[str]) -> str: | |
# IMAP query composition: (OR (OR (FROM a@a.ru) (FROM b@b.ru)) (FROM c@c.ru)) | |
def gather(a: str, b: str) -> str: | |
if 'FROM' not in a: | |
return f'OR (FROM "{a}") (FROM "{b}")' | |
else: | |
return f'OR ({a}) (FROM "{b}")' | |
return f'({reduce(gather, emails)})' if len(emails) > 1 else f'FROM {emails[0]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import random | |
async def fetching(q): | |
while True: | |
print("i'm fetching...") | |
d = random.random() | |
print("done fetching, got", d) | |
await q.put(d) | |
await asyncio.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
from queue import Queue | |
from threading import Thread | |
# create a consumer | |
def consumer(input_queue): | |
while True: | |
# retrieve data from queue (blocking) | |
data = input_queue.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton(type): | |
_instances = {} | |
def __call__(cls, *args, **kwargs): | |
if cls not in cls._instances: | |
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
return cls._instances[cls] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @authHeader NVARCHAR(64); | |
DECLARE @contentType NVARCHAR(64); | |
DECLARE @postData NVARCHAR(2000); | |
DECLARE @responseText NVARCHAR(2000); | |
DECLARE @responseXML NVARCHAR(2000); | |
DECLARE @ret INT; | |
DECLARE @status NVARCHAR(32); | |
DECLARE @statusText NVARCHAR(32); | |
DECLARE @token INT; | |
DECLARE @url NVARCHAR(256); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | | |
Where-Object { $_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID") } | | |
Select-Object -ExpandProperty PSChildName |
NewerOlder