Skip to content

Instantly share code, notes, and snippets.

View hrahimi270's full-sized avatar
🏠
Working from home

Hossein Rahimi hrahimi270

🏠
Working from home
View GitHub Profile
@hrahimi270
hrahimi270 / percentage-in-view.js
Created January 20, 2022 19:21 — forked from rijkvanzanten/percentage-in-view.js
Get how much percentage an element is in view in plain JavaScript
function getViewPercentage(element) {
const viewport = {
top: window.pageYOffset,
bottom: window.pageYOffset + window.innerHeight
};
const elementBoundingRect = element.getBoundingClientRect();
const elementPos = {
top: elementBoundingRect.y + window.pageYOffset,
bottom: elementBoundingRect.y + elementBoundingRect.height + window.pageYOffset
@hrahimi270
hrahimi270 / eventemitter.js
Created April 10, 2020 16:09 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@hrahimi270
hrahimi270 / validateCard.js
Created January 25, 2020 14:01 — forked from mahmoud-eskandari/validateCard.js
اعتبار سنجی کارت عابر بانک ایران در جاوا اسکریپت \ Validation function of Iranian bank cards in Javascript \ تابع تشخیص صحت کارت عابربانک
"use strict";
// By Mahmoud Eskandari @ MIT license
function validateCard(card) {
if (typeof card === 'undefined'
|| card === null
|| card.length !== 16) {
return false;
}
let cardTotal = 0;
for (let i = 0; i < 16; i += 1) {