Skip to content

Instantly share code, notes, and snippets.

View jasp402's full-sized avatar

jasp402 jasp402

View GitHub Profile
@jasp402
jasp402 / waitForExist()
Created February 12, 2018 14:20
AutoIT - Esperar hasta que exista o se cumpla el timeout
Func waitForExist($element, $iTimeOut)
$sBegin = TimerInit()
While TimerDiff($sBegin) < $iTimeOut
$isExist = WinExists($element)
If $isExist then
ConsoleWrite($isExist&@CRLF)
Return True
Else
ConsoleWrite($isExist&@CRLF)
ContinueLoop
@jasp402
jasp402 / createVar()
Last active February 19, 2019 19:22
VarDinamically
/**
ESTA FUNCION CREA VARIABLES DINAMICAMENTE BASADO EN UN OBJETO.
**/
let etc = { name: 'foobar', city: 'xyz', company: 'companyName' };
Object.keys(etc).forEach(key=>{return eval(`${key.toUpperCase()}='${etc[`${key}`]}'`)});
console.log(NAME) //foobar
console.log(CITY) //xyz
@jasp402
jasp402 / mutiplyAll()
Created March 28, 2018 03:35
Multiplica todos los valores de un array de arrays
const mutiplyAll=arr=>{let r=[];arr.forEach(x=>{x.forEach(y=>{return r.push(y)})});return r.reduce((acc, n) => n * acc)};
console.log(mutiplyAll([[1,2], [3,4], [5,6,7]])); //5040
@jasp402
jasp402 / mutiplyAll()
Created March 28, 2018 03:35
Multiplica todos los valores de un array de arrays
const mutiplyAll=arr=>{let r=[];arr.forEach(x=>{x.forEach(y=>{return r.push(y)})});return r.reduce((acc, n) => n * acc)};
console.log(mutiplyAll([[1,2], [3,4], [5,6,7]])); //5040
@jasp402
jasp402 / mergeArray()
Created March 29, 2018 16:34
merge 2 array (arKeys & ArValues) into one object with Javascript
const arr1 = [{ a: "a", 1: 1, 2: 2 }, { a: "b", 1: 1, 2: 3 }];
const arr2 = [{ a: "a", 3: 123 }, { a: "b", 3: 4411 }];
const result = [...arr1.concat(arr2) // concat the arrays
.reduce((m, o) => m.set(o.a, Object.assign(m.get(o.a) || {}, o)), // use a map to collect similar objects
new Map()
).values()]; // get the values iterator of the map, and spread into a new array
console.log(result);
@jasp402
jasp402 / clearStr()
Last active May 14, 2018 13:26
JavaScript - Regex, (Clear String)
clearStr(str) {
const corrections = {
'&': '',
'\/': '',
'\\': '',
'#': '',
',': '',
'+': '',
'(': '',
')': '',
@jasp402
jasp402 / findInArray()
Last active March 5, 2019 19:49
JavaScript: Search array in Array
let text = 'c';
let findText = [text];
let inArray = ["a",'c','d','g']
let result = [];
findText.find(text => inArray.forEach(arrValue=>text == arrValue && result.push(text)));
console.log(JSON.stringify(result));
// expected output: 12
@jasp402
jasp402 / FormatDateTime()
Last active June 8, 2018 15:44
JavaScript - FormatDate Time
const FormatDateTime=str=>{
let date = new Date(new Number(str));
return (date instanceof Date && !isNaN(date)) ? {
year:date.getFullYear(),
month:(date.getMonth() + 1),
day:date.getDate(),
hour:date.getHours(),
minute:date.getMinutes(),
second:date.getSeconds(),
mlSecond:date.getMilliseconds()
@jasp402
jasp402 / daysInMonth()
Created June 12, 2018 17:18
JavaScript - Generar un Array con el numero de días del mes actual
function daysInMonth() {
return Array.from({length: new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate()}, (x,i)=> { return (i+1); });
}
console.log(daysInMonth()); // 28
@jasp402
jasp402 / generateToken()
Last active June 13, 2018 13:31
JavaScript - Generar Token aleatorio
//VERSION 1
const rand=()=>Math.random(0).toString(36).substr(2);
const token=(length)=>(rand()+rand()+rand()+rand()).substr(0,length);
console.log(token(10));
//VERSION 2
function generateToken(length){
let rand=()=>Math.random(0).toString(36).substr(2);
return (rand()+rand()+rand()+rand()).substr(0,length)