Skip to content

Instantly share code, notes, and snippets.

View chathurawidanage's full-sized avatar
🏠
Working from home

Chathura Widanage chathurawidanage

🏠
Working from home
View GitHub Profile
initialPartitions = roundUp(( readCapacityUnits / 3,000 ) + ( writeCapacityUnits / 1,000 ))
= roundUp((5000 / 3000) + (1000 / 1000))
= 1.667 + 1
= 2.667
= 3
npm init
npm install --save validate.js
let AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient();
const validate = require("validate.js");
exports.handler = function (event, context, callback) {
//validating email and name
var constraints = {
email: {
presence: true,
email: true
const { execSync } = require('child_process');
const fs = require("fs");
let read = fs.readFileSync('index.js'); //reading myself
let code = read.toString();
let requireRegex = /=\s*require\s*\(['\"](.+)['\"]\)/g;
let match = requireRegex.exec(code);
while (match != null) {
npm install --prefix /tmp <library_name> --save
const { execSync } = require('child_process');
let oldRequire = require;
require = function(module) {
try{
oldRequire.resolve(`/tmp/node_modules/${module}`);
}catch(e){
execSync(`npm install --prefix /tmp --save ${module}`);
}
return oldRequire(`/tmp/node_modules/${module}`);
const { execSync } = require('child_process');
let oldRequire = require;
require = function(module) {
try{
oldRequire.resolve(`/tmp/node_modules/${module}`);
}catch(e){
execSync(`npm install --prefix /tmp --save ${module}`);
}
return oldRequire(`/tmp/node_modules/${module}`);
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template creates the stack for project PJ-1-0-0. Generated by Sigma",
"Outputs": {
"apigcontactuscontactPOST": {
"Description": "POST endpoint for resource /contact on API contact_us",
"Value": {
"Fn::Join": [
"",
[
//Old Fashion 1 - Two callback functions
oldFashionOne(function(error){
//handle error
},function(data){
//handle data
});
//Old Fashion 2 - One callback function with two arguements
oldFashionTwo(function(err,data){
if(!err){
@chathurawidanage
chathurawidanage / twocallbacks.js
Created March 30, 2018 05:39
Using two callbacks to handle success and failure
function task(onSuccess,onError){
//do task
if(failed){
onError(error);
}else{
onSuccess(data);
}
}
//calling task