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
// via https://github.com/suchipi/without-comments/blob/main/index.js | |
function trimComments(content, commentToken = "#") { | |
const startRegex = new RegExp(`^${commentToken}`); | |
const endRegex = new RegExp(`${commentToken}.*$`, "g"); | |
return content | |
.split("\n") | |
.map((line) => { | |
// remove comment lines | |
if (startRegex.test(line.trim())) return ""; |
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
// https://github.com/RajikaKeminda/multi-search/blob/main/index.js | |
// https://multi-search.vercel.app/ | |
// https://codesandbox.io/s/upbeat-goldberg-mzvzqz?from-embed=&file=/src/App.js | |
function singleKeyFilter(list, query, key) { | |
let querySanitizer = String(query).trim().toLowerCase(); | |
return list.filter( | |
(i) => String(i[key]).toLowerCase().indexOf(querySanitizer) > -1 | |
); | |
} |
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
<html> | |
<head> | |
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
<script type="text/javascript"> | |
const DEFAULT_ACTIVITY_TIME_IN_DAYS = 14 | |
google.charts.load('current', { 'packages': ['gantt'] }) | |
google.charts.setOnLoadCallback(drawChart); | |
function daysToMilliseconds(days) { |
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 path = require('path') | |
const getCacheInfo = require('whats-in-the-cache') | |
const NETLIFY_CACHE_DIR = '/opt/build/cache' | |
const MY_BUILD_DIR = path.resolve('build') | |
const CACHE_MANIFEST_PATH = path.join(MY_BUILD_DIR, 'cache-output.json') | |
getCacheInfo({ | |
cacheDirectory: NETLIFY_CACHE_DIR, | |
outputPath: CACHE_MANIFEST_PATH, |
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
// https://github.com/substack/parse-messy-time/blob/master/index.js | |
var months = [ | |
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', | |
'September', 'October', 'November', 'December' | |
]; | |
var days = [ | |
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' | |
]; |
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
// https://github.com/fastify/fastify/blob/224dc104260ad26f9baa0e46962f917963d41fe5/fastify.js#L711 | |
// https://twitter.com/matteocollina/status/1493198259212406784 | |
/** | |
* These export configurations enable JS and TS developers | |
* to consumer fastify in whatever way best suits their needs. | |
* Some examples of supported import syntax includes: | |
* - `const fastify = require('fastify')` | |
* - `const { fastify } = require('fastify')` | |
* - `import * as Fastify from 'fastify'` | |
* - `import { fastify, TSC_definition } from 'fastify'` |
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 fetch = async (...args) => { | |
console.log(...args) | |
return { | |
statusCode: 200, | |
data: {}, | |
} | |
} | |
function httpRequest(url, method, data, opts, cb) { | |
const init = { method } |
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
// Via https://twitter.com/RReverser/status/1490873967577640961 | |
function wwwProxy() { | |
return new Proxy(new URL('https://www/'), { | |
get: function get(target, prop) { | |
let orig = Reflect.get(target, prop); | |
if (typeof orig === 'function') return orig.bind(target); | |
if (typeof prop !== 'string') return orig; | |
if (prop === 'then') return Promise.prototype.then.bind(fetch(target)); | |
target = new URL(target); | |
target.hostname += `.${prop}`; |
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
// via https://blog.sessionstack.com/how-javascript-works-proxy-and-reflect-11748452c695 | |
const p = new Proxy(function() {}, { | |
apply: function(target, thisArg, argumentsList) { | |
console.log('called: ' + argumentsList.join(', ')); | |
return argumentsList[0] + argumentsList[1] + argumentsList[2]; | |
} | |
}); | |
console.log(p(1, 2, 3)); // This will print called: 1, 2, 3 and 6 |
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
// https://betterprogramming.pub/everything-you-should-know-about-javascript-proxy-67576f2e069e | |
function setPrivateField(obj, prefix = "_"){ | |
return new Proxy(obj, { | |
has: (obj, prop) => { | |
if(typeof prop === "string" && prop.startsWith(prefix)){ | |
return false | |
} | |
return prop in obj | |
}, | |
ownKeys: obj => { |