This file contains hidden or 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
import * as path from "path" | |
import * as fs from "fs" | |
// find all files that match the corresponding splitted directory component | |
// find all files and folders that match the regular expression of the corresponding path | |
// filter out all unmatched files/folders from the list based on splitted path | |
function getIgnoredFiles(ignorePath: string) :string[]{ | |
const allFiles = walk(process.cwd(), [], {}) | |
const regex = buildRegex(ignorePath) |
This file contains hidden or 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
class TimeStampDB{ | |
constructor (){ | |
this.db = {} | |
} | |
set(key, timestamp, value){ | |
this.db[key] = this.db[key] || {} | |
this.db[key][timestamp] = value | |
this.db[key]['timestamps'] = this.db[key]['timestamps'] || [] | |
// find insert position for sorted set of timestamps array |
This file contains hidden or 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 pluralize = function (value){ | |
return Math.floor(value) > 1 ? 's' : ''; | |
} | |
function ago(date){ | |
const now = Math.floor(Date.now()/1000) | |
const time = new Date(date) | |
if(isNaN(time.getTime())){ | |
throw new Error(`Passed in date ${date} is not a valid date`) | |
} |
This file contains hidden or 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 timeNow = new Date(); | |
let currentHour = timeNow.getHours(); | |
let count = 1; | |
let idk = null | |
function greet(){ | |
if (count == 10){ | |
clearInterval(idk); | |
} | |
if ((5 <= currentHour) && (currentHour <= 10)){ |
This file contains hidden or 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++){ |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
NewerOlder