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 WebSocket = require('ws'); | |
| const wss = new WebSocket.Server({port: 8080}); | |
| wss.on('connection', socket => { | |
| socket.on('message', data => { | |
| socket.send(data); | |
| }); | |
| }); | |
| console.log(`Listening on ws://localhost:8080`); |
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 short = require('short-uuid'); | |
| const connections = {}; | |
| const send = (connectionId, data) => { | |
| const connection = connections[connectionId]; | |
| connection.send(data); | |
| } | |
| const defaultActions = { |
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 = { |
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
| 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
| 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
| 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
| 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
| { | |
| TableName, | |
| Key, | |
| UpdateExpression: `REMOVE friends[${indexToRemove}]`, | |
| ConditionExpression: `friends[${indexToRemove}] = :valueToRemove`, | |
| ExpressionAttributeValues: { | |
| ":valueToRemove": friendName | |
| } | |
| } |