Skip to content

Instantly share code, notes, and snippets.

View victornpb's full-sized avatar
⌨️

Victor victornpb

⌨️
View GitHub Profile
/**
* Human readable elapsed or remaining time (example: 3 minutes ago)
* @param {Date|Number|String} date A Date object, timestamp or string parsable with Date.parse()
* @return {string} Human readable elapsed or remaining time
* @author github.com/victornpb
*/
function fromNow(date) {
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
@victornpb
victornpb / clone_all.sh
Last active March 31, 2021 04:29
Clone All repositories from User or Organization
#!/bin/bash
echo "-------------------------------"
echo " Clone all GitHub Repositories "
echo "-------------------------------"
#prompt for variables
printf "\nCreate a token here https://github.com/settings/tokens\nor leave it empty for public repositories\n\n"
read -s -p 'Personal Token (optional): ' GITHUB_TOKEN
printf "\n"
@victornpb
victornpb / sortBy.js
Last active January 18, 2021 01:16
Sort by field
function sortBy(arr, fields) {
if (typeof fields === 'string') fields = [fields];
function compareFn(a, b) {
return fields
.map(field => {
let dir = 1;
if (field[0] === "-") {
dir = -1;
field = field.substring(1);
}
@victornpb
victornpb / caracoroa.c
Created December 4, 2014 21:57
Joguinho do cara-coroa desenvolvido durante a aula 4-dec-2014 no curso de linguagem C do curso de robotica e automacao 2014 no UNICERP. por Victor B.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define CARA 1
#define COROA 2
int pontosJogador;
int pontosComputador;
/**
* Create a function that maps a value to a range
* @param {Number} inMin Input range minimun value
* @param {Number} inMax Input range maximun value
* @param {Number} outMin Output range minimun value
* @param {Number} outMax Output range maximun value
* @return {function} A function that converts a value
*
* @author Victor N. wwww.victorborges.com
* @see https://gist.github.com/victornpb/51b0c17241ea483dee2c3a20d0f710eb/
@victornpb
victornpb / frozen-task.js
Last active February 26, 2020 14:14
Bookmarklet to make frozen tasks more effortless
(() => {
if (window.MOD) return alert("Already running!");
window.MOD = true;
const doc = document;
doc.querySelector("#toggle-side-nav").click();
doc.querySelector("nav").style.position = "absolute";
const delay = async t => new Promise(r => setTimeout(r, t));
const wait4Elm = async selector => {
@victornpb
victornpb / Import-Export-Beanstalk-Enviroment-Variables.js
Last active February 20, 2020 18:46
Import/Export Beanstalk Enviroment Variables
(function() {
var html = `<div style="position: fixed; top: 50px; left: 50px; z-index: 99999999; background-color:black; color: white; padding: 5px;">
<div style="display: flex;">
READ:
<button class="readAsJsonBtn">as JSON</button>
<button class="readAsEnvBtn">as ENV</button>
WRITE:
<button class="writeFromJsonBtn">from JSON</button>
<button class="writeFromEnvBtn">from ENV</button>
<span style="flex-grow: 1;"></span>
@victornpb
victornpb / remove-outline-focus-ring.js
Last active February 6, 2020 00:32
Remove the focus outline ring when using mouse but keep it for keyboard users for a11y
/**
* Hide the uggly focus outline ring on UI elements for users using mouse
* as input device, but enable it as soon as the keyboard is being used.
* This is important for keyboard and a11y purposes.
* @author https://gist.github.com/victornpb/0aa4aba6e15a2f156a53a7ba995a432e
*/
(function () {
document.head.appendChild(document.createElement("style")).innerHTML =
"body.hide-focus-ring *:focus { outline: none !important; }";
@victornpb
victornpb / HideAddressBar.js
Created December 1, 2013 17:04
Hide the address bar on mobile devices.
/** Hide the address bar - vitim.us */
function hideAddressBar(){
setTimeout(function(){
if(scrollY) return;
scrollTo(scrollX, 1);
setTimeout(function()
if(scrollY==1)
scrollTo(scrollX, 0);
}, 1);
}, 1);
@victornpb
victornpb / zip.js
Created December 18, 2019 18:39
Zip file on nodeJS using subprocess
const path = require('path');
const { spawn } = require('child_process');
(async () => {
try {
await zip(path.resolve(__dirname, 'foo.js'), path.resolve(__dirname, 'bar.zip'));
console.log('OK');
} catch (err) {
console.error('Failed to zip!', err);