Skip to content

Instantly share code, notes, and snippets.

View AnalyzePlatypus's full-sized avatar
🐏
Bah.

Michoel Samuels AnalyzePlatypus

🐏
Bah.
View GitHub Profile
@AnalyzePlatypus
AnalyzePlatypus / israeli-kosher-numbers.md
Created June 28, 2023 12:28
Detect Israeli Kosher phone numbers with JavaScript

Detect Israeli Kosher Phone Numbers

Based on a code sample provided to me by Avi Marcus.

// Valid as of 2018-10-19
// https://en.wikipedia.org/wiki/Telephone_numbers_in_Israel#Kosher_numbers

const KOSHER_PHONE_MOBILE_REGEX = /^0(5041|5271|5276|5331|5341|5484|5485|5567|5571|5598|5832)\d{5}$/;
const KOSHER_PHONE_FIXED_REGEX = /^0([23489]80\d{5}|7229\d{5}|73724\d{4})$/;

Tailwind Icon Height sizes

These CSS classes will size any square SVG to match the default TailwindCSS font sizes. Great for mixing icons with text on buttons and headings.

The icon sizes were manually picked, so they match my taste. Your mileage may vary! I've also added sizes that are larger than Tailwind's max font size for really big icons in hero sections and the like

Enjoy!

Using (and debugging) Pre-signed S3 URLS

Architecture - A Brief Overview

A Pre-signed URL is used to allow untrusted users to temporary access to private S3 resources. (Example: upload an image to a private S3 bucket).

The URL is a string consists of:

  1. AWS URL of the object to be accessed, and
  2. A signed base64 string describing the HTTP request:
@AnalyzePlatypus
AnalyzePlatypus / example-lambda-deploy.md
Last active May 12, 2021 03:21
Deploy a Node.js Lambda function using the AWS CLI

.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

Amazon.com Referral Fees

Amazon's referral fees, in JSON format.

Does not contain "Categories Requiring Approval"

Last updated April 19, 2021

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)

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

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