Skip to content

Instantly share code, notes, and snippets.

View ArrayIterator's full-sized avatar

ArrayIterator ArrayIterator

View GitHub Profile
@ArrayIterator
ArrayIterator / Adsense.tsx
Last active February 24, 2025 03:26
Google Adsense Implementation for non GPT (Google Publisher Tag)
import React, {createRef, useEffect, useState} from 'react';
import {CSSProperties, ReactNode} from 'react';
import AdsenseJS from './AdsenseJS';
declare var window: Window&{
adsbygoogle: any[],
};
const IS_SSR = typeof window !== 'object' || !window || typeof window.document !== 'object';
export function Adsense(props: {
@ArrayIterator
ArrayIterator / OATH.js
Last active December 27, 2024 16:47
OATH - HOTP (HMAC-based One-time Password Algorithm) - TOTP (Time-based One-time Password Algorithm)
/**
* OATH - HOTP (HMAC-based One-time Password Algorithm)
*
* @author ArrayIterator
* @link https://tools.ietf.org/html/rfc4226
* @link https://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm
*/
class HOTP {
/**
@ArrayIterator
ArrayIterator / sha1.js
Created December 24, 2024 21:57
Javascript Implementation sha1 & hash_hmac<sha1>
/**
* SHA1
* Implementation of SHA1 algorithm as described in RFC 3174
* @see https://www.ietf.org/rfc/rfc3174.txt
*
* @param {string} string input to be hashed
* @param {boolean} [raw=false] If the optional binary is set to true, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.
* @return {string|false} Calculated the sha1 hash of a string, returning false if fail
*/
const sha1 = (string, raw = false) => {
@ArrayIterator
ArrayIterator / SemanticVersion.php
Created October 19, 2024 01:29
The semantic version parser
<?php
declare(strict_types=1);
class SemanticVersion implements JsonSerializable
{
/**
* Regex pattern for semantic versioning
* eg:
* 1.2.3
* v1.2.3
@ArrayIterator
ArrayIterator / base64_encode.js
Created August 24, 2024 13:56
Fix base64 encode (btoa incompatibility)
/**
* Fix base64 encode for javascript
*/
const base64_encode = (param) => {
const convert_binary_str = (str) => {
if (str.length < 1) {
return '';
}
let ord = str[0].charCodeAt(0);
if (ord < 0) {
@ArrayIterator
ArrayIterator / Ip.ts
Created August 17, 2024 09:10
IP Calculator (inet_pton/ntop) and CIR Ranges
export default class Ip {
/**
* IPv4 regex
*/
public static readonly IPv4_REGEX = /^(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$/;
/**
* IPv6 regex
* ::1 is also valid IPv6 address
*/
public static readonly IPv6_REGEX = /^([0-9a-fA-F]{0,4}:){1,7}([0-9a-fA-F]{1,4})$/;
@ArrayIterator
ArrayIterator / ip_helper.cjs
Last active August 17, 2024 09:11
IP Helper For Validate IP4 & IP6 - (ip_helper.mjs - for module) & (ip_helper.cjs - for common js) https://gist.github.com/ArrayIterator/e54e83513875e6eb2ffc1e1b3566d7eb
/*!
* IP Helper
*
* @author ArrayIterator<[email protected]>
*/
const IPv4_REGEX = /^(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\.(?:[0-1]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])$/;
// ::1 is also valid IPv6 address
const IPv6_REGEX = /^([0-9a-fA-F]{0,4}:){1,7}([0-9a-fA-F]{1,4})$/;
/**
* Simple Password Strength Checker
* ~ Password Score based on the following rules:
* PasswordScore(password: string, username: string|null): number
* ~ Generate Password based on the following rules:
* GeneratePassword(length: number = 12): string
* ~ Password Strength Level:
* PASSWORD_WEAK: 0
* PASSWORD_MEDIUM: 1
* PASSWORD_STRONG: 2
@ArrayIterator
ArrayIterator / Crypto.js
Last active August 15, 2024 06:12
Easier to use Web Crypto - Crypto.js
const Algorithms = {
AES: {
description: 'Advanced Encryption Standard',
ivLength: 16,
decryptionSupported: true,
keySupported: true,
publicKeySupported: false,
signatureSupported: false,
default: 'AES-128-CBC',
algorithms: {
@ArrayIterator
ArrayIterator / helper.js
Last active May 12, 2024 05:33
Helper for React.js (just like some php functions) to easier manage code - https://github.com/ArrayIterator/arrayiterator-js-helper
const createTrimRegexP = (e, position ='both') => {
const charArray = {};
strval(e).split('').forEach((e) => {
if (in_array(e, ['-', '/'])) {
e = '\\' + e;
}
charArray[e] = e;
});
let regex = `[${values(charArray).join('')}]`;
switch (lower_trim(position)) {