Skip to content

Instantly share code, notes, and snippets.

Avatar

Joakim Hedlund Sleavely

View GitHub Profile
@Sleavely
Sleavely / README.md
Created Jun 30, 2020
ACL Management API prototype
View README.md

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
Sleavely / README.md
Last active Apr 21, 2020
Restricted-access environment variables for AWS Lambda
View README.md

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
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
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_ACCESS_KEY_ID: 'ASIA5USITABHEEWHMCOL',
AWS_DEFAULT_REGION: 'eu-west-1',
AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs12.x',
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '128',
AWS_LAMBDA_FUNCTION_NAME: 'tmp1337',
AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/tmp1337',
AWS_LAMBDA_LOG_STREAM_NAME: '2020/01/14/[$LATEST]425d2a3419de4db38f86fc1896cc1cc1',
@Sleavely
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
Sleavely / download-file.js
Last active Jun 10, 2019 — 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([response.data], { type: 'application/octet-stream' })
const filename = response.headers['content-disposition'].split('"')[1]
if (typeof window.navigator.msSaveBlob !== 'undefined') {
@Sleavely
Sleavely / jira.sh
Created Mar 26, 2019
A bash function for quickly opening tickets in Jira
View jira.sh
# put this in your ~/.profile or equivalent
JIRA_HOST="foobar.atlassian.net"
function jira {
# Uppercase the argument
TARGET_TICKET=${TARGET_TICKET^^}
# Inject dash if its not there
TARGET_TICKET=$(echo ${1} | sed -E --expression='s/([A-Z]+)([0-9]+)/\1-\2/g')
@Sleavely
Sleavely / api.js
Last active Aug 11, 2020
A helper for running a local webserver against lambda-api
View api.js
// Require the framework and instantiate it
const api = require('lambda-api')()
// Define a route
api.get('/status', async (req, res) => {
return { status: 'ok' }
})
api.get('/README.md', async (req, res) => {
res.sendFile('./README.md')
You can’t perform that action at this time.