Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jonathanrodriguezs's full-sized avatar

Jonathan Rodriguez jonathanrodriguezs

View GitHub Profile
@jonathanrodriguezs
jonathanrodriguezs / promise-race.js
Created June 15, 2020 06:14
Set a timeout in ms to resolve a promise
function timeout(ms, promise) {
let timeoutID;
const timeoutPromise = new Promise((_, reject) => {
timeoutID = setTimeout(() => {
reject(Error(`Operation timed out after ${ms}ms`))
}, ms)
})
return Promise
.race([promise, timeoutPromise])
.finally(() => {
@jonathanrodriguezs
jonathanrodriguezs / prop-recursive.js
Created June 15, 2020 06:16
Access nested properties using recursion
const value = (obj, prop) => {
try {
const [property, ...rest] = prop.split(".")
return rest.length > 0
? findProp(obj[property], rest.join("."))
: obj[prop]
} catch {
return obj
}
}
@jonathanrodriguezs
jonathanrodriguezs / powershell.js
Created June 21, 2020 06:39
Promisified powershell child process
function powershell(commands) {
return new Promise(function (resolve, reject) {
const spawn = require("child_process").spawn
const child = spawn("powershell.exe", ["-Command", "-"])
const result = [], errors = []
child.stdout.on("data", data => {
result.push(data.toString())
})
@jonathanrodriguezs
jonathanrodriguezs / groupBy.js
Last active June 21, 2020 23:12
Group by lodash's replica
function groupped (list, param) {
return list.reduce((result, item) => {
let prop = item[param]
const hasProp = result.hasOwnProperty(prop)
if(hasProp) result[prop].push(item)
else result[prop] = [item]
return result
}, {})
}
#!usr/bin/python
import sys
import hashlib
pass_found = False
input_hash = sys.argv[1]
pass_doc = sys.argv[2]
try:
import java.util.Scanner;
class Fecha {
int dia;
int mes;
int ano;
protected int[] diasPorMes = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
protected int[] diasAcumulados = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
protected int[] diasAcumuladosEnBisiesto = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
Scanner scan = new Scanner(System.in);
@jonathanrodriguezs
jonathanrodriguezs / gmail.pl
Last active June 27, 2020 05:57
Send email via Gmail SMTP (SSL)
#!/usr/bin/perl
use strict;
use warnings;
use Email::Send::SMTP::Gmail;
my ($mail,$error) = Email::Send::SMTP::Gmail->new(
-layer => 'ssl',
-port => '465',
-smtp => 'smtp.gmail.com',