Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
cmawhorter / troubleshooting.md
Last active February 28, 2024 16:28
Solution to AWS Lambda node.js UnrecognizedClientException "The security token included in the request is invalid."

Troubleshooting AWS unauthorized errors in lambda requests

This is mainly for node.js but might apply to other environments. Unsure.

If you are running a AWS Lambda function that calls another AWS service and getting an error about invalid tokens or other access denied errors, do this:

Check IAM

The role assigned to your lambda function will need permission to perform the actions. Check IAM and make sure the role has all the permissions.

@cmawhorter
cmawhorter / mp-util-classes.css
Created October 25, 2017 19:03
Margin and padding utility classes
.ma-0,
.my-0,
.mt-0 {
margin-top: 0;
}
.ma-q,
.my-q,
.mt-q {
margin-top: .25rem;
@cmawhorter
cmawhorter / proxy.js
Created June 26, 2014 05:36
Node script to forward all http requests to another server and return the response with an access-control-allow-origin header. Follows redirects.
// Simple proxy/forwarding server for when you don't want to have to add CORS during development.
// Usage: node proxy.js
// Open browser and navigate to http://localhost:9100/[url]
// Example: http://localhost:9100/http://www.google.com
// This is *NOT* for anything outside local development. It has zero error handling among other glaring problems.
// This started as code I grabbed from this SO question: http://stackoverflow.com/a/13472952/670023
@cmawhorter
cmawhorter / test-smtp.js
Created May 11, 2018 16:01
Quick nodejs script to send a test smtp message using nodemailer
'use strict';
// Before running, you need to yarn add yargs nodemailer
// And also replace this with your email:
const DEFAULT_TO_EMAIL = '';
// Username password correct? Make sure your smtp provider doesn't
// have a from/to email address whitelist, or if it does, both emails
// are on it.
@cmawhorter
cmawhorter / .bash_profile
Created October 21, 2014 19:53
Add alias to bash_profile to get a quick http server anywhere. Just type H to serve current directory.
# http://stackoverflow.com/a/12269225/670023
# Binds to localhost
alias H="echo 'Serving HTTP on 127.0.0.1 port 8000 ...'; python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"127.0.0.1\", 8000), shs.SimpleHTTPRequestHandler).serve_forever()'"
@cmawhorter
cmawhorter / list-of-example-arns.js
Created January 21, 2017 02:13
list of all the example arns from the aws arns and namespaces doc page
// all the example arns from this page: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
var arns = [
'arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment',
'arn:aws:iam::123456789012:user/David',
'arn:aws:rds:eu-west-1:123456789012:db:mysql-db',
'arn:aws:s3:::my_corporate_bucket/exampleobject.png',
'arn:aws:artifact:::report-package/Certifications and Attestations/SOC/*',
'arn:aws:artifact:::report-package/Certifications and Attestations/ISO/*',
'arn:aws:artifact:::report-package/Certifications and Attestations/PCI/*',
'arn:aws:autoscaling:us-east-1:123456789012:scalingPolicy:c7a27f55-d35e-4153-b044-8ca9155fc467:autoScalingGroupName/my-test-asg1:policyName/my-scaleout-policy',
@cmawhorter
cmawhorter / workaround-s3-rename.js
Created October 6, 2015 18:03
Help workaround discrepancy between OS directory names and S3 key name collisions
'use strict';
// Script to workaround discrepancies in s3 <=> os file and directory names.
// It allows you to host your static website on s3 without trailing slashes.
// e.g. example.com/products and example.com/products/mugs
if (!process.argv[2]) throw new Error('Must pass bucket as argument');
var options = {
target: '.',
@cmawhorter
cmawhorter / fdsafsad.js
Created June 15, 2016 01:09
if you absolutely want to use that SO code
// snippet for SO: http://stackoverflow.com/a/14138133/670023
// Never do this. Handlers inside of handlers is a Bad Idea regardless of whether they're once or not.
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
//this part runs when the mapobject is created and rendered
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
//this part runs when the mapobject shown for the first time
});
});
@cmawhorter
cmawhorter / bootstrap-half-columns.less
Created July 20, 2016 21:30
Bootstrap 3 half columns pull and push
// Very often while building a responsive site with bootstrap, you run into the need
// to have half columns.
// The accepted solution seems to be wrapping the row in yet-another-row http://stackoverflow.com/a/22986836/670023
// But that's annoying when you just need something to be the correct width at a screen size
// and it won't center.
// This hasn't really been tested but _seems_ to work.
@cmawhorter
cmawhorter / pr-http-proxy-test.js
Created July 6, 2015 16:58
node http-proxy pr perf test
process.title = 'node http-proxy';
var CONCURRENCY = 250;
var assert = require('assert')
, crypto = require('crypto')
, http = require('http');
http.globalAgent.maxSockets = Infinity;