Skip to content

Instantly share code, notes, and snippets.

@AnalyzePlatypus
AnalyzePlatypus / lambda-gmail-compose.md
Created May 13, 2020 08:11
Use serverless function to send low-volume emails without 3rd party mail services.

Sending email with serverless functions

You can deploy this function on any of the serverless platforms - AWS Lambda, Google Cloud Functions, Azure Functions, Netlify, Cloudflare Workers, etc.

  1. Create a new function and paste in the following code.
  2. You will need to add nodemailer to your package.json (npm i nodemailer), and follow your platform's instructions on bundling dependencies.
  3. Obtain Gmail API credentials for your account. You will need clientID, clientSecret, and refreshToken. Follow this YouTube tutorial
  4. Expose these credentials as the follwing environment variables:
GMAIL_EMAIL_ADDRESS
"source ~/.vimrc
" Find more examples here: https://jb.gg/share-ideavimrc
let mapleader=" "
" Don't use Ex mode, use Q for formatting.
map Q gq
set number relativenumber
set scrolloff=5
@AnalyzePlatypus
AnalyzePlatypus / using-sheets-api.md
Last active April 27, 2024 05:35
Node.js - Accessing a spreadsheet using the Google Sheets API

Using the Sheets API

To access the Sheets API, you will need to enable the Sheets API, obtain credentials, and grant access to your Sheet.

Based on these instructions

1. Enabling the Sheets API

  1. Open the Google Developers Console
  2. Select your project or create a new one (and then select it)

AWS Lambda: Upload code from Command Line

Last update: June 2020

AWS is notorious for it's incredibly complicated security model. This guide will walk you through setting up a fully-featured build & upload script for your Lambda functions.

You will need:

  • An AWS account

AWS Lambda SAM cli: Using local env vars

To use local env vars, you must follow the following steps:

  1. Declare all env vars in your template.yml, like so:
Resources:
  MyFunction:
 Type: AWS::Serverless::Function 

Compression Test

A quick script for testing how well a JSON file compresses

// Imports

const fs = require('fs');
const { promisify } = require('util');
const { deflate } = require('zlib');

Amazon.com Root Categories

These are the 35 root categories on Amazon.com.

Retrieved via Keepa API on April 12, 2021.

API call:

https://api.keepa.com/category?key=<REDACTED>&domain=1&category=0&parents=1
@AnalyzePlatypus
AnalyzePlatypus / swBuildEnvVarFile.js
Created July 26, 2020 14:02
Build an Env Var file for your service workers
/*
By default, service workers cannot access our Vue environment variables.
To allow this, this script collects the variables we want at build time
and places them in a JS file that the service worker can access.
To prevent the leak of sensitive credentials (the SW file is public),
only whitelisted environment variables are built into this file.
Deploy this file alongside your service worker, and import th efile in your service worker (`importScripts('swenv.js');` in Workbox)

Obtaining Gmail OAuth tokens

To access your Gmail account from the API, you will need to obtain the following values from Google's OAuth system:

clientId clientSecret refreshToken

Part 1: Client secrets

  1. Open console.google.com

Amazon.com Referral Fees

Amazon's referral fees, in JSON format.

Does not contain "Categories Requiring Approval"

Last updated April 19, 2021