Skip to content

Instantly share code, notes, and snippets.

Avatar
🐏
Bah.

Michoel Samuels AnalyzePlatypus

🐏
Bah.
  • Jerusalem, Israel
View GitHub Profile
@AnalyzePlatypus
AnalyzePlatypus / example-lambda-deploy.md
Last active May 12, 2021
Deploy a Node.js Lambda function using the AWS CLI
View example-lambda-deploy.md

.env file

LAMBDA_FUNCTION_NAME=MyFunction
AWS_UPLOAD_CODE_PROFILE=MY_CLI_PROFILE
SLACK_DEV_NOTIFICATIONS_WEBHOOK_URL=https://hooks.slack.com/services/****/****/****

deploy.sh file

# Read the .env file
View AmazonReferralFees.md

Amazon.com Referral Fees

Amazon's referral fees, in JSON format.

Does not contain "Categories Requiring Approval"

Last updated April 19, 2021

View CompressionTest.md

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');
View amazon_root_categories.md

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 Jul 26, 2020
Build an Env Var file for your service workers
View swBuildEnvVarFile.js
/*
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)
View AWS Lambda - Upload `node_modules` without `devDependencies`.md

AWS Lambda - Upload node_modules without devDependencies

By default, ZIPing the project directory will included all of your devDependencies. slowing your upload speed to a crawl as you upload an enormous bundle containing 80% useless code (unless you're testing in production™ )

You only need your production dependencies when deploying, but need you devDependencies for development. But you have to deploy from the same directory, and it must be named node_modules. How can slim down the ol' deploy bundle?

Here's a horrible but effective hack that accomplishes this:

  1. We'll create an additional directory called node_modules__prod for storing production dependencies.
  2. When we deploy we swap the names of the dev and production node_modules directories 😱, so the deploy tool stupidly uploads what it thinks is our full node_modules but actually is our production-only modules directory.
  3. When deploy is done (or fails) we swap the directory names again, restoring us back to developme
View obtaining-gmail-auth-tokens.md

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
View aws-sam-env-vars.md

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 
View lambda-build-and-upload.md

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
@AnalyzePlatypus
AnalyzePlatypus / using-sheets-api.md
Last active Mar 17, 2021
Node.js - Accessing a spreadsheet using the Google Sheets API
View using-sheets-api.md

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)