Skip to content

Instantly share code, notes, and snippets.

View n370's full-sized avatar

Dylson Valente Neto n370

View GitHub Profile
@n370
n370 / useless_reset.sh
Created July 5, 2023 15:41
useless_reset.sh
function hardreset() { \
git reset --hard $(git log --skip=$(expr $1 - 1) -1 --format=%h) \
}
// @err {string} - Optional error message.
function fake(err) {
return new Promise((resolve, reject) => {
const msg = prompt('Cancel to simulate an API failure or add a message and Confirm to simulate a successful call')
if (!msg) {
return reject(err)
}
resolve(msg)
})
}
@n370
n370 / recipe.md
Last active April 30, 2021 16:50
Break down PDF document pages into multiple JPEG/PNG images

To convert pdf to image files use following commands:

For PNG gs -sDEVICE=png16m -dTextAlphaBits=4 -r300 -o a.png a.pdf

For JPG gs -sDEVICE=jpeg -dTextAlphaBits=4 -r300 -o a.jpg a.pdf

If you have multiple pages add to name %03d gs -o a%03d.jpg a.pdf

@n370
n370 / openconnect.md
Created June 24, 2020 20:54 — forked from moklett/openconnect.md
OpenConnect VPN on Mac OS X

Unfortunately, the Cisco AnyConnect client for Mac conflicts with Pow. And by "conflicts", I mean it causes a grey-screen-of-death kernel panic anytime you connect to the VPN and Pow is installed.

As an alternative, there is OpenConnect, a command-line client for Cisco's AnyConnect SSL VPN.

Here's how to get it set up on Mac OS X:

  1. OpenConnect can be installed via homebrew:

     brew update
    

brew install openconnect

@n370
n370 / async.js
Last active December 8, 2018 17:49
async function example
async function myAsyncFuntion() {
try {
const ok = await (() => new Promise((resolve, reject) => {
setTimeout(() => {
const luckyEnough = Math.round(Math.random() * 10) % 2 === 0;
if (luckyEnough) {
resolve('ok');
} else {
reject('err');
}
@n370
n370 / eventos.js
Last active October 30, 2018 01:55
Observables como abstracción ideal para desarrollar aplicaciones asíncronas en JavaScript
window.addEventListener('click', function (e) {
// Haz algo cuando se haga un click
});
setInterval(function () {
// Haz algo a cada segundo
}, 1000);
var ajax = new XMLHttpRequest();
ajax.addEventListener('load' function (e) {
@n370
n370 / async-series.js
Last active July 23, 2018 18:59
A naive example on how to schedule the execution in series of a list of async tasks.
const a = [];
a.push(() => setTimeout(() => { console.log('a'); a.shift(); a.length && a[0]();}, 1000))
a.push(() => setTimeout(() => { console.log('b'); a.shift(); a.length && a[0]();}, 1000))
a.push(() => setTimeout(() => { console.log('c'); a.shift(); a.length && a[0]();}, 1000))
a.push(() => setTimeout(() => { console.log('d'); a.shift(); a.length && a[0]();}, 1000))
a.push(() => setTimeout(() => { console.log('e'); a.shift(); a.length && a[0]();}, 1000))
a[0]();
@n370
n370 / remova-paywall.js
Created June 4, 2018 16:47
Script sujo e rápido para remover o paywall "Exclusivo para assinantes" do jornal O Globo online.
// Script sujo e rápido para remover o paywall "Exclusivo para assinantes" do jornal O Globo online.
// (1) Abra o console javascript do seu navegador utilizando a tecla F12.
// (2) Copie/Cole o bloco de código abaixo e pressione enter.
// (3) Leia o artigo!
(function () {
[].forEach.call(document.querySelectorAll('iframe'), function (node) { node.parentElement.removeChild(node); });
document.querySelector('#barreiraRegisterExclusiva').parentElement.removeChild(document.querySelector('#barreiraRegisterExclusiva'));
document.querySelector('link[href="https://static.infoglobo.com.br/paywall/register-piano/v2/styles/styles.css"]').parentElement.removeChild(document.querySelector('link[href="https://static.infoglobo.com.br/paywall/register-piano/v2/styles/styles.css"]'));
})()
@n370
n370 / trace.sh
Last active April 9, 2017 18:04
Convert all images inside a given folder from coloured to grayscale, tweak it's black and white dither levels and trace it to a SVG vector file.
#!/bin/bash
for f in *.jpg; do convert $f -colorspace gray -channel Gray -level 10,80% -brightness-contrast 10x90% -channel All -threshold 20 bmp:- | potrace -s - -o $f.svg ; done
# Based on https://gist.github.com/fernandoaleman/5083680
# Start the old vagrant
$ vagrant init ubuntu_saucy
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on