This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const vhost = require('vhost'); | |
// after registering all middleware, then you register your hostname as | |
app.use(vhost('admin.localhost',app)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var asteriskRegExp = /\*/g | |
var asteriskReplace = '([^\.]+)' | |
var endAnchoredRegExp = /(?:^|[^\\])(?:\\\\)*\$$/ | |
var escapeRegExp = /([.+?^=!:${}()|\[\]\/\\])/g | |
var escapeReplace = '\\$1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isregexp(val) { | |
return Object.prototype.toString.call(val) === '[object RegExp]' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vhostof(req, regexp) { | |
var host = req.headers.host | |
var hostname = hostnameof(req) | |
if (!hostname) { | |
return | |
} | |
var match = regexp.exec(hostname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hostnameof(req) { | |
var host = req.headers.host | |
if (!host) { | |
return | |
} | |
var offset = host[0] === '[' | |
? host.indexOf(']') + 1 | |
: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hostregexp(val) { | |
var source = !isregexp(val) | |
? String(val).replace(escapeRegExp, escapeReplace).replace(asteriskRegExp, asteriskReplace) | |
: val.source | |
// force leading anchor matching | |
if (source[0] !== '^') { | |
source = '^' + source | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a vhost middleware. | |
* | |
* @param {string|RegExp} hostname | |
* @param {function} handle | |
* @return {Function} | |
* @public | |
*/ | |
function vhost(hostname, handle) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dayRegex = /^(([0-2]?[1-9])|([3][0-1]))$/; //01-31 | |
let monthRegex = /^(([0]?[1-9])|([1][0-2]))$/; //01-12 | |
let emailRegex = /^\S*?@\S*?\.[a-z]{2,3}^/; | |
let lessThanTen = /^[0]?[1-9]?$/ // 1-9, 01-09 | |
let percentRegex = /^([1-9][0-9]?)$|(^100$)/ // 1-100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isLeapYear(year){ | |
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); | |
} | |
function calendar(inputDate){ | |
const presentDate = inputDate ? (new Date(inputDate)) : (new Date()); | |
console.log("date is ", presentDate) | |
if(Boolean(presentDate) === false){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = []; | |
for(let i = 0; i < 100000; i++){ | |
numbers.push(Math.round(Math.random()*100000)) | |
} | |
function hashDuplicate(value){ | |
console.time("hash duplicate") | |
let hashValues = {} | |
for(let i = 0; i < numbers.length; i++){ |
OlderNewer