Skip to content

Instantly share code, notes, and snippets.

View mohammadwali's full-sized avatar

Mohammad Wali mohammadwali

View GitHub Profile
@mohammadwali
mohammadwali / validateSubdomain.js
Last active June 15, 2018 13:55
Validate a subdomain with JavaScript, inspired from https://gist.github.com/stuartbain/7212385
const MIN_LENGTH = 5;
const MAX_LENGTH = 63;
const ALPHA_NUMERIC_REGEX = /^[a-z][a-z\-]*[a-z0-9]*$/;
const START_END_HYPHEN_REGEX = /\A[^-].*[^-]\z/i;
const reservedNames = ['www', 'ftp', 'mail', 'pop', 'smtp', 'admin', 'ssl', 'sftp'];
const validateSubdomain = subdomain => {
//if is reserved...
if (reservedNames.includes(subdomain))
throw new Error('cannot be a reserved name');
@mohammadwali
mohammadwali / dynamic-favicon.js
Created September 27, 2015 22:35
Change Browsers Favicon Dinamically using JavaScript (Credits: http://softwareas.com/dynamic-favicons/)
var favicon = {
change: function(iconURL) {
if (arguments.length == 2) {
document.title = optionalDocTitle
}
this.addLink(iconURL, "icon")
this.addLink(iconURL, "shortcut icon")
// Google Chrome HACK - whenever an IFrame changes location
// (even to about:blank), it updates the favicon for some reason