Skip to content

Instantly share code, notes, and snippets.

View jgdev's full-sized avatar
🏠
Working from home

Joan Peralta jgdev

🏠
Working from home
View GitHub Profile
@jgdev
jgdev / DateAgo.ts
Created February 13, 2020 02:38
Date
import moment from "moment";
export const msToSeconds = (n: number) => n * 1000;
export const getElapsedTime = (date?: number) => {
if (!date) return "";
let elapsed = 0;
let elapsedPrefix = "";
const timeElapsed = Date.now() - date;
@jgdev
jgdev / cloudSettings
Last active November 3, 2022 06:21
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-08-13T20:52:32.602Z","extensionVersion":"v3.4.3"}
@jgdev
jgdev / 1.prepare-commit-msg
Last active April 24, 2019 00:30
Modify commit message in order to determine which project to deploy in monorepo project | GIT HOOKS
#!/usr/bin/env bash
FILES_CHANGED=$(git status -s | sed -En "s/(M|D|\?\?)//pg" | sed -e 's/^[[:space:]]*//')
DEPLOY_ALL=$(echo "$FILES_CHANGED" | grep -Ec '^(src\/@core|src\/@runner)')
DEPLOY_SERVICES=$(echo "$FILES_CHANGED" | grep -Eo '^src/(.*)-(.*)/' | sed -En "s/(src|\/)//pg")
DEPLOY_INFO=$'# If you want to avoid auto deploy, please the following deploy metadata\n\n[DeployServices]:';
if [[ "$DEPLOY_ALL" -ge 1 ]]; then
DEPLOY_INFO="$DEPLOY_INFO all";
elif [[ "$DEPLOY_SERVICES" != "" ]]; then
@jgdev
jgdev / promise-sequentially.js
Last active August 26, 2018 07:59
Run promises sequentially
const promise = n => new Promise((resolve) => setTimeout(() => {
console.log(n);
resolve(n);
}, (n * 1000)));
const sequence = (promises) => {
return new Promise((resolve, reject) => {
let results = [];
promises
.reduce((chain, promise) => {
@jgdev
jgdev / get_unused_port.sh
Created December 13, 2017 19:22
Get unused port on shell
#!/bin/sh
port=-1
get_unused_port()
{
while [ "$port" -eq "-1" ]
do
p="$(jot -r 1 4444 65000)"
r=$(nc -z 127.0.0.1 $p > /dev/null 2>&1 && echo "used")
import * as http from "http";
import * as https from "https";
import * as HttpError from "standard-http-error";
import { URL } from "url";
export default function makeRequest(url: string, options: any = {}): any {
if (!url) {
throw new Error("Invalid url");
}
return new Promise((resolve, reject) => {
@jgdev
jgdev / validate-document-id.js
Created September 18, 2017 14:54
Function to validate identity document - Dominican Republic - Javascript
function isValidDocument(document) {
if (!document) return false;
if (document.includes('-')) {
document = document.replace(/-/g, '');
}
let verificador = 0;
let digito = 0;
let digitoVerificador = 0;
let digitoImpar = 0;
let sumaPar = 0;
@jgdev
jgdev / HashMap.cpp
Created August 31, 2017 00:35
HashMap.cpp
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
using namespace std;
const int TABLE_SIZE = 128;
class HashEntry
{
public:
#include <iostream>
using namespace std;
template <typename T, int N>
int binarySearch(T(&array)[N], int toSearch) {
int start = 0;
int length = N - 1;
while (start <= length) {