Skip to content

Instantly share code, notes, and snippets.

View evankirkiles's full-sized avatar

evan evankirkiles

View GitHub Profile
@evankirkiles
evankirkiles / config.h
Created November 1, 2022 22:56
/main/include/config.h for CS334 Espressif IDE tutorial
#ifndef __CONFIG_H__
#define __CONFIG_H__
// GPIO pins for our buttons
#define CONFIG_PIN_BUTTON_1 32
#define CONFIG_PIN_BUTTON_2 33
#endif /* __CONFIG_H__ */
@evankirkiles
evankirkiles / server.ts
Created October 4, 2022 06:21
ESP32 Websocket Server
import express from "express";
import { Server } from "ws";
import type { WebSocket } from "ws";
import short from "short-uuid";
const PORT = process.env.PORT || 3000;
const INDEX = "/index.html";
// websocket object to keep track of all clients
const sockets: { [key: string]: WebSocket } = {};
@evankirkiles
evankirkiles / cascadeDeletion.ts
Created March 7, 2022 15:06
MEDIUM: Run Cascade Deletion in REST API from client
import { Auth, API } from "aws-amplify";
// ...
const id = "<some-clothe-id>";
const myInit = {
headers: {
Authorization: `Bearer ${(await Auth.currentSession())
.getIdToken()
.getJwtToken()}`,
@evankirkiles
evankirkiles / clothe.js
Last active March 7, 2022 14:41
MEDIUM: AWS Amplify Cascading Deletion Clothe
const GraphQLClient = require("/opt/graphQLClient.js");
const Q = require("/opt/graphql/queries.js");
const M = require("/opt/graphql/mutations.js");
/* -------------------------------------------------------------------------- */
/* EXPORTS */
/* -------------------------------------------------------------------------- */
/**
* Deletes a clothe, its clothe images, and any corresponding outfit components.
@evankirkiles
evankirkiles / queries.js
Created March 7, 2022 14:29
MEDIUM: AWS Amplify Cascading Deletion Queries + Mutations
// /opt/graphql/queries.js
const listClotheImages = /* GraphQL */ `
query listClotheImages(
$filter: ModelClotheImageFilterInput
$nextToken: String
) {
listClotheImages(filter: $filter, nextToken: $nextToken) {
items {
id
@evankirkiles
evankirkiles / app.js
Created March 7, 2022 14:22
MEDIUM: AWS Amplify Lambda Function Cascading Delete Serverless Express Route
const Clothe = require("./clothe.js");
\\ ...
app.delete("/clothe/:clotheId", function (req, res) {
if (!req.headers["authorization"]) {
res.json({ success: false, error: "Not authenticated!" });
} else if (!req.params.clotheId) {
res.json({ success: false, error: "No clothe ID parameter!" });
} else {
@evankirkiles
evankirkiles / schema.graphql
Created March 7, 2022 14:03
AWS Amplify: Sample Wardrobe Schema for Cascade Deletion
type Outfit
@model
@auth(rules: [{ allow: owner }]) {
components: [OutfitComponent!] @hasMany
}
type OutfitComponent
@model
@auth(rules: [{ allow: owner }]) {
clotheImage: ClotheImage! @belongsTo
@evankirkiles
evankirkiles / graphQLClient.js
Last active March 7, 2022 13:20
AWS Amplify: GraphQL Client Lambda Layer
const AWS = require("aws-sdk");
const https = require("https");
const UrlParse = require("url").URL;
const gql = require("graphql-tag");
const graphql = require("graphql");
const { print } = graphql;
/*
* Waits using an exponential
* backoff algorithm.
@evankirkiles
evankirkiles / override.ts
Created March 7, 2022 06:09
Cognito User Pool Auth for AWS Amplify Function CFN Override
// This file is used to override the REST API resources configuration
import { AmplifyApiRestResourceStackTemplate } from "@aws-amplify/cli-extensibility-helper";
export function override(resources: AmplifyApiRestResourceStackTemplate) {
// Add our user pool id as a parameter so we can create authorizers with it
// Note that you have to replace <your auth name here> with the name of your auth!
// It's the name of the folder in amplify/backend/auth that was created when you
// added the auth to the project (NOT userPoolGroups). Also make sure you keep
// the preceding "auth" part of the string before the auth name, it's necessary.
resources.addCfnParameter(