Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View andrhamm's full-sized avatar
:shipit:
Shipping 🔥 & ⚡️

Andrew Hammond andrhamm

:shipit:
Shipping 🔥 & ⚡️
View GitHub Profile
@andrhamm
andrhamm / AWS JavaScript SDK - Configure AWS Service Client from an API Service Model (JSON files).md
Last active September 22, 2023 21:50
AWS JavaScript SDK - Configure AWS Service Client from an API Service Model (JSON files)

The AWS JavaScript SDK (and presumably SDKs for other langauges) are dynamically configured from JSON files that specify all the possible API endpoints and their request/response structure for the given service.

In the case of Amazon Personalize, the minimal documentation only describes how to "load" these JSON files for the CLI SDK:

https://docs.aws.amazon.com/personalize/latest/dg/aws-personalize-set-up-aws-cli.html

Here is an example of how to configure a service client object in the JavaScript SDK. I arrived at this conclusion by exploring the node_modules/aws_sdk directory, specifically the apis, and clients subdirectory.

(Download the service models from the page linked above.)

@andrhamm
andrhamm / delete-reddit-history.js
Created September 6, 2017 20:50
Delete reddit comment and post history
// Load user profile page, if using RES scroll so many comments are loaded onto the page
// then enter the following in the browser's developer console.
// it will delete 1 post/comment every 1500ms
var $domNodeToIterateOver = $('.del-button .option .yes'),
currentTime = 0,
timeInterval = 1500;
$domNodeToIterateOver.each(function() {
@andrhamm
andrhamm / aws-auth-mfa.sh
Last active May 16, 2022 15:49
Simple AWS CLI MFA login script
#!/bin/bash
set -eo pipefail
# Note: this script will overwrite your credentials for the `default` AWS profile, you may wish to create a backup
# Pre-requisites:
# 1) Run:
# brew install jq awscli
# 2) Add alias to .zshrc or .bashrc:
# alias aws-auth-mfa="~/.scripts/aws-auth-mfa.sh"
@andrhamm
andrhamm / callbacks.js
Last active April 27, 2022 17:01
Paginating Scans & Queries in DynamoDB with Node.js using Callbacks OR Promises
const AWS = require('aws-sdk');
AWS.config.logger = console;
const dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' });
let val = 'some value';
let params = {
TableName: "MyTable",
ExpressionAttributeValues: {
@andrhamm
andrhamm / await-state-machine-execution.js
Last active December 23, 2021 06:35
API Gateway Synchronous Step Function Execution
// handlers/await-state-machine-execution.js
import AWS from 'aws-sdk';
import { snakeCaseObj } from '../lib/common';
const stepfunctions = new AWS.StepFunctions({apiVersion: '2016-11-23'});
const {
STATE_MACHINE_ARN,
} = process.env;
@andrhamm
andrhamm / deepChangeKeyCase.js
Last active November 2, 2020 16:20
Javascript Deep Change Key Case
// deeply changes the case of object keys, including in sub arrays of objects
const _ = require('lodash');
function deepChangeKeyCase(value, fn) {
if (Array.isArray(value)) {
return value.map(v => deepChangeKeyCase(v, fn));
} else if (_.isPlainObject(value)) {
return Object.entries(value).reduce((acc, [k, v]) => {
acc[fn(k)] = deepChangeKeyCase(v, fn);
return acc;
<---
_._ _..._ .-', _.._(`))
'-. ` ' /-._.-' ',/
) \ '.
/ _ _ | \
| a a / |
\ .-. ;
'-('' ).-' ,' ;
'-; | .'
\ \ /
@andrhamm
andrhamm / signing.rb
Created May 10, 2018 15:55
Signing in Ruby/Rails with no dependencies
# JWT-like tokens in Rails
require 'openssl'
require 'base64'
# Generate encrypted signing key
key = OpenSSL::PKey::RSA.new(2048)
cipher = OpenSSL::Cipher.new('AES-128-CBC')
@andrhamm
andrhamm / killsticky.js
Created October 13, 2017 13:07
Kill Sticky Header (Bookmarklet)
// Found this bookmarklet on a blog post somewhere and it is awesome.
// Save to bookmark bar and click to kill any annoying floating headers that take up you vertical resolution
javascript:(function()%7B(function%20()%20%7Bvar%20i%2C%20elements%20%3D%20document.querySelectorAll('body%20*')%3Bfor%20(i%20%3D%200%3B%20i%20%3C%20elements.length%3B%20i%2B%2B)%20%7Bif%20(getComputedStyle(elements%5Bi%5D).position%20%3D%3D%3D%20'fixed')%20%7Belements%5Bi%5D.parentNode.removeChild(elements%5Bi%5D)%3B%7D%7D%7D)()%7D)()
@andrhamm
andrhamm / keybase.md
Created September 6, 2017 20:00
Keybase proof

Keybase proof

I hereby claim:

  • I am andrhamm on github.
  • I am andrhamm (https://keybase.io/andrhamm) on keybase.
  • I have a public key ASD1L_zjBmhhjwPN9qUKs_j3afa7VxjZaxsSRq_qahht_Ao

To claim this, I am signing this object: