Skip to content

Instantly share code, notes, and snippets.

View Shalabyelectronics's full-sized avatar
💭
Start easy, start small, and keep showing up.

Mohamed Shalaby Shalabyelectronics

💭
Start easy, start small, and keep showing up.
View GitHub Profile
@Shalabyelectronics
Shalabyelectronics / Colorama module
Created March 7, 2022 13:14
شرح تغيير ألوان الخط بإستخدام مكتبة colorama
from colorama import init, Fore, Back, Style
#اذا كنت تريد تشغيل الخطوط من ويندوز فعل هذه الدالة
init()
#الألوان الخطوط الموجودة
FORES = [ Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE ]
# ألوان الخلفيات الموجودة
BACKS = [ Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW, Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE ]
# شدة الألوان او الأضاءة
BRIGHTNESS = [ Style.DIM, Style.NORMAL, Style.BRIGHT ]
def oct_to_hex(oct):
# write your code here
oct_list = [int(number) for number in str(oct)]
number_pos = len(oct_list) - 1
decimal_list = []
for number in oct_list:
decimal_number = number
for _ in range(number_pos):
decimal_number *= 8
number_pos -= 1
import re
class EmailChecker:
def __init__(self,email:str):
self.email = email
self.id = None
self.provider= None
self.extention =None
self.is_valid()
def is_valid(self):
import time
def alarm_me(minutes: int, message:str) -> str:
alarm_time = time.time() + minutes * 60
while True:
if time.time() > alarm_time:
break
print(message)
def in_range(number:int, range_from:int, range_to:int) -> bool:
return number in list(range(range_from,range_to+1))
@Shalabyelectronics
Shalabyelectronics / check_type.py
Created November 15, 2022 05:31
Decorator Check datatype example
def check_type(current_type:object):
"""
This Decorator will check the datatype of the
target function to validate the datatype arguments.
"""
def get_func(func):
def wrapper(*args,**kwargs):
check_values = []
bad_values = []
if args:
@Shalabyelectronics
Shalabyelectronics / time_execution.py
Created November 16, 2022 05:31
Decorator Check how long time does function to execute
def calc_execution(func):
def wrapper(*args,**kwargs):
"""
This wrapper will use time module to check
the diffrence between the time when the excution start
and when it's end.
"""
import time
start = time.time()
value = func(*args,**kwargs)
glossary = {
"fruits": ["Apple", "Orange", "Banana"],
"vegetables": ["Cucumber", "Lemon", "Tomato"],
"sweets": ["Mars", "Kitkat", "Galaxy"]
}
# This about invers dictionary values from list to become a keys and their keys became a values that refer to them
def invert_dict(d):
@Shalabyelectronics
Shalabyelectronics / app.js
Created April 25, 2023 21:32
Basic usage for React.memo
import { memo, useState } from 'react';
export default function MyApp() {
const [name, setName] = useState('');
const [address, setAddress] = useState('');
return (
<>
<label>
Name{': '}
<input value={name} onChange={e => setName(e.target.value)} />
@Shalabyelectronics
Shalabyelectronics / app.js
Created April 27, 2023 21:53
Practice React memo, useMemo and useCallback
import React, { useState, memo, useMemo, useCallback } from "react";
function Box({ color, onClick }) {
console.log(`Box color : ${color.color}`);
return (
<div
style={{
margin: 10,
width: 75,
height: 75,