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 csv | |
| import os | |
| from typing import List, Union | |
| def write_csv(file_full: Union[str, os.PathLike], data: List[any]): | |
| """Writes a row of data to a CSV file. | |
| Args: | |
| file_full: The full path to the CSV 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
| import toml | |
| from typing import Union, Any, Dict | |
| def load_file(toml_filename: str) -> Union[Dict[str, Any], None]: | |
| """Loads a TOML file and returns its parsed data as a dictionary. | |
| Args: | |
| toml_filename: The path to the TOML 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
| pylint --generate-rcfile > .pylintrc |
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 tempfile | |
| with tempfile.TemporaryDirectory() as tmpdirname: | |
| with open('some_file.txt', mode='w') as f: | |
| f.write('Hi, and goodbye.') | |
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
| # HK, 01.01.21 | |
| import argparse | |
| import os | |
| from pathlib import Path | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--dir_path', type=str, help='directory which file permissions will be changed') | |
| parser.add_argument('--ref_path', type=str, help='directory of which file permissions will be taken as reference') | |
| flags = parser.parse_args() | |
| dir_path = Path(flags.dir_path) |
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 at_most_n(X, n): | |
| """ | |
| Yields at most n elements from iterable X. If n is None, iterates until the end of iterator. | |
| """ | |
| yield from itertools.islice(iter(X), n) |
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 sys | |
| print(sys.executable) | |
| print(sys.version) | |
| print(sys.version_info) |
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Description: | |
| Author: PhatLuu | |
| Created on: 2020/06/14 | |
| """ | |
| #%% | |
| # ================================IMPORT PACKAGES==================================== |
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
| ####################################################################################################################### | |
| re_is_url = re.compile( | |
| r'^(?:http|ftp)s?://' # http:// or https:// | |
| r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... | |
| r'localhost|' # localhost... | |
| r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip | |
| r'(?::\d+)?' # optional port | |
| r'(?:/?|[/?]\S+)$', re.IGNORECASE) | |
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
| """Tools for converting data for creating PySpark DataFrames""" | |
| import json | |
| import logging | |
| from datetime import datetime, timedelta, timezone | |
| from decimal import Decimal | |
| from pathlib import Path | |
| from random import randint | |
| from typing import Any, Callable, Dict, List, Literal, Tuple, Union |