Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Sleavely / README.md
Last active April 21, 2020 11:32
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
Sleavely / process.env.js
Last active March 22, 2020 14:14
AWS Lambda environment variables when running with a default configuration
// 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 / attributeResolution.js
Created March 22, 2020 13:55
Product attribute schema POC
const attributes = {
// Attribute Keys are always localized
'color': {
name: {
'en-US': 'Color',
'sv-SE': 'Färg',
},
},
'size': {
@Sleavely
Sleavely / lodash-get.js
Created October 7, 2019 13:33
lodash.get alternative that covers _most_ cases.
// 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.
'([^"\'][^[]*)' + '|' +
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 / jira.sh
Created March 26, 2019 14:42
A bash function for quickly opening tickets in Jira
# 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 / apply-price-rules.php
Last active November 22, 2018 16:34
Programmatically apply catalog price rules in Magento
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Bootstrap Magento
require '../magento/app/Mage.php';
Mage::app('admin', 'store');
try{
$catalogPriceRule = Mage::getModel('catalogrule/rule');
@Sleavely
Sleavely / move-tab-new-window.js
Created August 31, 2018 21:09
An IIFE that moves your Chrome tab to a new window. Must be run from an extension with appropriate permissions.
(() => {
const _currentTab = new Promise((resolve) => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
resolve(tabs[0])
})
});
const _currentWindow = new Promise((resolve) => {
chrome.windows.getCurrent((win) => resolve(win))
});
@Sleavely
Sleavely / JsonpDetector.js
Last active April 4, 2018 11:43
A middleware for automatically converting AdonisJS responses to JSONP
'use strict'
const Config = use('Config')
/**
* JSON-P middleware for AdonisJS 4.1
* https://gist.github.com/Sleavely/da1ac50e1ea614b4171beae7868ec3ed
*/
class JsonpDetector {
async handle ({ request, response }, next) {
@Sleavely
Sleavely / promise-catch-skip.js
Created October 19, 2017 11:41
Simple showcase of how faulty catch() might behave different than you expect.
Promise.resolve(true)
.then(() => {
console.log('First then() was called!');
throw new Error('error!!!');
return true;
})
.catch((err) => {
console.log('First catch() was called');
console.log('Error: ', err);