This file contains hidden or 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
alphabet = "".join(chr(ord("a") + i) for i in range(26)) | |
def derive_key(sentence: str) -> str: | |
key = "" | |
sentence = sentence.lower() | |
for letter in sentence + "".join(alphabet): | |
if letter not in key: | |
key += letter | |
return key |
This file contains hidden or 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 xor_hash(input_bytes: bytes) -> bytes: | |
hash_length = 16 # in bytes | |
# Get the first 16 bytes | |
if len(input_bytes) < hash_length: | |
return input_bytes + b"\0" * (hash_length - len(input_bytes)) | |
hash_value = input_bytes[:hash_length] | |
# iterate over blocks of the defined length | |
remaining = input_bytes[hash_length:] |
This file contains hidden or 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 hashlib | |
import itertools | |
import time | |
from typing import Tuple | |
def find_hash(start: str = "00") -> Tuple[str, int]: | |
nb_probed = 0 | |
for probe in generate_random_str(): | |
nb_probed += 1 |
This file contains hidden or 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 hashlib | |
from collections import defaultdict | |
from pathlib import Path | |
from typing import List | |
def find_duplicates(directory: Path) -> List[List[Path]]: | |
fingerprint2paths = defaultdict(list) | |
for path in directory.glob("**/*"): | |
if not path.is_file(): |
This file contains hidden or 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 typing import Literal, List | |
from dataclasses import dataclass | |
from enum import Enum | |
class EnumRoles(Enum): | |
REGISTERED = "Registered" | |
MODERATOR = "Moderator" | |
ADMIN = "ADMIN" |
This file contains hidden or 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 typing import Literal, List | |
from pydantic import BaseModel, Field | |
class User(BaseModel): | |
name: str | |
roles: List[Literal["Registered", "Moderator", "Admin"]] = Field( | |
default_factory=list | |
) |
This file contains hidden or 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
mysql: | |
host: localhost | |
user: root | |
password: something | |
preprocessing_queue: # Line comments are available! | |
- name: preprocessing.scale_and_center | |
width: 32 | |
height: 32 | |
- preprocessing.dot_reduction | |
use_anonymous: true |
This file contains hidden or 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 resource | |
import contextlib | |
@contextlib.contextmanager | |
def limit(resource_type, limit): | |
"""Temporarily limit a resource.""" | |
soft_limit, hard_limit = resource.getrlimit(resource_type) | |
resource.setrlimit(resource_type, (limit, hard_limit)) # set soft limit | |
try: |
This file contains hidden or 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 lxml import etree | |
xml = """ | |
<!DOCTYPE XML [ | |
<!ENTITY ee SYSTEM "file:///etc/passwd" > | |
]> | |
<root>ⅇ</root> | |
""" | |
parser = etree.XMLParser() | |
doc = etree.fromstring(xml.encode(), parser) |
This file contains hidden or 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 lxml import etree | |
xml = """<root>Hello World!</root>""" | |
parser = etree.XMLParser() | |
doc = etree.fromstring(xml.encode(), parser) | |
parsed_xml = etree.tostring(doc).decode("utf8") | |
print(parsed_xml) |