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
// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]
const valid6 = [4, 5, 3, 9, 6, 8, 9, 8, 8, 7, 7, 0, 5, 7, 9, 8]
// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]
@Shalabyelectronics
Shalabyelectronics / App.js
Created May 2, 2023 23:28
Practicing Lifthing State up with React Js
import React, { useState } from "react";
const Child = ({ resize, resizeParenObj }) => {
const { setResizeParent, resizeBox: resizeParent } = resizeParenObj;
return (
<div
style={{
width: `${resize}px`,
height: `${resize}px`,
margin: 10,
@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,
@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)} />
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 / 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)
@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:
def in_range(number:int, range_from:int, range_to:int) -> bool:
return number in list(range(range_from,range_to+1))
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)
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):