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 / 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 / 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 / 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 / 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 / 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.