Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Rodriguez jonathanrodriguezs

View GitHub Profile
@jonathanrodriguezs
jonathanrodriguezs / gmail.pl
Last active Jun 27, 2020
Send email via Gmail SMTP (SSL)
View gmail.pl
#!/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',
View dictionary-password.py
#!usr/bin/python
import sys
import hashlib
pass_found = False
input_hash = sys.argv[1]
pass_doc = sys.argv[2]
try:
@jonathanrodriguezs
jonathanrodriguezs / powershell.js
Created Jun 21, 2020
Promisified powershell child process
View powershell.js
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 / prop-recursive.js
Created Jun 15, 2020
Access nested properties using recursion
View prop-recursive.js
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 / promise-race.js
Created Jun 15, 2020
Set a timeout in ms to resolve a promise
View promise-race.js
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 / groupBy.js
Last active Jun 21, 2020
Group by lodash's replica
View groupBy.js
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
}, {})
}
View Fecha.java
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);
You can’t perform that action at this time.