This file contains 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
//Parse and extract data from a string like: param1=111¶m2=222¶m3=333 | |
const parseQryStr = (url)=>{ | |
//Match xxx=yyy | |
const paramRegex = '[a-zA-Z0-9]=[a-zA-Z0-9]'; | |
//Split the params. | |
const params = url.split('&'); | |
//Extract the variables if match with the format. |
This file contains 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
class Animal{ | |
constructor(sound){ | |
this.sound = sound; | |
} | |
speak(text){ | |
//Split the input text by space. | |
let chunks = text.split(' '); |
This file contains 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
//Include joi module schema validator. | |
const Joi = require('joi'); | |
/* | |
Receive a js structure using joi values and return it as a joi object with keys. | |
Params: | |
schema : {strucutre} | |
Returns: | |
{Joi object} | |
*/ |
This file contains 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 getTimeZone = ()=>{ | |
let timezone_offset_min = new Date().getTimezoneOffset(), | |
offset_hrs = parseInt(Math.abs(timezone_offset_min/60)), | |
offset_min = Math.abs(timezone_offset_min%60), | |
timezone_standard; | |
if(offset_hrs < 10) | |
offset_hrs = '0' + offset_hrs; |
This file contains 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
/* | |
In this example I show how avoid to use assert in nodejs to validate if the parameter is defined. | |
*/ | |
//Star from here. | |
const assert = require('assert'); | |
//Using with assert | |
const sum3 = (a,b,c)=>{ |
This file contains 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') | |
AWS.config.update({ | |
region: 'us-east-1' | |
}) | |
const parameterStore = new AWS.SSM(); | |
module.exports.get = async (event, context) => { |
This file contains 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 workerpool = require('workerpool'); | |
const pool = workerpool.pool({maxWorkers: 7}); | |
//Define filter prototype for be used into a worker. | |
const filterWorker = (values,fnStr) => values.filter(eval(fnStr)); | |
//Declare new prototype for array filter into a worker. | |
Array.prototype.filter = async function(fn){ | |
//Assign the operation in the worker. |
This file contains 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
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
REPO_ROOT=$(git rev-parse --show-toplevel) | |
echo "Git repo is at $REPO_ROOT" | |
SITE_CHANGES=$(git diff origin/develop -- ./package.json | grep version | wc -l) | |
echo "Detected $SITE_CHANGES changes" |
This file contains 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
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
ORANGE='\033[0;33m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' |
This file contains 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'); | |
const rekognition = new AWS.Rekognition(); | |
const s3 = new AWS.S3({apiVersion: "2006-03-01"}); | |
exports.handler = async (event) => { | |
const params = { | |
Attributes: ["ALL"], | |
Image: { | |
S3Object: { |
OlderNewer