Skip to content

Instantly share code, notes, and snippets.

:shipit:
Shipping 🔥 & ⚡️

Andrew Hammond andrhamm

:shipit:
Shipping 🔥 & ⚡️
Block or report user

Report or block andrhamm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@andrhamm
andrhamm / deepChangeKeyCase.js
Last active Oct 18, 2019
Javascript Deep Change Key Case
View deepChangeKeyCase.js
// 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;
@andrhamm
andrhamm / await-state-machine-execution.js
Last active Jun 14, 2019
API Gateway Synchronous Step Function Execution
View await-state-machine-execution.js
// 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 / AWS JavaScript SDK - Configure AWS Service Client from an API Service Model (JSON files).md
Last active May 9, 2019
AWS JavaScript SDK - Configure AWS Service Client from an API Service Model (JSON files)
View AWS JavaScript SDK - Configure AWS Service Client from an API Service Model (JSON files).md

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 / signing.rb
Created May 10, 2018
Signing in Ruby/Rails with no dependencies
View signing.rb
# 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 / callbacks.js
Last active Jul 31, 2019
Paginating Scans & Queries in DynamoDB with Node.js using Callbacks OR Promises
View callbacks.js
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 / killsticky.js
Created Oct 13, 2017
Kill Sticky Header (Bookmarklet)
View killsticky.js
// 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 / delete-reddit-history.js
Created Sep 6, 2017
Delete reddit comment and post history
View delete-reddit-history.js
// 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() {
View keybase.md

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:

View emotional_support_pig.html
<---
_._ _..._ .-', _.._(`))
'-. ` ' /-._.-' ',/
) \ '.
/ _ _ | \
| a a / |
\ .-. ;
'-('' ).-' ,' ;
'-; | .'
\ \ /
@andrhamm
andrhamm / redis-expireeq.rb
Last active Aug 29, 2015
Redis LUA script for atomically setting a key's expiration if its value is unchanged
View redis-expireeq.rb
# EXPIREEQ key value_assertion seconds
# Set a timeout on key if the current value equals value_assertion.
# EXPIREEQ is short for "EXPIRE if EQual"
# The lua script:
expireeq = <<-EOF
local key = KEYS[1]
local val_assert = ARGV[1]
local ex = ARGV[2]
local val = redis.call("GET", key)
You can’t perform that action at this time.