Skip to content

Instantly share code, notes, and snippets.

View alpden550's full-sized avatar
🎯
Focusing

Denis Novikov alpden550

🎯
Focusing
View GitHub Profile
@alpden550
alpden550 / sync.py
Last active December 8, 2023 13:20
Sync nested
import hashlib
import shutil
from collections.abc import Iterator
from pathlib import Path
BUF_SIZE = 65536
type H = dict[str, str]
type A = Iterator[tuple[str, str, str | None]]
from string import ascii_letters as letters
def make_caesar(message: str, key: int) -> str:
return message.translate(str.maketrans(letters, letters[key:] + letters[:key]))
@alpden550
alpden550 / generate_random_string.py
Last active June 29, 2021 08:24
Generate random ending for names.
import random
import string
def generate_random_string(length=20, allowed_symbols=None):
allowed_symbols = allowed_symbols or string.ascii_letters + string.digits
return ''.join(random.sample(allowed_symbols, length))
# https://cs50.harvard.edu/x/2020/psets/6/dna/
import csv
import re
import sys
from pathlib import Path
def get_dna(filename):
return Path(filename).read_text()
from . import db
from .exceptions import SaveObjectException
# From Mike Bayer's "Building the app" talk
# https://speakerdeck.com/zzzeek/building-the-app
class BaseMixin:
"""
A mixin that adds a surrogate integer 'primary key' column named ``id``
to any declarative-mapped class and other usefull stuff.
from functools import wraps
import warnings
def deprecated(func):
code = func.__code__
warnings.warn_explicit(
func.__name__ + 'is deprecated',
category=DeprecationWarning,
filename=code.co_filename,
@alpden550
alpden550 / output.py
Created January 21, 2020 16:50
Flat tree
flat = {}
make_tree_flat(tree, flat)
{'a': (None, ['b', 'e']),
'b': ('a', ['c', 'd']),
'c': ('b', []),
'd': ('b', []),
'e': ('a', ['f']),
'f': ('e', ['g']),
'g': ('f', [])}
from functools import reduce
from operator import getitem
def walk(dictionary, keys):
return reduce(lambda d, key: d.get(key) if d else None, keys, dictionary)
def another_walk(dictionary, path):
return reduce(getitem, path, dictionary)
def create_chunks(products, size=7):
for i in range(0, len(products), size):
yield products[i: i + size]