Skip to content

Instantly share code, notes, and snippets.

View AnalyzePlatypus's full-sized avatar

Michoel Samuels AnalyzePlatypus

View GitHub Profile
AnalyzePlatypus /
Last active February 1, 2024 14:29
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)
AnalyzePlatypus /
Last active January 24, 2024 13:38
Helper function for line-wrapping in jsPDF
AnalyzePlatypus /
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:
AnalyzePlatypus /
Last active December 1, 2023 05:45
Vue.js 2.7: Detect clicks outside an element (Close modals, popups, etc.)

Detecting outside clicks in Vue.js

See this StackOverflow thread

First off, include the directive at the end of this gist.

  1. On your open button, make sure to use @click.stop to prevent the open click event from closing your modal.
  2. On your modal, add the v-click-outside directive and points it at a function to call when clicked outside.


View Root Categories

These are the 35 root categories on

Retrieved via Keepa API on April 12, 2021.

API call:<REDACTED>&domain=1&category=0&parents=1
AnalyzePlatypus /
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

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})$/;
AnalyzePlatypus / jsPDF_convert_points_to_other_units.js
Last active May 15, 2022 06:47
jsPDF helper function: Convert points to other units
View jsPDF_convert_points_to_other_units.js
function convertPointsToUnit(points, unit) {
// Unit table from
var multiplier;
switch(unit) {
case 'pt': multiplier = 1; break;
case 'mm': multiplier = 72 / 25.4; break;
case 'cm': multiplier = 72 / 2.54; break;
case 'in': multiplier = 72; break;
case 'px': multiplier = 96 / 72; break;
case 'pc': multiplier = 12; break;

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


View Using (and debugging) Pre-signed S3

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:

Vue.js: Use without increasing initial bundle size

There's no questions about it: in the age of "fat" frontend clients, less bloat is better. A useful technique is to split off large libraries into separate Webpack chunks so the they don't take up space in your main bundle, delaying the initial load of your webapp. I like doing this with what I call the "installer pattern". Every split-out library gets its own "installer", an async function that loads the Webpack chunk, performs any initializations or configuration necessary, and then informs the relevant parts of your app that loading has completed.

Here's what that pattern looks like for installing the error reporting SDK:

First, add Sentry to your project: