Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / doc-update-partial.js
Last active September 8, 2017 22:51
Automate DynamoDB doc.update call by generating the required attributes from an object literal.
// Note: This takes your data keys and drops them directly into the
// UpdateExpression. If you have more exotic key names, this will likely
// fail because 'this is a valid key name' works in javascript but not the
// dynamodb client.
var keyName = 'thePartitionKey';
var data = {
thePartitionKey: '1231342142321321',
message: 'your partial data i.e. the fields you want updated in the target document'
};
@cmawhorter
cmawhorter / region-policy.txt
Last active January 1, 2016 05:29
AWS IAM inline policy for a user that gives them access to a specific region. Definitely not complete but good enough for me, for now for dev.
I'm no expert here so there may be better ways, but this attempts to give a user complete access to a specific region only.
The first statement covers all resources with ARNs that have the region included. (Everything except S3 and IAM?)
And the second statement specifically handles s3 and gives complete access to all buckets that end in the target region.
{
"Version": "2012-10-17",
"Statement": [
{
@cmawhorter
cmawhorter / gist:d43c326e90340028159a
Created January 1, 2016 03:21
AWS IAM inline policy for a user that gives them access to a specific region. Definitely not complete but good enough for me, for now for dev.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*",
"Condition": {
"StringLike": {
"aws:SourceArn": "arn:aws:*:us-west-2:*"
@cmawhorter
cmawhorter / local-lambda.js
Created December 29, 2015 23:10
Quick and dirty local lambda development environment.
'use strict';
// To use - edit the options below and `node local-lambda.js`
// path to your lambda entry point
var app = require('./index.js');
// the handler you wish to test (you may only have one e.g. exports.handler)
var handler = app.handler;
// simulated max duration
var duration = 30000;
@cmawhorter
cmawhorter / lambda-functionWhileThrottled.js
Last active December 24, 2015 01:59
Script to trigger lambda throttling. Creates many concurrent lambda calls to a long-running function.
// just a control; doesn't matter specifics
exports.handler = function(event, context) {
console.log('starting');
setTimeout(function() {
console.log('done');
context.succeed();
}, 1000);
};
@cmawhorter
cmawhorter / wait-for-state-example.js
Created December 23, 2015 03:53
Wait for all values in state to be true before calling callback or error on timeout.
// similar usecase; abbreviated
var myTask = function(callback) {
var state = { response: false, body: false, other: null }; // only t/f factored when enableNulls
var abortWait = waitForState(state, callback); // returns function to abort with error
var req = request('https://...');
req.on('response', function(res) {
asyncLogResponse(function(err) {
if (err) return abortWait(err); // aborts wait and callbacks immediately
state.response = true;
@cmawhorter
cmawhorter / patch-document-createelement-for-gwt.js
Last active November 12, 2015 05:14
Older versions of GWT used document.createElement incorrectly which leads to an Invalid Character error
// If you're supporting an app built with GWT and running into Invalid Character errors
// in older version of IE, this patch should fix it with no GWT code changes.
//
// Just include thes script before before including your gwt <script src="app.nocache.js">
//
// Yay. GWT magically working again.
// NOTE: Does a console.warn "Init document.createElement interception..." prior to running.
// NOTE: If the patch ever encounters an error it will fall back to the native browser