Skip to content

Instantly share code, notes, and snippets.

View tarasowski's full-sized avatar
:electron:

Dimitri (Dimi) Tarasowski tarasowski

:electron:
View GitHub Profile
@tarasowski
tarasowski / .js
Last active July 18, 2018 09:22
#Lambda - Sample Code: Resizing Images
'use strict'
const AWS = require('aws-sdk')
const gm = require('gm').subClass({ imageMagick: true})
const util = require('util')
const path = require('path')
const parse = require('./parse')
const s3 = new AWS.S3()
// constants
const WEB_WIDTH_MAX = 150
@tarasowski
tarasowski / create-table.sh
Last active July 18, 2018 09:20
#DynamoDB - Create New Table CLI
aws dynamodb create-table --table-name AppSync-Destinations --attribute-definitions AttributeName=id,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
@tarasowski
tarasowski / load-data.sh
Last active July 18, 2018 09:27
#DynamoDB - Load Sample Data
aws dynamodb batch-write-item --request-items file://Destinations.json
@tarasowski
tarasowski / cloud9-bootstrap.bash
Last active July 18, 2018 09:19
#Cloud9 - Bootstrapping Node + AWS SAM
#!/bin/bash
## README
# To run this script
# => run `sudo bash cloud9-bootstrap.sh`
# Install node 8.10
nvm install 8.10
# Set node 8.10 as default
nvm alias default 8.10
@tarasowski
tarasowski / local-invocation.js
Last active July 18, 2018 09:20
#Lambda - Local Invocation AWS SAM
sam local invoke SaveContact -e ../../_mocks/lambda-payload-save-contact.json --template ../../../../template.yaml
sam local invoke SaveCompany -e ../../_mocks/lambda-payload-save-company.json --template ../../../../template.yaml
sam local invoke SaveDeal -e ../../_mocks/lambda-payload-save-deal.json --template ../../../../template.yaml
sam local invoke SaveActivity -e ../../_mocks/lambda-payload-save-activity.json --template ../../../../template.yaml
//stdin
echo '{"message": "Hey, are you there?" }' | sam local invoke "Ratings"
@tarasowski
tarasowski / short-circuit.js
Last active July 18, 2018 09:21
#JavaScript - Short Circuit
let isVarAssigned = false
// if isVarAssigned is true, assign the value else assign 'There is no variable assigned' String
const x = isVarAssigned || 'There is no variable assigned'
console.log(x)
// if isVarAssigned is true go and assign the value 'Yes the variable is assigned' if false assign false
const y = isVarAssigned && 'Yes there is a variable assiged'
@tarasowski
tarasowski / aws-cli-cognito.md
Last active July 18, 2018 09:18
#Cognito - Adding New User
$ aws cognito-idp admin-create-user --user-pool-id eu-west-1_Ez3lS4Q8O --username email@email.com --user-attributes file://cognito-create-user.json
[
  {
    "Name": "name",
 "Value": "Dimitri"
@tarasowski
tarasowski / lambda-parallel.js
Last active July 18, 2018 09:18
#Lambda - Async Code Parallel Execution
// This lambda function will not timeout during a 3sec, since all 3 background processes happening at the same time
const hello1 = () => {
return new Promise(resolve => {
setTimeout(() => resolve(console.log('Hello from Hello1')), 2000)
})
}
const hello2 = () => {
return new Promise(resolve => {
@tarasowski
tarasowski / lambda-async-await.md
Last active July 22, 2023 04:47
#Lambda - Async/Await Rules
  1. The function after await someFunc() need to return a promise. Otherwise it will not await and exit from the function. The function below will simply exit and won't wait till the background process is finished. Since async functions are waiting for Promises. The keyword await makes JavaScript wait until that promise settles and returns its result.
const hello4 = () => setTimeout(() => console.log('Hello from Hello4'), 5000)

const asycFunc = async() => {
	await hello4()
    return
}
@tarasowski
tarasowski / callbacks-promises.md
Last active July 18, 2018 09:25
#JavaScript - Callbacks vs. Promises

Using Callbacks

const posts = [
    { title: 'Post One', body: 'This is post one' },
    { title: 'Post Two', body: 'This is post two' }
]

const getPosts = () => {
    setTimeout(() => {
        let output = ''