Skip to content

Instantly share code, notes, and snippets.

View DavidWells's full-sized avatar
😃

David Wells DavidWells

😃
View GitHub Profile
@DavidWells
DavidWells / ddb-to-sql.js
Created February 24, 2025 19:43
DynamoDB to SQL statement
function as_sql_insert(attributes, table_name) {
// Create a copy to avoid modifying the original object
let attrs = Object.assign({}, attributes)
console.log('attributes in sql insert: ', attrs)
const removed_attributes = ['__initialised__', 'PK', "SK", "GSI1PK", "GSI1SK", "GSI2PK", "GSI2SK", "GSI3PK", "GSI3SK", "batch"]
for (const attribute of removed_attributes) {
if (attribute in attrs) {
delete attrs[attribute]
}
@DavidWells
DavidWells / run-tests-for-file.bash
Created February 20, 2025 18:41
Bash for VSCode* to run tests in current file. E.g. Inside file.js will run file.test.js, inside file.test.js it runs itself
#!/bin/bash
if [[ "${relativeFile}" == *.test.js ]]; then
FILE="${relativeFile}"
elif [ -f "${fileDirname}/${fileBasenameNoExtension}.test.js" ]; then
FILE="${fileDirname}/${fileBasenameNoExtension}.test.js"
elif [ -f "${fileDirname}/$(basename "${fileDirname}").test.js" ]; then
FILE="${fileDirname}/$(basename "${fileDirname}").test.js"
else
FILE="${relativeFile}"

Resource Costs Prompt

You are an expert AWS Billing consultant. You are to

Below is a list of resources in this CloudFormation stack. Please provide me with their associated costs.

Please output the response with Fixed costs first (For example KMS key costs $1 per month per key), then Variable costs (for example requests to S3 cost $0.01 per 1000 requests).

If any Fixed Monthly Costs are present, please provide the total monthly cost for all Fixed Monthly Costs.

function testFilename(filename) {
const match = filename.match(/^(?:(\d+)[.-])?([^.]+)(?:\.([^.]+))?(?:\.([^.]+))?$/)
if (match) {
const order = match[1]
const base = match[2] ?? filename
const modifier = match[4] ? match[3] : undefined
const extension = match[4] ?? match[3]
console.log({
// UTILS
export const getPaddingFromPrecision = (
floatingPointPrecision: number,
): number => {
return Math.ceil(Math.log2(360 * floatingPointPrecision));
};
export const convertToBinary = (
num: number,
@DavidWells
DavidWells / stringify-object.js
Created September 13, 2023 23:23
stringify object into one line
const props = {
text: 'hello',
boolean: true,
array: ['hi', 'there', true],
object: {
cool: true,
nice: 'awesome'
},
func: () => {},
@DavidWells
DavidWells / highlightMatch.js
Created April 12, 2023 06:37
Highlight text in a string of content
// Used to match HTML entities and HTML characters.
const unescapedHtml = /[&<>"']/g
const hasUnescapedHtml = RegExp(unescapedHtml.source)
const htmlEscapes = {
"&": "&amp",
"<": "&lt",
">": "&gt",
'"': "&quot",
"'": "&#39"
}
@DavidWells
DavidWells / debug-node-script.js
Last active June 27, 2024 14:49
How to easily debug node.js script
const { inspect } = require('util')
/* Log out everything in the deep array/object */
function deepLog(obj) {
console.log(inspect(obj, {showHidden: false, depth: null, colors: true}))
}
function myScript(input) {
/* Lots of crap */
/* And lots more crap */
const fs = require('fs')
const path = require('path')
const cacheManager = require('cache-manager')
const fsStoreHash = require('cache-manager-fs-hash')
const CACHE_KEY = 'foo'
const STORAGE_PATH = (process.env.IS_OFFLINE) ? path.join(__dirname, '../tmp') : '/tmp'
const SECONDS = 60
const MINUTES = 60
const ONE_HOUR = SECONDS * MINUTES
const mbOfStorage = 512