Skip to content

Instantly share code, notes, and snippets.

View brianfoody's full-sized avatar
🙃
Play

Brian brianfoody

🙃
Play
View GitHub Profile
type Prediction = {
status: "starting" | "processing" | "succeeded" | "failed" | "canceled";
id: string;
output: string;
};
const captionAnImage = async () => {
const body = JSON.stringify({
version: "2e1dddc8621f72155f24cf2e0adbde548458d3cab9f00c0139eea840d0ac4746",
input: {
const payload = {
model: "gpt-4",
messages: [
{
content: `Tell me the days of the week.`,
role: "user",
} as ChatGptMessage,
],
temperature: 0.8,
top_p: 1,
@brianfoody
brianfoody / .zshrc
Created February 15, 2023 03:04
gitc
# gitc "Fix - The dropdown in the bubble menu should forget its state"
gitc () {
msg=${1:-'Quick commit'}
git add . && git commit -m "$msg" && git push origin "$(git branch | sed -n "/\* /s///p")"
}
@brianfoody
brianfoody / gist:04dc7855fb03b19fb53a5f8ca1cee430
Last active October 28, 2022 12:21
Aurora v2 Lambda Invoke
-- Docs: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/PostgreSQL-Lambda.html
-- Add the lambda extension
CREATE EXTENSION IF NOT EXISTS aws_lambda CASCADE;
-- Add a trigger to a table
create trigger item_insert_trigger after
insert
on
public.item for each row execute function item_insert_entry();
@brianfoody
brianfoody / gist:2c62cecc912dbd97bc759eba427e84cf
Created October 28, 2022 07:14
Example GPT-3 cost calculator
# Prompt AWS Pricing for IOT Core Example
Pricing example for a workload using all AWS IoT Core components
You have 100,000 devices that maintain a constant connection to AWS IoT Core for 30 days in the Europe (Ireland) region. Each day, each device sends 325 messages of 1 KB in size. Of the 325 messages sent per device each day, 100 trigger a Device Shadow update and 200 trigger a rule that executes one action. Your charges would be calculated as follows:
Connectivity Charges
Minutes of connection = 100,000 connections * 60 minutes/hour * 24 hours/day * 30 days = 4,320,000,000 minutes of connection
Connectivity charges = 4,320,000,000 minutes of connection * $0.08/1,000,000 minutes of connection = $345.60
Messaging Charges
Messages = 100,000 devices * 325 messages/device-day * 30 days = 975,000,000 messages
@brianfoody
brianfoody / TlDrawScrollBox
Last active October 4, 2022 07:28
tldrraw scrollable HTML element
src/shapes/scrollbox
// Shape
import type { TLShape } from '@tldraw/core'
export interface ScrollBoxShape extends TLShape {
type: 'scrollbox'
size: number[]
}
@brianfoody
brianfoody / crafter.ts
Created April 19, 2022 05:17
IAM Least Access Crafter
import * as AWS from "aws-sdk";
import { retry } from "ts-retry-promise";
import { v4 } from "uuid";
import { makeApiGatewayScanner } from "./adapters/makeApiGatewayScanner";
const iam = new AWS.IAM();
var sts = new AWS.STS();
export const getAccountId = async (): Promise<string | undefined> => {
const identity = await sts.getCallerIdentity().promise();
@brianfoody
brianfoody / aws.ts
Last active April 5, 2022 11:50
Easy AWS SSO Stuff
const { createAWSClient } = require("easy-aws-utils");
const exec = async () => {
const { aws, access, s3Helper } = await createAWSClient();
// The access details you have configured
console.log(JSON.stringify(access, null, 2));
// The organisations in the left bar
const ssoUrls = access.organisations.map((o) => o.ssoStartUrl);
@brianfoody
brianfoody / cleanup.ts
Last active April 4, 2022 03:32
How to do a StepFunction cleanup post deploy
const taskWaitThreeHours = new sfn.Wait(this, "Wait 3 hours for tasks to have executed.", {
time: sfn.WaitTime.duration(cdk.Duration.hours(3))
});
const deprovisionLambda = new nodeLambda.NodejsFunction(this, "deprovisionFn", {
runtime: lambda.Runtime.NODEJS_14_X,
entry: "workflow/deprovision.ts",
handler: "main",
timeout: cdk.Duration.seconds(30),
logRetention: logs.RetentionDays.ONE_MONTH,
@brianfoody
brianfoody / monorepo.mjs
Created January 5, 2022 18:15
Clone an environment
await Promise.all([$`sleep 1; echo 1`, $`sleep 2; echo 2`, $`sleep 3; echo 3`]);