Skip to content

Instantly share code, notes, and snippets.

View entirelymagic's full-sized avatar
🌈
There is no end to education.

Munteanu Elvis entirelymagic

🌈
There is no end to education.
View GitHub Profile
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'\)'
@entirelymagic
entirelymagic / get_from_dict_using_selectors.py
Created February 23, 2022 14:45
Get from a dictionary the value using selectors
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.
@entirelymagic
entirelymagic / SimpleHttpServer.py
Created January 18, 2022 10:42
Very simple HTTP server in python for logging requests
"""
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
@entirelymagic
entirelymagic / slugify.py
Created December 7, 2021 09:35
Converts a string to a URL-friendly slug.
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
@entirelymagic
entirelymagic / text_to_kebab.py
Last active December 7, 2021 09:32
text-to-kebab
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:
@entirelymagic
entirelymagic / json_file_handler.py
Last active October 22, 2021 19:49
JsonFileHandler/Serializer/Deserializer
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:
@entirelymagic
entirelymagic / file_parser.py
Created October 16, 2021 08:30
A class that takes a folder path and return a list or dictionary with all specific files required
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 = []
@entirelymagic
entirelymagic / phoneMasks.json
Created March 30, 2021 10:18 — forked from mikemunsie/phoneMasks.json
Phone Masks by Country Code JSON
{
"AC": "+247-####",
"AD": "+376-###-###",
"AE": "+971-5#-###-####",
"AE": "+971-#-###-####",
"AF": "+93-##-###-####",
"AG": "+1(268)###-####",
"AI": "+1(264)###-####",
"AL": "+355(###)###-###",
"AM": "+374-##-###-###",
@entirelymagic
entirelymagic / random_american_name.py
Last active March 30, 2021 10:12
Generate a random american name considering the most common names.
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',