Skip to content

Instantly share code, notes, and snippets.

View ThomRoman's full-sized avatar

ThomRoman

View GitHub Profile
const reduce = ([a,...b],fn,initValue)=>a?reduce(b,fn,fn(initValue,a)):initValue
const map = (arr,fn)=>reduce(arr,(acc,curr)=>acc.concat(fn(curr,arr)),[])
const filter = (arr,fn)=>reduce(arr,(acc,curr)=>fn(curr)? acc.concat(curr) :acc,[])
const print = console.log
/**
* @author Thom Maurick Roman Aguilar - thomtwd@gmail.com
* @param {arr} es el array para buscar
* @param {value} es el element que será el que comprueba
* @return La función retornará un array de array
* @example ([2,6,8,0,9,-10,-1]) and 8 => [[2,6] ,[8,0],[9,-1]]
@ThomRoman
ThomRoman / pso.py
Last active July 10, 2019 05:46
Implementing the Particle Swarm Optimization
#!/usr/bin/python3
"""
* AUTHOR : https://gist.github.com/IranNeto/21542660d740ac02dfce2f6aeb11ebeb
https://github.com/IranNeto
* WEB : https://medium.com/analytics-vidhya/implementing-particle-swarm-optimization-pso-algorithm-in-python-9efc2eb179a6
"""
# https://code.sololearn.com/cvIleZW1gfC6/#py
import random
import numpy as np
@ThomRoman
ThomRoman / parse-jwt.js
Created July 18, 2019 01:07
Obtener PayLod , fecha de creación y expiración JWT
const parseJWT = token =>{
let base64URL = token.split('.')[1]
let base64 = base64URL.replace('-','+').replace('_','/')
return JSON.parse(window.atob(base64))
}
@ThomRoman
ThomRoman / postman.js
Last active July 18, 2019 21:28
Settings Test Postman
// test postman
let res = pm.response.json();
if(res.ok) {
let token = res.token;
pm.environment.set("token", token);
}else{
console.log('No se actualizó el token');
}
@ThomRoman
ThomRoman / singleton.java
Created July 23, 2019 05:54
Singleton java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.shoppingcar.model.dao.postgres;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@ThomRoman
ThomRoman / trampoline.js
Created August 23, 2019 01:56
avoid stack overflow
const trampoline = fn => (...args)=>{
let result = fn(...args)
while (typeof result === 'function')
result = result()
return result
}
const sum = (number,step=0)=>(
!number?step:()=>sum(number-1,step+number)
)
// const tsum = trampoline(sum)(500000) // currying
touch .gitignore && echo "node_modules" >> .gitignore
const coords = navigator.geolocation.getCurrentPosition(position=>{
console.log(position)
let coord = position.coords
let lat = coord.latitude
let long = coord.longitude
console.log(lat,long)
})
@ThomRoman
ThomRoman / generics.ts
Last active September 1, 2019 06:12
Data Structures
const printFullName_1 = <T extends {name:string,lastName:string}>(obj:T)=>({
...obj,
fullName:`${obj.name} ${obj.lastName}`
})
interface IPerson{
name:string,
lastName:string
}
class Course{
constructor(private _id:number,private _name:string){
}
get id(){
return this._id
}
set id(id:number){
this._id=id
}