ngrok http https://localhost:8080 -bind-tls=true -host-header="localhost:8080"
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
/*! | |
* Add items to an object at a specific path | |
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com | |
* @param {Object} obj The object | |
* @param {String|Array} path The path to assign the value to | |
* @param {*} val The value to assign | |
*/ | |
Object.stringSet = (obj, path, val) => { | |
/** |
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
// This function can be used on frontend. For better performance use the "for" version | |
Object.byString = function(object, string) { | |
string = string.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties | |
string = string.replace(/^\./, ''); // strip a leading dot | |
const array = string.split('.'); | |
array.forEach((key) => { | |
if (key in object) object = object[key]; | |
}); | |
return object; |
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
/** | |
* Get all documents of collection | |
* @param db {Object} - MongoDB connection | |
* @param collectionName {String} - Collection name | |
* @returns {Promise<Array>} | |
*/ | |
async function getDocs(db, collectionName) { | |
const collection = db.collection(collectionName); | |
const cursor = await collection.find(); | |
return cursor.toArray(); |
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 toDots(object, array = []) { | |
const deepValue = (obj, path) => path.replace(/\[|\]\.?/g, '.').split('.').filter(s => s).reduce((acc, val) => acc && acc[val], obj); | |
function parseToDots(obj, key) { | |
const value = deepValue(obj, key); | |
array.push(key); // Add if you want add only certains fields | |
if (typeof value === 'object') Object.keys(value).forEach(key2 => parseToDots(obj, `${key}.${key2}`)); | |
} | |
Object.keys(object).forEach(key => parseToDots(object, key)); |
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
/** | |
* Get FQDN from a string | |
* @name FQDN | |
* @param URL {String} - String you want get FQDN | |
* @return {String} | |
**/ | |
function FQDN(URL = '') { | |
URL = URL.subtring(0, 50); // This will avoid evaluate long malicious fqdn | |
const regex = /[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+/i; | |
const filtered = regex.exec(URL); |
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
/** | |
* Search number of times a character/string exist in DOM element | |
* | |
* @name countCharacter | |
* @param DOMElement {String|Object} - DOM element you want count characters inside | |
* @param character {String} - String you want count | |
* @param caseSensitive {Boolean} - Option to set sensitive to uppercase or lowercase | |
* @return {Number} - Total of times character match in DOM element | |
**/ | |
function countCharacter(DOMElement = 'body', character = '', caseSensitive = 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
upstream app_server { | |
ip_hash; | |
server app_react:3000 max_fails=3 fail_timeout=30s; | |
} | |
upstream api_server { | |
ip_hash; | |
server api_feathers:3040 max_fails=3 fail_timeout=30s; | |
} |
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 = require('node-fetch'); | |
/** | |
* Responds to any HTTP request. | |
* | |
* @param {!express:Request} req HTTP request context. | |
* @param {!express:Response} res HTTP response context. | |
*/ | |
exports.hubspot = async (req, res) => { | |
res.set('Access-Control-Allow-Origin', '*'); | |
if (req.method === 'OPTIONS') { |
To solve the problem when execute npm install
and get node-gyp error access permission:
EACCES current user ("$user") does not have permission to access the dev dir "/root/.cache/node-gyp/12.16.1"
Execute the follow commands:
sudo npm -g install node-gyp --unsafe-perm