Skip to content

Instantly share code, notes, and snippets.

View clodal's full-sized avatar

clodal clodal

View GitHub Profile
@clodal
clodal / fetchSupabaseSchemaString.ts
Last active November 11, 2023 10:56
Fetch Supabase Postgres Schema String to Pass to OpenAI Assistant for SQL Queries
/** Use this function to get a one-time dump of the database tables and columns to pass to OpenAI to come up with SQL queries.
* @link https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models#executing-sql-queries
*/
const fetchSupabaseSchemaString = async () => {
// make a get request to this route:
const schemaResponse = await fetch(
`${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/?apikey=${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY}`,
)
const schemaResponseData = await schemaResponse.json()
const schemaDefinitions = schemaResponseData.definitions
/* eslint-disable */
function isImport(node, imported) {
return node.type === "ImportDeclaration" && node.source.value === imported;
}
/**
* @usage Replace member imports from @mui/material with direct imports in `src` folder
* $ jscodeshift --extensions=js,jsx,ts,tsx --parser=tsx -t codemods/member-to-direct-import-codemod.js src --module '@mui/material'
* @param fileInfo
@clodal
clodal / upgrade-mui-v4-to-v5.md
Last active January 9, 2022 13:22
Upgrade NextJS + MUI v4 to v5

Upgrade NextJS + MUI v4 to v5

  1. yarn add @mui/material @mui/styles @emotion/react @emotion/styled @emotion/cache @emotion/server @mui/icons-material @mui/lab date-fns @onextech/gvs-kit @onextech/material-ui-landing
  2. In package folder do npx @mui/codemod v5.0.0/preset-safe src
  3. In package.json, remove legacy packages: yarn remove @material-ui/core @material-ui/icons @material-ui/lab @material-ui/pickers
  4. In babel.config.js, ensure that you have this:
plugins: [
	'@mui/material': {
 transform: '@mui/material/${member}',
@clodal
clodal / zshrc.md
Last active September 16, 2021 10:54

My ZSH RC

plugins=(
    git
    zsh-syntax-highlighting
    zsh-autosuggestions
    zsh-z
)
@clodal
clodal / mail-lambda.md
Last active August 23, 2021 06:50
How to setup a new Mail lambda for sending emails

Amplify Email Template Solution (AWS Pinpoint + Mail)

We use Mail to generate email template html body. We need to use a Lambda because Mail is a backend-only package as it relies on ESJ (a kind of server-side templating language). Using Mail on the FE is not possible.

The idea is to fire a request to this lambda to generate the html template and pass it off to AWS Pinpoint to fire the email.

Pre-Requisites

  1. amplify add analytics and amplify push to add Pinpoint
  2. Access Key & Secret Access Key of IAM User with PinPointFullAccess
@clodal
clodal / my-keyboard-speed
Last active February 4, 2021 14:24
MacOS Keyboard Speed
### Set keyboard speed
```
defaults write -g ApplePressAndHoldEnabled -bool false
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write -g InitialKeyRepeat -int 6
```
@clodal
clodal / apple-m1-brew-node
Created January 21, 2021 06:55
M1 Brew Issues with sharp on yarn build with NextJS
# M1 Brew Issues with sharp on yarn build with NextJS
1. Install rosetta2
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
2. Install brew for M1
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
3. Install brew packages like this:
arch -x86_64 brew install <package>
@clodal
clodal / dynamodb-transactions.md
Created December 12, 2020 15:40
Dynamo DB Transactions

Rules of transactions:

  1. You cannot have more than one operation in your transaction for a single item.

  2. You cannot use the results of one operation as an input to another operation in the same transaction.

  3. Aside from the uniqueness of the primary key, there is no enforced dependency (nor enforced non/anti-dependency) between any items in the same table.

  4. There are no dependencies between items in different tables (such as a foreign key requirement) that DynamoDB enforces.

@clodal
clodal / vercel-monorepo.MD
Last active October 12, 2021 14:40
Setting Up Vercel Monorepo

Vercel Monorepo

Why?

  1. Code sharing: xxx-web project can directly access files and variables in xxx-api project vice versa. No need for a private npm module (i.e. @onextech/ens-api) for code sharing.
  2. Integrated: Only 1 git repository to check-in to. No need to split across web and api, etc.

Benefits

  1. Linked dependencies (i.e. node_modules) via Yarn Workspaces
  2. Aliased imports (i.e. @app/web/src/*)
@clodal
clodal / cypress-e2e-setup.MD
Last active October 21, 2020 10:03
E2E Setup with Cypress

E2E Setup with Cypress

Installing Playwright

  1. Ensure that you are using the latest version of Node 10 as playwright requires it: nvm use 10
  2. Install playwright: yarn add -D playwright

Why switch from Playwright to Cypress?

  • Stability over speed in testing
  • QaWolf & Playwright had flaky issues
  • Stability in Cypress test runner over Playwright