Skip to content

Instantly share code, notes, and snippets.

When using AWS SAM it is possible to call your local lambdas using the AWS SDK, just as you would lambdas running in AWS. I found this very useful when building acceptance tests that would work on local as well as against our AWS staging environment.

To do it, just run sam local as a service on a specific port:

sam local start-lambda -p 8035

Then you can run your code which calls the lambda.

Git command cheat sheet

Git is the perfect source control for my home projects. It is free, works on mac, linux and windows, makes it easy to share code through github and takes me out of my Microsoft technology comfort zone. Here are the basic commands I need to be productive.

Basics

Adding all changed files in the current directory to the commit:

git add .

Adding any deleted files in the current directory to the commit:

NPM command cheat sheet

Instantiate NPM in the current directory

npm init

Installing a new package.

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