Skip to content

Instantly share code, notes, and snippets.

View devtin's full-sized avatar
💭
wondering...

Martin Rafael Gonzalez devtin

💭
wondering...
  • Keep Wondering, LLC
  • McKinney, TX
  • X @tin_r
View GitHub Profile
/**
* Pre-loads an image on the browser retrying in case of error.
* @param {String} src - Remote url
* @param {Number} [retries=3] - How many times to re-try in case of error
* @param {Number} [delay=300] - Amount of milliseconds to wait prior retrying in case of error.
* @return Promise.<HTMLElement> - Resolves the created image
* @throws {Error} - Once exhausted all `retries`, the last error thrown by the dom element
*/
export function preloadImage (src, { retries = 3, delay = 300 } = {}) {
import { explainSync as _explainSync, explain as _explain } from 'jsdoc-api'
import path from 'path'
import fs from 'fs'
import os from 'os'
const tmpDirHasLeadingUnderscore = () => /\/_/.test(os.tmpdir())
/**
* Quick fix for jsdoc-api issue#19
*
@devtin
devtin / wildcard-pattern.js
Last active January 24, 2020 00:39
Wildcard pattern finder
// As part of an technical screening interview I was requested to create the following function
/**
* Finds whether given `a` matches pattern `b`
*
* Pattern constrains:
* 1 <= length(a), length(b) <= 9e4
* '?' : Matches any single character.
* '*' : Matches any sequence of characters (including the empty sequence).
*
/**
*
* @parameter: {String} t - Given word
* @return: {Boolean} whether given word (`t`) is or not a palindrome.
*
* @see: https://en.wikipedia.org/wiki/Palindrome
*/
function isPalindrome (t) {
if (typeof t !== 'string' || t.length === 0) {
/**
* As part of a technical screening interview I was requested to create a function
* able to calculate the total score of a game after all of the given rounds were completed
* following the criteria below:
*
* The function receives an array of strings restricted to the following operation:
* Integer: Directly represents the number of points scored this round.
* +: The points scored this round are the sum of the last two valid round's points.
* D: The points scored this round are double the last valid round's points.
* C: The last valid round's points were invalid and should not be counted towards the total score or any future operations.
/**
* As part of a technical screening interview I was requested to create a function
* able to perform a binary search.
*
* @param {Number[]} arr - A sorted array
* @param {Number} k - Number to find
* @return {Number} index position where k was found in the array
*
* @see: https://en.wikipedia.org/wiki/Binary_search_algorithm
*/
/**
* As part of a technical on-site screening-interview I was requested to create a function
* able to find two numbers in array `arr` that added together would equal given number `k`.
*
* I initially did an approach equal to run the function below with the option `reduceIterations=false`.
*
* My interviewer asked if I had a better approach: honestly, not only I had a headache but also I was already screened
* remotely and was not expecting more coding review: especially on the spot. I don't know, first time interviewing
* in the US... The thing is, he suggested using a 'table hash' (first time I heard the term) to reduce iteration. At
* the beginning I did not understand him (probably due to my technical language barer) but then I realized he wanted
@devtin
devtin / mongo-clone
Last active January 6, 2022 14:15
mongoDb collection backup
#!/usr/bin/env bash
SRC_URI=<source-connection-uri>
SRC_DB=<source-database-name>
DST_URI=<destination-connection-uri>
DST_DB=<destination-database-name>
FLOW=1000
mongodump --archive --uri $SRC_URI --db $SRC_DB | mongorestore --archive --uri $DST_URI --db $DST_DB --numInsertionWorkersPerCollection=$FLOW
@devtin
devtin / cli regex extract
Created May 4, 2022 20:19
cli regex extract
perl -n -e'/(\d+) events processed!/ && print $1'
@devtin
devtin / .github
Last active May 20, 2022 15:10
github commands
#!/bin/bash
# prints remote github-url
function ghr () {
GITHUB_REMOTE=$(git config --get remote.origin.url)
if [ $? -eq 1 ]; then
echo "either not a github repo or remote not found 😙"
return 1
fi