Skip to content

Instantly share code, notes, and snippets.

View Jaballadares's full-sized avatar

John Balladares Jaballadares

View GitHub Profile
const request = require('request');
exports.main = async (event, callback) => {
/* BE SURE TO ADD THE CONTACT ID INTO THE 'PROPERTY TO INCLUDE IN CODE' SECTION OF THE CUSTOM CODED ACTION */
const contact_id = event.inputFields['hs_object_id'];
/* LOOK UP THE CONTACT VIA THE ID AND RETRIEVE THE PROPERTY 'hs_additional_emails' */
var options = {
"method": "GET",
"url": "https://api.hubapi.com/crm/v3/objects/contacts/" + contact_id + "?hapikey=" + process.env.HAPIKEY + "&properties=hs_additional_emails"
@Jaballadares
Jaballadares / outbound-email-with-cloudflare.md
Created December 29, 2023 18:12 — forked from irazasyed/outbound-email-with-cloudflare.md
Using Gmail SMTP with Cloudflare Email Routing: A Step-by-Step Guide

Using Gmail SMTP with Cloudflare Email Routing: Step-by-Step Guide

Learn how to send emails through Gmail SMTP with Cloudflare Email Routing in this comprehensive guide.

Step 1: Enable 2-Factor Authentication

To proceed with this method, ensure that you have enabled two-factor authentication for your Google account. If you haven't done so already, you can follow the link to set it up → Enable 2FA in your Google account.

Step 2: Create an App Password for Mail

/*
Autosend Invites to anyone that shares X number of connections with you.
Way to use this script:
1. Save it as a bookmarklet
2. Go to 'People you may know'
3. Click on this bookmarklet.
4. Enter number of overlapping connections
5. Check your console
@Jaballadares
Jaballadares / oneliners.js
Created September 21, 2021 23:36 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
@Jaballadares
Jaballadares / README.org
Created July 22, 2021 20:02 — forked from jcouyang/README.org
Promise All with Limit of Concurrent N

The Promise All Problem

in case of processing a very large array e.g. Promise.all(A_VERY_LARGE_ARRAY_OF_XHR_PROMISE)

which would probably blow you browser memory by trying to send all requests at the same time

solution is limit the concurrent of requests, and wrap promise in thunk

Promise.allConcurrent(2)([()=>fetch('BLAH1'), ()=>fetch('BLAH2'),...()=>fetch('BLAHN')])

@Jaballadares
Jaballadares / THINK.md
Last active June 26, 2021 05:26
Personal Reminders for Writing Clean Code

Things to Remember When Trying to write Clean JavaScript

Prefer Multiple Paramaters Over Single Object Paramaters

Why?

It's easier to read!

// Good
@Jaballadares
Jaballadares / createRequire.js
Last active June 25, 2021 17:23
createRequire.js
import { createRequire } from "module";
const require = createRequire(import.meta.url);
// usage
const creds = require('./config/creds.json');
@Jaballadares
Jaballadares / url_to_drive.js
Created June 24, 2021 18:59 — forked from denilsonsa/url_to_drive.js
Google Apps Script to upload a file from an URL directly to Google Drive.
// url_to_drive.gs
// Google Apps Script
// Allows uploading a URL directly to Google Drive.
//
// Live link:
// https://script.google.com/macros/s/AKfycbzvhbHS4hnWPVBDHjQzZHA0qWq0GR-6hY7TbYsNto6hZ0MeAFZt/exec
//
// Source-code:
// https://gist.github.com/denilsonsa/8134679
// https://script.google.com/d/1Ye-OEn1bDPcmeKSe4gb0YSK83RPMc4sZJt79SRt-GRY653gm2qVUptoE/edit
@Jaballadares
Jaballadares / export-to-csv.gs
Created June 24, 2021 18:59 — forked from mderazon/export-to-csv.gs
Google apps script to export to individual csv files all sheets in an open spreadsheet
/*
* script to export data in all sheets in the current spreadsheet as individual csv files
* files will be named according to the name of the sheet
* author: Michael Derazon
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var csvMenuEntries = [{name: "export as csv files", functionName: "saveAsCSV"}];
ss.addMenu("csv", csvMenuEntries);
@Jaballadares
Jaballadares / reduceExamples.js
Created June 17, 2021 15:41 — forked from quangnd/reduceExamples.js
Some examples about reduce() in Javascript
//Example 1 - Calculate average value of an array (transform array into a single number)
var scores = [89, 76, 47, 95]
var initialValue = 0
var reducer = function (accumulator, item) {
return accumulator + item
}
var total = scores.reduce(reducer, initialValue)
var average = total / scores.length
/*Explain about function