Skip to content

Instantly share code, notes, and snippets.

Sleavely / orchestrate-apidocs.js
Created Nov 2, 2020
A Serverless extension for orchestrating API->Lambda setups from your Swagger/OpenAPI definitions. This workflow encourages that the documentation is kept up-to-date.
View orchestrate-apidocs.js
const ServerlessAWSCloudFormationSubVariables = require('serverless-cloudformation-sub-variables')
class ApiOrchestrator {
constructor(serverless) {
this.serverless = serverless
// Register ${lambda:myFunctionKey} so that we can
// refer to it from our Swagger/OpenAPI definition
this.variableResolvers = {
Sleavely /
Created Jun 30, 2020
ACL Management API prototype

Open it in a fancy viewer here or locally with swagger-local:

$ swagger-local swagger.yaml
View gpio.js
const Gpio = require('onoff').Gpio;
const sleep = require('./sleep')
const motor = new Gpio(17, 'out')
// Run the motor connected to GPIO17 every 1000ms
let beltIsShuttingDown = false
const runBelt = async () => {
if (beltIsShuttingDown) return
Sleavely /
Last active Apr 21, 2020
Restricted-access environment variables for AWS Lambda

This Lambda showcases how you can prohibit certain users from seeing or interacting with the environment variables of a Lambda.

Deployment assumes that you use aws cloudformation package followed by aws cloudformation deploy. Here's a suggested Makefile for allowing you to type make deploy. Note that the S3DEPLOYBUCKET and SECRET_PASSWORD variables need to be changed:

SECRET_PASSWORD    ?= pancakes
S3DEPLOYBUCKET      = my-s3-bucket
Sleavely / attributeResolution.js
Created Mar 22, 2020
Product attribute schema POC
View attributeResolution.js
const attributes = {
// Attribute Keys are always localized
'color': {
name: {
'en-US': 'Color',
'sv-SE': 'Färg',
'size': {
Sleavely / process.env.js
Last active Mar 22, 2020
AWS Lambda environment variables when running with a default configuration
View process.env.js
// The original values have been redacted, but their general format remains for display purposes.
AWS_DEFAULT_REGION: 'eu-west-1',
AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs12.x',
AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/tmp1337',
AWS_LAMBDA_LOG_STREAM_NAME: '2020/01/14/[$LATEST]425d2a3419de4db38f86fc1896cc1cc1',
Sleavely / lodash-get.js
Created Oct 7, 2019
lodash.get alternative that covers _most_ cases.
View lodash-get.js
// Graciously stolen from lodash's stringToPath
const charCodeOfDot = '.'.charCodeAt(0)
const reEscapeChar = /\\(\\)?/g
const rePropName = RegExp(
// Match anything that isn't a dot or bracket.
'[^.[\\]]+' + '|' +
// Or match property names within brackets.
'\\[(?:' +
// Match a non-string expression.
'([^"\'][^[]*)' + '|' +
View App.jsx
import React, { useEffect, useState } from 'react'
import { CartProvider } from "use-cart"
import { LoadCart, SaveCart } from "./cartStorage"
function App() {
return (
<CartProvider initialCart={LoadCart()}>
<SaveCart />
<RestOfApp> ... </RestOfApp>
Sleavely / download-file.js
Last active Oct 30, 2020 — forked from javilobo8/download-file.js
Download files from Lambda with AWS Amplify
View download-file.js
await API.get('myCloudApi', '/items', {
responseType: 'blob',
response: true
.then((response) => {
const blob = new Blob([], { type: 'application/octet-stream' })
const filename = response.headers['content-disposition'].split('"')[1]
if (typeof window.navigator.msSaveBlob !== 'undefined') {
Sleavely /
Created Mar 26, 2019
A bash function for quickly opening tickets in Jira
# put this in your ~/.profile or equivalent
function jira {
# Uppercase the argument
# Inject dash if its not there
TARGET_TICKET=$(echo ${1} | sed -E --expression='s/([A-Z]+)([0-9]+)/\1-\2/g')