This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function conditionalVersionRemoveFriendByValue(friendName) { | |
const Key = { id: "1234" }; | |
// fetch the document | |
const document = (await DynamoDB.get({ | |
TableName, | |
Key | |
}).promise()).Item; | |
// find the index | |
let indexToRemove = document.friends.indexOf(friendName); | |
let version = document.version; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DynamoDB.put({ TableName, Item: { | |
id: "1234", | |
name: "carl", | |
friends: ["meatwad", "frylock", "shake"], | |
version: 1, | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helper function to return the error in a promise | |
async function updateWithErrorWrapper(params) { | |
return new Promise(resolve => { | |
DynamoDB.update(params, (err, data) => { | |
resolve({ err, data }); | |
}); | |
}); | |
} | |
async function conditionalRemoveFriendByValue(friendName) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
TableName, | |
Key, | |
UpdateExpression: `REMOVE friends[${indexToRemove}]`, | |
ConditionExpression: `friends[${indexToRemove}] = :valueToRemove`, | |
ExpressionAttributeValues: { | |
":valueToRemove": friendName | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function removeFriendByValue(friendName: string) { | |
const Key = { id: "1234" }; | |
// fetch the document | |
let result = await DynamoDB.get({ | |
TableName, | |
Key | |
}).promise(); | |
// find the index | |
const indexToRemove = result.Item.friends.indexOf(friendName); | |
if (indexToRemove === -1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DynamoDB.put({ TableName, Item: { | |
id: "1234", | |
name: "carl", | |
friends: ["meatwad", "frylock", "shake"] | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await foreach (string message in GetChatMessagesAsync()) { | |
Render(message); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebSocket = require('ws'); | |
const readline = require('readline'); | |
const url = process.argv[2]; | |
const ws = new WebSocket(url); | |
ws.on('open', () => console.log('connected')); | |
ws.on('message', data => console.log(`From server: ${data}`)); | |
ws.on('close', () => { | |
console.log('disconnected'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
// apply the patch | |
require('./patch.js'); | |
let send = undefined; | |
function init(event) { | |
const apigwManagementApi = new AWS.ApiGatewayManagementApi({ | |
apiVersion: '2018-11-29', | |
endpoint: event.requestContext.domainName + '/' + event.requestContext.stage | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('aws-sdk/lib/node_loader'); | |
var AWS = require('aws-sdk/lib/core'); | |
var Service = AWS.Service; | |
var apiLoader = AWS.apiLoader; | |
apiLoader.services['apigatewaymanagementapi'] = {}; | |
AWS.ApiGatewayManagementApi = Service.defineService('apigatewaymanagementapi', ['2018-11-29']); | |
Object.defineProperty(apiLoader.services['apigatewaymanagementapi'], '2018-11-29', { | |
get: function get() { | |
var model = { |