Skip to content

Instantly share code, notes, and snippets.

/*! normalize.css v3.0.0 | MIT License | git.io/normalize */
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
article,
@helephant
helephant / !calling-lambda-cross-account.md
Last active October 24, 2023 03:52
Calling a lambda in another AWS account by assuming a cross-account IAM role

Set up a cross-account IAM role in the destination account

  • Add a new IAM role
  • For type of trusted entity select "another AWS account"
  • Specify the accountId of the account that will be using the resource in the destination account. You can find your AWS Account ID, which is available on the support homepage when you are logged in.
  • Create a policy that allows lambda:InvokeFunction for your function and attach it to this new role.

Create a lambda in the calling account.

  • Set up a role for your lambda that is allowed to assumeRole
  • Use the AWS SDK to assume the new role in the destination account.
  • Pass the credentials to the lambda object when you create it
@helephant
helephant / css rotation on exif images.md
Last active January 23, 2019 17:30
CSS rotation on exif images

Exif rotation in browsers is a journey of disappointment. The definitive guide on the history of it is quite an interesting read. There's also a current state of the world round-up written in 2012, which is pretty much still the same in 2019.

Firefox supports a CSS attribute that tells the browser to respect exif rotation, but no other browser respects it. There's been a Chrome ticket open to fix it for about five years now.

This is a little proof of concept to try to fix the issue with CSS transforms. We didn't end up using it because we had the images in other elements that were already rotated themselves, so we felt like this would probably cause more problems than it solved. But who kn

@helephant
helephant / node sleep.js
Created January 24, 2019 17:42
Javascript snippet for getting a node process to wait for a set period of time. This is useful for debugging, probably don't want to be doing this in real code.
// sleep the function for 5 seconds
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
// Usage!
await sleep(5000);
@helephant
helephant / concurrency-limits-and-step-functions.md
Last active November 23, 2022 10:30
Do step functions wait for an available lambda if they hit a concurrency limit or do they fail?

We have a process that spawns lots of lambdas that we were worried might hit a concurrency limit. We wanted to know what a step function would do in that situation because the AWS documentation says that poll-based services have a built-in retry mechanism if lambdas are throttled and we were hoping that the subsequent steps would simply wait until there was enough capacity.

So I built a step function with three steps that had a sleep in them, and then set the reserve concurrency to 1 for the middle step. Then I kicked off three step functions at the same time.

The result was the second intance of the step function failed on the throttled lamda with the error message: "Lambda.TooManyRequestsException"

There are retry options in step functions, but it is interesting to know that they don't wait for a lambda slot to be available.

@helephant
helephant / image-compare-jest-test.js
Created January 30, 2019 17:23
How to use jest to compare an image to a pre-generated screenshot using an npm library called toMatchImageSnapshot
const { toMatchImageSnapshot } = require('jest-image-snapshot');
const path = require('path');
const fs = require('fs');
var gm = require("gm").subClass({imageMagick: true});;
jest.setTimeout(15000);
expect.extend({ toMatchImageSnapshot });
const imageAtTestPath = path.resolve(__dirname, '11c429f0-8bee-4c86-ab17-e04cf2bd2e11.jpeg');
const pngAtTestPath = path.resolve(__dirname, '11c429f0-8bee-4c86-ab17-e04cf2bd2e11.png');
@helephant
helephant / unicode-output-in-powershell.md
Created March 18, 2019 21:26
How to see characters from non-ASCII character sets in powershell

Check to see what output encoding your console has, to make sure the output of your apps don't end up encoded as Ascii.

> $OutputEncoding
IsSingleByte      : True
BodyName          : us-ascii
EncodingName      : US-ASCII
HeaderName        : us-ascii
WebName           : us-ascii
WindowsCodePage   : 1252
@helephant
helephant / an-intro-to-react.md
Last active April 23, 2019 20:48
Some notes on learning react

Notes on learning react

React is made of ....

React maintains it's own hierarchy of react elements. React elements are plain javascript objects instead of DOM objects, so they are very light-weight and fast to process. React keeps the real DOM elements in sync with the react DOM. When something changes, React compares the new components with the current ones and only re-renders the components that have changed.

A React component will start with a root element that exists somewhere inside a HTML document. Everything under that element will be controlled by the React DOM.

const element = Hello, world;

jmeter -Jthreads=10 -n -t ./my-test.jmx -l my-test-log.jtl -o my-test-output.csv

Useful CLI arguments

  • -n: don't launch the GUI
  • -t: location of the test script
  • -o: location of an output file
  • -l: location of a detailed log file

NPM command cheat sheet

Instantiate NPM in the current directory

npm init

Installing a new package.