Skip to content

Instantly share code, notes, and snippets.

View josefaidt's full-sized avatar
🦉

josef josefaidt

🦉
View GitHub Profile
@josefaidt
josefaidt / create-store.ts
Created February 21, 2024 01:43
quick and simple store example
function createStore<T = unknown>(initial?: T) {
type Subscriber = (state: T) => void
let previous: T
let current: T
let _subscriber: Subscriber
if (initial) current = initial
const update = (state: T) => {
previous = current
@josefaidt
josefaidt / parse-url-encoded-form-event.ts
Created April 3, 2024 15:17
Parse a URL encoded form event in AWS Lambda
import type { APIGatewayProxyEventV2 } from "aws-lambda"
import busboy from "busboy"
// https://github.com/francismeynard/lambda-multipart-parser/blob/master/index.js
async function parseUrlEncodedFormEvent<T>(
event: APIGatewayProxyEventV2,
): Promise<T> {
return new Promise((resolve, reject) => {
const fields: Record<string, unknown> = {}
const bb = busboy({ headers: event.headers })
@josefaidt
josefaidt / use-user-profile.tsx
Last active April 10, 2024 21:53
useUserProfile hook for Amplify auth
import type { PropsWithChildren } from "react"
import { useState, createContext, useEffect, useContext } from "react"
import { useAuthenticator } from "@aws-amplify/ui-react"
import { fetchUserAttributes } from "aws-amplify/auth"
type UserProfile = {
/**
* the sub
*/
id: string
@josefaidt
josefaidt / init.lua
Last active August 8, 2024 16:49
lua scripts to fold InlineFilters in aws amplify docs
vim.api.nvim_set_keymap('n', '<SPACE>', '<NOP>', { noremap = true })
vim.g.mapleader = " "
if vim.g.vscode then
require("vscode_amplify_docs_fold_filters_commands")
-- VSCode extension
local vscode = require('vscode-neovim')
-- set vscode as default notifier
vim.notify = vscode.notify
-- amplify docs filters
@josefaidt
josefaidt / demo-dsql-drizzle.ts
Created March 4, 2025 16:55
scrappy demo script for using drizzle to interact with Amazon Aurora DSQL
import { DsqlSigner } from "@aws-sdk/dsql-signer"
import { drizzle } from "drizzle-orm/node-postgres"
import pg from "pg"
const { Client } = pg
const id = "<your-database-id>" as const
const endpoint = `${id}.dsql.us-east-1.on.aws` as const
const region = "us-east-1" as const