Skip to content

Instantly share code, notes, and snippets.

{
title: "Bread Sticks",
category: "Appetizer",
elements: [
{
title: "garlic butter",
ingredients: [
{
count: 1.5,
title: "butter"
@misterussell
misterussell / rmt620.js
Created June 20, 2018 22:43
response mapping temp
#set($elements = [])
#set($ingredients = [])
#foreach($item in $ctx.result.items)
#if($item['dbtype']=="info")
#set($title = $item['title'])
#set($status = $item['status'])
#set($id = $item['id'])
#set($type = $item['type'])
#set($category = $item['category'])
@misterussell
misterussell / response620.js
Created June 20, 2018 22:35
expected return
{
"id": "87971",
"category": "breakfast",
"elements": [
{
"title": "dough",
"ingredients": [
{
"title": "flour",
"count": 1,
@misterussell
misterussell / rqmap620.js
Created June 20, 2018 22:30
request map
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
"expression": "id = :id",
"expressionValues" : {
":id" : {
"S" : "${ctx.args.id}"
}
}
@misterussell
misterussell / iam.js
Created June 5, 2018 19:05
updates for IAM policy
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:DeleteItem",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:Scan",
@misterussell
misterussell / mappingtemp6518.js
Last active June 5, 2018 18:23
resolver request mapping template for 6 5 18 post
#set($recipedata = [])
#foreach($recipe in ${ctx.args.recipes})
$util.qr($recipe.put("author", $ctx.identity.username ))
$util.qr($recipedata.add($util.dynamodb.toMapValues($recipe)))
#end
#set($elementsdata = [])
#foreach($element in ${ctx.args.elements})
$util.qr($elementsdata.add($util.dynamodb.toMapValues($element)))
#end
@misterussell
misterussell / findHighest
Created March 28, 2018 20:00
Find's the highest values in an array and return an object with their indices as keys.
function findHighestValues(arr, numberOfValues) {
return Object.assign(...arr.map((val, i) => [i, val])
.sort((a, b) => b[1] - a[1])
.filter((keyVal, i) => i <= numberOfValues)
.map(([i, val]) => ({[i]: val})));
}
@misterussell
misterussell / golSustains.js
Created March 27, 2018 18:48
Find the adjacent equal values in an arr of values
// this function is rather long for doing something simple.
function getSustainedPeriods(arr) {
let life = [];
let lifeCount = 0;
let death = [];
let deathCount = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[i] === 1) {
life[lifeCount] === undefined ? life[lifeCount] = [1] : life[lifeCount] = [...life[lifeCount], 1];
@misterussell
misterussell / golmetrics-v1.js
Last active March 27, 2018 19:11
Initial versioning for Game Of Life Metrics
// create array of objects to use in testing
function generateExamples() {
const genExample = [
[0, 0, 0, 0, 0],
[0, 1, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 1, 1, 1, 0],
[1, 0, 0, 0, 0]
];
@misterussell
misterussell / newNew.js
Created January 26, 2018 18:32
Replicate the unary new operator
function nouveau(Constructor){
let args = Array.prototype.slice.call(arguments);
function createNew(func){
const newObj = Object.create(func.prototype);
return function() {
func.apply(newObj, arguments)
return newObj;
};
};
return createNew(args[0])(...args.slice(1))