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 / 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));
}
/* eslint-disable @typescript-eslint/no-non-null-assertion */
type Job = {
id: number;
code: string;
name: string;
jobType: string;
status: string;
publicationType: string;
recruiterId: number;

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 / 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');
@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.

@geovanisouza92
geovanisouza92 / main.js
Last active April 24, 2020 14:42
Reactive expression evaluator
import {run} from '@cycle/xstream-run'
import {makeDOMDriver, div, input, button, label} from '@cycle/dom'
import {makeLocalStorageDriver} from 'cyclejs-storage'
import Collection from '@cycle/collection'
import xs from 'xstream'
import debounce from 'xstream/extra/debounce'
import dropRepeats from 'xstream/extra/dropRepeats'
import pairwise from 'xstream/extra/pairwise'
import delay from 'xstream/extra/delay'
import concat from 'xstream/extra/concat'
@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())) { } })
@geovanisouza92
geovanisouza92 / builder.ts
Last active April 3, 2019 11:49
A builder type where build() only appears after correct initalization
interface Buildable<T> {
build(): T;
}
type HasSawThickness = { sawThickness: number };
type HasDirection = { direction: "horizontal" | "vertical" };
type HasWidth = { width: number };
type HasHeight = { height: number };
type HasPhase = { phase: number };