Skip to content

Instantly share code, notes, and snippets.

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

André Marcondes Teixeira andremarcondesteixeira

🏠
Working from home
  • André Marcondes Teixeira
  • Curitiba, Paraná, Brazil
View GitHub Profile
:root {
--space-unit: 1rem;
--space-xxs: calc(0.25 * var(--space-unit));
--space-xs: calc(0.5 * var(--space-unit));
--space-sm: calc(0.75 * var(--space-unit));
--space-md: calc(1.25 * var(--space-unit));
--space-lg: calc(2 * var(--space-unit));
--space-xl: calc(3.25 * var(--space-unit));
--space-xxl: calc(5.25 * var(--space-unit));
}
export function calculateIpv4Subnet(ipAddress, subnetMask) {
// helper functions
const numbersArrayFromString = v => v.split('.').map(v => parseInt(v));
const numberBinaryAsString = v => (v >>> 0).toString(2).padStart(8, '0');
const addressBinaryAsString = v => numbersArrayFromString(v).map(numberBinaryAsString).join('');
const addressAsNumber = v => parseInt(addressBinaryAsString(v), 2);
const addressStringFromNumber = v => [24, 16, 8, 0].map(shift => (v >>> shift) & 255).join('.');
ipAddressNumber = addressAsNumber(ipAddress);
subnetMaskNumber = addressAsNumber(subnetMask);
@andremarcondesteixeira
andremarcondesteixeira / ipv4-validation-regex
Last active December 17, 2019 18:57
IPV4 validation regex
^(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)){3}$