Skip to content

Instantly share code, notes, and snippets.

@dmost714
dmost714 / App.tsx
Last active April 27, 2023 12:22
I have a SAAS build with AWS Amplify. Unauthenticated users will see the marketing page, which has a 'sign-up/sign-in' button on it. Authenticated users will get the dashboard. Amplify's useAuthenticator hook lets you know if the user is signed in or not. The routing is handled using react-router-v6. Only the / route (index) shows the marketing …
import { Authenticator, View, Image, Text, Heading, useTheme, useAuthenticator } from '@aws-amplify/ui-react'
import { BrowserRouter } from "react-router-dom"
import { Routes, Route } from "react-router-dom"
import AppRoutes from "./AppRoutes"
import MarketingPage from './routes/MarketingPage'
import logoSvg from './logo.svg'
function App() {
const { route, user, signOut } = useAuthenticator(context => [context.route, context.user, context.isPending])
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Create pending order",
"States": {
"Create pending order": {
"Type": "Pass",
"Next": "Select Payment Method"
},
"Select Payment Method": {
"Type": "Choice",
@alanbsmith
alanbsmith / sign.js
Last active August 5, 2021 09:17
A JS function for adding a signature to an HTML canvas element
function sign(name, fontSize = 96) {
// assumes the id of the canvas element is 'canvas'
const canvas = document.getElementById('canvas')
const ctx = canvas.getContext('2d');
ctx.font = `italic ${fontSize}px Snell Roundhand`;
const signatureWidth = ctx.measureText(name).width;
const x = canvas.width/2 - signatureWidth/2;
const y = canvas.height/2 + fontSize/2;
ctx.fillStyle = ctx.strokeStyle;
ctx.fillText(name, x, y);
@dabit3
dabit3 / SingleTableAppSync.md
Last active February 24, 2023 20:05
GraphQL Single Table Design with DynamoDB and AWS AppSync

GraphQL

GraphQL Schema

type Customer {
  id: ID!
  email: String!
}
// source: https://jennamolby.com/how-to-use-cookies-to-capture-url-parameters/
(function(){
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
https://jennamolby.com/how-to-use-cookies-to-capture-url-parameters/
let YOUR_DOMAIN = "YOUR_DOMAIN.TLD" // ex: scrapingbee.com
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
@benkehoe
benkehoe / aws-profile-for-bashrc.sh
Last active April 2, 2024 10:41
AWS_PROFILE env var management
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
@vdelacou
vdelacou / README.md
Last active January 30, 2024 23:54
Create Multi Tenant AWS Amplify For B2B

npm install -g @aws-amplify/cli

npm init private

amplify init

? Enter a name for the project tenant
? Enter a name for the environment develop
? Choose your default editor: Visual Studio Code
#!/bin/bash
branchname=${1:-$(git rev-parse --abbrev-ref HEAD)}
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: "jq" is not installed.' >&2
exit 1
fi
if [ ! $SECRET_GH_TOKEN ]; then
import { useEffect } from "react"
import { confirm } from "../modals"
const hrefBlank = element => {
const href = element.getAttribute("href")
return !href || href === "#"
}
function useBeforeLeave({
message = "",