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 / update-github-diffstats.js
Created January 27, 2013 17:44
Wanted to take a screenshot of GitHub diff-stats UI but didn't want to count some of the files/changes in the commit so I wrote a quick script to update them after deleting unwanted nodes from the DOM.
/*
* Use Chrome web inspector to remove elements for files
* you don't want to count in the diff stats, then run this
* function to update the diff stats in the UI
*/
function () {
var allAdditions = 0;
$(".diffstat > a").each( function (index, element) {
$(".diffstat-bar", this).remove();
var addition = $.trim($(this).text().replace(/[A-Za-z$-]/g, ""));
@andrhamm
andrhamm / redis-expireeq.rb
Last active August 29, 2015 14:27
Redis LUA script for atomically setting a key's expiration if its value is unchanged
# 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)
<---
_._ _..._ .-', _.._(`))
'-. ` ' /-._.-' ',/
) \ '.
/ _ _ | \
| a a / |
\ .-. ;
'-('' ).-' ,' ;
'-; | .'
\ \ /
@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:

@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 / 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 / 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 / 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 / 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 / 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;