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 itertools import count | |
import re | |
import os | |
import sys | |
import_1 = 'from django.utils.translation import ugettext.*' | |
regex_text_1 = r' _\(.*' | |
regex_text_2 = r'[^_](_\()[^()]*\)' | |
front_remove = r' _\(' | |
last_remove = r'\)' |
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 functools import reduce | |
from operator import getitem | |
def get_from_dict(d, selectors): | |
""" | |
Retrieves the value of the nested key indicated by the given selector list from a dictionary or list. | |
- Use functools.reduce() to iterate over the selectors 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
""" | |
KEONN - Very simple HTTP server in python for logging requests | |
Usage:: | |
./server.py [<port>] | |
python3.9 httpServer.py 8000 | |
""" | |
import sys | |
if str(sys.version)[0] == '3': | |
from http.server import BaseHTTPRequestHandler, HTTPServer |
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 re | |
def slugify(s): | |
s = s.lower().strip() | |
s = re.sub(r'[^\w\s-]', '', s) | |
s = re.sub(r'[\s_-]+', '-', s) | |
s = re.sub(r'^-+|-+$', '', s) | |
return s |
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 re import sub | |
def kebab(s): | |
return '-'.join( | |
sub(r"(\s|_|-)+"," ", | |
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+", | |
lambda mo: ' ' + mo.group(0).lower(), s)).split()) | |
# Examples: |
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 json | |
import os | |
class JsonFileHandler: | |
"""Given the name of the json file location, data can be extracted or added. | |
If the location does not exists it will be created. | |
""" | |
def __init__(self, file_name: str) -> None: |
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 os | |
class FileParser: | |
"""A class to parse for files or directories in a given directory path""" | |
def __init__(self, folder_path) -> None: | |
self.folder_path: str = folder_path | |
self.all_file_list: list = [] | |
self.all_dirs_list: 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
{ | |
"AC": "+247-####", | |
"AD": "+376-###-###", | |
"AE": "+971-5#-###-####", | |
"AE": "+971-#-###-####", | |
"AF": "+93-##-###-####", | |
"AG": "+1(268)###-####", | |
"AI": "+1(264)###-####", | |
"AL": "+355(###)###-###", | |
"AM": "+374-##-###-###", |
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 random | |
FIRST_NAMES = ('James', 'John', 'Robert', 'Michael', 'William', 'David', | |
'Richard', 'Charles', 'Joseph', 'Thomas', 'Christopher', 'Daniel', 'Paul', | |
'Mark', 'Donald', 'George', 'Kenneth', 'Steven', 'Edward', 'Brian', | |
'Ronald', 'Anthony', 'Kevin', 'Jason', 'Matthew', 'Gary', 'Timothy', | |
'Jose', 'Larry', 'Jeffrey', 'Frank', 'Scott', 'Eric', 'Stephen', 'Andrew', | |
'Raymond', 'Gregory', 'Joshua', 'Jerry', 'Dennis', 'Walter', 'Patrick', | |
'Peter', 'Harold', 'Douglas', 'Henry', 'Carl', 'Arthur', 'Ryan', 'Roger', | |
'Joe', 'Juan', 'Jack', 'Albert', 'Jonathan', 'Justin', 'Terry', 'Gerald', |