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 net = require('net'); | |
const getOpenPort = async (port, maxPort) => { | |
const isPortAvail = (currentPort) => new Promise((resolve, reject) => { | |
const tester = net.createServer() | |
.once('error', (err) => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err))) | |
.once('listening', () => tester.once('close', () => resolve(true)).close()) | |
.listen(currentPort); | |
}); | |
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 React, { createContext, useState } from 'react'; | |
import PropTypes from 'prop-types'; | |
const mq = 'screen and (max-width: 671px)'; | |
const ResponsiveContext = createContext(); | |
const ResponsiveContextProvider = ({ children }) => { | |
const [isMobile, setIsMobile] = useState(window.matchMedia(mq).matches); | |
matchMedia(mq).addEventListener('change', e => setIsMobile(e.matches)); |
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
/* eslint no-console: 0 */ | |
/* eslint no-unused-vars: 0 */ | |
const https = require('https'); | |
const goodUrl = 'https://jsonplaceholder.typicode.com/users/1'; | |
const badUrl = 'https://jsonplaceholder.typicode.com/foo'; | |
const badDomain = 'https://no.such.url'; | |
const externalCall = (url, t = 0) => new Promise((resolve, reject) => { | |
setTimeout(() => { |
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 isTruthy = (expression) => { | |
if (typeOf expression === 'number') return true // 0 returns true | |
if (Array.isArray(expression) && expression.length < 1) return false // empty array returns false | |
if typeOf expression === 'Object' && Object.keys(expression).length < 1) return false // empty object returns false | |
return !!expression | |
} |
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
<script> | |
const els = document.querySelectorAll('li') | |
const iterables = new Map([ | |
['myObject', { | |
appetizer: 'Soup', | |
entree: 'Mahi Mahi', | |
dessert: 'Pie!' | |
}], | |
['myArray', [ |
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
export const trimAnything = (str, trimChar, opts = { start: false, end: true }) => { | |
if (str.length > 1 || opts.allowEmpty) { | |
let pattern; | |
if (opts.start && !opts.end) { | |
pattern = `^\\${trimChar}+`; | |
} else if (!opts.start && opts.end) { | |
pattern = `\\${trimChar}+$`; | |
} else { | |
pattern = `^\\${trimChar}+|\\${trimChar}+$`; | |
} |
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
//*********server.js********* | |
const express = require('express') | |
const path = require('path') | |
const app = express() | |
const port = process.env.PORT || 3000 |
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
{ | |
"parserOptions": { | |
"ecmaVersion": 2017, | |
"sourceType": "module", | |
"ecmaFeatures": { | |
"experimentalObjectRestSpread": true | |
} | |
}, | |
"rules": { | |
"func-names": [ |
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
// Element.matches() | |
if (!Element.prototype.matches) | |
Element.prototype.matches = | |
Element.prototype.msMatchesSelector || | |
Element.prototype.webkitMatchesSelector | |
// NodeList.forEach() | |
if (window.NodeList && !NodeList.prototype.forEach) { | |
NodeList.prototype.forEach = function (callback, thisArg) { |
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 isMobile = () =>{ | |
return ( navigator.userAgent.match(/Android/i) || | |
navigator.userAgent.match(/BlackBerry/i) || | |
navigator.userAgent.match(/iPhone/i) || | |
navigator.userAgent.match(/iPad/i) || | |
navigator.userAgent.match(/iPod/i) || | |
navigator.userAgent.match(/iPhone|iPad|iPod/i) || | |
navigator.userAgent.match(/IEMobile/i) ) | |
} |
NewerOlder