Skip to content

Instantly share code, notes, and snippets.

View engmagdy87's full-sized avatar
:octocat:

Mohamed Magdy engmagdy87

:octocat:
  • Vodafone Intelligent Solutions (_VOIS)
  • Cairo, Egypt
View GitHub Profile
@engmagdy87
engmagdy87 / gist:1088a6fd382a534e8931d15d4c780979
Created June 21, 2022 01:43 — forked from homaily/gist:8672499
Regex to validate saudi mobile numbers

السلام عليكم ، هذا كود ريجيكس بسيط للتحقق من صحة أرقام الجوالات السعودية ، يقوم الريجيكس بالتحقق من مفتاح الدولة ، مفتاح شركة الإتصالات لضمان صحة النص المدخل .

Hello, this is a simple regex to validate saudi mobile numbers, the code will validate country code, telecome company code and make sure the tested sting is correct .

/^(009665|9665|\+9665|05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$/

Regex Breakdown - شرح الكود

@engmagdy87
engmagdy87 / mongodb_cheat_sheet.md
Created December 22, 2021 09:37 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

Useful methods to process tables in Cucumber step definitions When you accept a table in your Cucumber step definition, that table object will have:

table.raw : Turn the table into an array of arrays

table.hashes : Convert the table to an array of hashes, where the keys are the table headers from the first row

table.rows

const validateEmailAndPhoneNumber = function (value) {
const emailRegEx = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._\+-])*([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
const mobileRegEx = /^\d{11}$/;
return emailRegEx.test(value) || mobileRegEx.test(value);
};
const TruncateText = (text) => {
return `${text.slice(0, 200)}...`
}
export default TruncateText
import { HEADER_HEIGHT, HEADER_HEIGHT_MOBILE } from "../constants/Header"
import isDeviceSmart from "../helpers/DetectIsDeviceSmart"
const whatIsTheSectionAppearInViewport = () => {
let fromTop = document.getElementById("app").scrollTop;
const ids = document.getElementsByClassName("wrapper");
let offsetFromTop = isDeviceSmart() ? HEADER_HEIGHT_MOBILE : HEADER_HEIGHT
let currentActiveItem = ""
for (let i = 0; i < ids.length; i++) {
const id = ids[i].id;
const isDeviceSmart = () => {
const phone = window.matchMedia('(max-width:575px)');
const landscapePhone = window.matchMedia(
'(min-width:576px) and (max-width: 767px)'
);
const tablet = window.matchMedia(
'(min-width:768px) and (max-width: 991px)'
);
return phone.matches || landscapePhone.matches || tablet.matches
@engmagdy87
engmagdy87 / CountryCodes.json
Created July 29, 2020 03:49 — forked from anubhavshrimal/CountryCodes.json
Country and Dial or Phone codes in JSON format
[
{
"name": "Afghanistan",
"dial_code": "+93",
"code": "AF"
},
{
"name": "Aland Islands",
"dial_code": "+358",
"code": "AX"
@engmagdy87
engmagdy87 / clean_code.md
Created February 8, 2020 20:40 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

function saveToFile(jsonData, filename) {
let blob = new Blob([JSON.stringify(jsonData)], { type: 'text/plain;charset=utf-8;' })
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename)
} else {
let link = document.createElement('a')
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
let url = URL.createObjectURL(blob)
link.setAttribute('href', url)