Skip to content

Instantly share code, notes, and snippets.

View geovanisouza92's full-sized avatar
🏠
Working from home

Geo geovanisouza92

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am geovanisouza92 on github.
  • I am geovanisouza92 (https://keybase.io/geovanisouza92) on keybase.
  • I have a public key whose fingerprint is 8B5C C25C D7BC 4E02 EF4D 1C58 2BD4 9AD7 EF5B 8C6A

To claim this, I am signing this object:

@geovanisouza92
geovanisouza92 / login-form.js
Created February 6, 2022 21:44
Ask user confirmation before exit page when react-hook-form is dirty
export function LoginForm() {
const { register, handleSubmit, formState: { isDirty } } = useForm();
useBeforeUnload((event) => {
if (isDirty) event.preventDefault();
});
const login = (data) => console.log(data);
return (
@geovanisouza92
geovanisouza92 / express-passport.js
Last active February 6, 2022 18:50
Express with Passport (local, facebook, google, jwt)
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
const FacebookStrategy = require('passport-facebook');
const GoogleStrategy = require('passport-google-oidc');
const { MultiSamlStrategy } = require('passport-saml');

Nesse modelo, as atualizações são transmitidas por websockets (socket.io) e focadas nas abas/janelas dos usuários da mesma empresa.

@geovanisouza92
geovanisouza92 / _notes.md
Last active February 6, 2022 17:55
Prefetch de dados SSR com react-query

Vantagem: a página é carregada já com dados, logo, se o usuário está com uma máquina mais modesta ou internet mais lenta, vai evitar loading/spinner.

/* eslint-disable @typescript-eslint/no-non-null-assertion */
type Job = {
id: number;
code: string;
name: string;
jobType: string;
status: string;
publicationType: string;
recruiterId: number;
@geovanisouza92
geovanisouza92 / async-functions.js
Last active September 28, 2022 11:18
You don't need bluebird / async
async function forEachSerial(cb, arr) {
await arr.reduce(async (prevPromise, value) => {
await prevPromise;
return cb(value);
}, Promise.resolve());
}
async function forEachParallel(cb, arr) {
await Promise.all(arr.map(cb));
}
@geovanisouza92
geovanisouza92 / make.go
Created September 25, 2018 15:22
Go tasks
package main
import (
"github.com/geovanisouza92/go-tasks"
"github.com/geovanisouza92/go-tasks/vcs/git"
"github.com/geovanisouza92/go-tasks/build/docker"
"github.com/geovanisouza92/go-tasks/deploy/kubernetes"
)
func main() {
@geovanisouza92
geovanisouza92 / main.js
Last active September 25, 2018 14:36
Async iterator for pagination
class Token {
nextRange() {
return `${this._range}-`;
}
feed(response) {
this._range = response.headers.Range;
}
}
@geovanisouza92
geovanisouza92 / cartesian-product.benchmark.js
Last active November 7, 2019 16:15
Cartesian Product algo Benchmark
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const A = Array(3).fill(null).map((_, index) => index + 1);
const B = A.map((a) => [a, a * -1]);
suite
.add('cartesianProduct_gen', function () { for (const _ of cartesianProduct_gen(B.slice())) { } })
.add('cartesianProduct_loop', function () { for (const _ of cartesianProduct_loop(...B.slice())) { } })
.add('cartesianProduct_genLoop', function () { for (const _ of cartesianProduct_genLoop(B.slice())) { } })