Skip to content

Instantly share code, notes, and snippets.

View ArrayIterator's full-sized avatar

ArrayIterator ArrayIterator

View GitHub Profile
@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)) {
@ArrayIterator
ArrayIterator / PasswordHash.php
Last active April 6, 2024 23:25
Password Hashing Library with OpenWall PasswordHash Compat
<?php
declare(strict_types=1);
namespace ArrayIterator\Hashing;
use Exception;
use function chr;
use function crypt;
use function max;
use function min;
// stpd! chatgpt 3.5 generated
// phpDateConverter.js
/**
* Converts PHP date format to JavaScript date format.
* @param {string} phpFormat - PHP date format string.
* @returns {string} - JavaScript date format string.
*/
function convertPhpToJsDateFormat(phpFormat) {
// Mapping of PHP date format characters to JavaScript equivalents
@ArrayIterator
ArrayIterator / as-numbers.php
Last active October 31, 2023 20:54
array list of tld domain + supported sub domains, ipv4, ipv6, as-number include whois server
<?php
declare(strict_types=1);
// auto generated at : 2023-10-28T05:03:52+07:00
return [
'0-0' => [
'range' => [
0,
0,
],