Skip to content

Instantly share code, notes, and snippets.

View damiancipolat's full-sized avatar
💭
Creating amazing things!

DamCipolat damiancipolat

💭
Creating amazing things!
View GitHub Profile
@damiancipolat
damiancipolat / urlparser.js
Last active May 4, 2019 17:41
URL Parser Exercise in JS
//Parse and extract data from a string like: param1=111&param2=222&param3=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.
@damiancipolat
damiancipolat / zoo.js
Created May 4, 2019 17:57
Zoo excercise Javascript
class Animal{
constructor(sound){
this.sound = sound;
}
speak(text){
//Split the input text by space.
let chunks = text.split(' ');
@damiancipolat
damiancipolat / joiDecorate.js
Created June 11, 2019 03:00
Create a joi decorator function that dinamycali extend the validations.
//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}
*/
@damiancipolat
damiancipolat / iso8601.js
Created July 29, 2019 19:05
Get datetime with forma ISO 8601 in javascript
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;
@damiancipolat
damiancipolat / avoid_assert_parameters.js
Last active December 24, 2019 02:00
Avoid use assert in node.js to detect if a function parameters is defined.
/*
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)=>{
@damiancipolat
damiancipolat / awsParamStoreInLambda.js
Created February 18, 2020 00:47
Aws parameter store example into a lambda function
const AWS = require('aws-sdk')
AWS.config.update({
region: 'us-east-1'
})
const parameterStore = new AWS.SSM();
module.exports.get = async (event, context) => {
@damiancipolat
damiancipolat / array_filter_in_worker.js
Created February 26, 2020 04:21
Array file prototype using a worker
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.
@damiancipolat
damiancipolat / bash-githook.sh
Created March 12, 2020 03:24
Bash script to avoid same package.json version to be used in a githook.
#!/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"
@damiancipolat
damiancipolat / git_hook_package.json
Created April 30, 2020 00:44
Bash script to control the package.json version in js projects
#!/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'
@damiancipolat
damiancipolat / rekognitionLambda.js
Created May 11, 2020 15:04
Example of use rekognition - detect faces
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: {