Skip to content

Instantly share code, notes, and snippets.

View antstanley's full-sized avatar
🐶
On the internet, nobody knows you're a hooman.

Ant Stanley antstanley

🐶
On the internet, nobody knows you're a hooman.
View GitHub Profile
@antstanley
antstanley / index.js
Created May 31, 2024 14:26
Why use 27 lines when you can use 8
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
console.log((await new BedrockRuntimeClient({ region: 'us-east-1' }).send(new ConverseCommand({
modelId: "anthropic.claude-3-haiku-20240307-v1:0", messages: [{
role: "user",
content: [{ text: "Explain 'rubber duck debugging' in one line." }],
}]
}))).output.message.content[0].text)
@antstanley
antstanley / mimeTypes.json
Created May 7, 2024 10:11
JSON dictionary of file extensions and their corresponding mime types
{
"./aac": "audio/aac",
".abw": "application/x-abiword",
".apng": "image/apng",
".arc": "application/x-freearc",
".avif": "image/avif",
".avi": "video/x-msvideo",
".azw": "application/vnd.amazon.ebook",
".bin": "application/octet-stream",
".bmp": "image/bmp",
@antstanley
antstanley / cors.json
Created October 5, 2022 23:55
Example of CORS headers for API Gateway with Authorization and Cookies
{
"Access-Control-Allow-Headers":
"Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token, Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Credentials, Cookie, Set-Cookie",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS, GET",
"Access-Control-Allow-Credentials": true
}
@antstanley
antstanley / .env
Created September 9, 2021 00:33
Get Cognito User Token
COGNITO_CLIENT_ID=<cognito client id>
COGNITO_USER_POOL_ID=<cognito user pool id>
COGNITO_USERNAME=<cognito username>
COGNITO_PASSWORD=<cognito user password>
@antstanley
antstanley / buildUpdateParams.js
Created February 16, 2021 11:05
Dynamically build update parameters required for the DynamoDB Client. Just pass a JSON object of the fields you want to update and get the UpdateExpression, ExpressionAttributeNames and ExpressionAttributeValues returned.
function mapToObject (processMap) {
const returnObject = {}
for (const [key, value] of processMap) {
returnObject[key] = value
}
return returnObject
}
function randomString (stringLength) {
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'
@antstanley
antstanley / index.js
Created April 11, 2019 14:09
Google Run test code with file system layout
const express = require('express')
const fs = require('fs')
const path = require('path')
const app = express()
let coldstart = true
const fsExplore = async dir => {
try {
const dirContents = fs.readdirSync(dir, {
@antstanley
antstanley / .eleventy.js
Last active September 12, 2022 21:43
Using PurgeCSS and CleanCSS with 11ty to remove unused CSS selectors
const Purgecss = require('purgecss')
const { JSDOM } = require('jsdom')
const CleanCSS = require("clean-css");
//array of css files to combine
const cssFiles = ['./src/css/custom.css','./src/css/markdown.css', './src/css/tachyons.css']
// cleanCSSOptions for minification and inlining css, will fix duplicate media queries
const cleanCSSOptions = {
level: {
@antstanley
antstanley / slightlyMoreEventFun.js
Last active May 29, 2018 10:06
publishing to EventGrid using REST endpoints and Request module
const uuid = require("uuid").v4;
const topicCreds = "mytopickey";
const topicEndpoint = "mytopic.westeurope-1.eventgrid.azure.net";
const request = require('request');
function publishEvent(topicURL, topicSecret, eventPayload, callback) {
const options = {
method: 'POST',
url: topicURL,
@antstanley
antstanley / publishEvent.js
Last active May 29, 2018 09:55
example to publish event to Azure Event Grid using Request module and Azure REST interface
const request = require('request');
function publishEvent(topicURL, topicSecret, eventPayload, callback) {
const options = {
method: 'POST',
url: topicURL,
headers: {
'aeg-sas-key': topicSecret
},