Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Github Copilot Fallback geovanisouza92

🏠
Working from home
View GitHub Profile
@geovanisouza92
geovanisouza92 / async-functions.js
Last active Nov 7, 2019
You don't need bluebird / async
View async-functions.js
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));
}
View make.go
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 Sep 25, 2018
Async iterator for pagination
View main.js
class Token {
nextRange() {
return `${this._range}-`;
}
feed(response) {
this._range = response.headers.Range;
}
}
@geovanisouza92
geovanisouza92 / cartesian-product.benchmark.js
Last active Nov 7, 2019
Cartesian Product algo Benchmark
View cartesian-product.benchmark.js
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 Apr 3, 2019
A builder type where build() only appears after correct initalization
View builder.ts
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 };
View keybase.md

Keybase proof

I hereby claim:

  • I am geovanisouza92 on github.
  • I am geovanisouza92 (https://keybase.io/geovanisouza92) on keybase.
  • I have a public key ASCpolGtmdNixlFQCCB-CbnR2smOlL8WtGUTk7GFb5CMfgo

To claim this, I am signing this object:

@geovanisouza92
geovanisouza92 / README.md
Created Jun 22, 2018
Injeção de módulos com Webpack
View README.md

Uma forma simples de reduzir acoplamento modificando apenas a configuração de build.

Como a configuração é "apenas Javascript", fica fácil manipular, porém é importante tomar cuidado para não cair na situação do "na minha máquina funciona", pois cada ambiente pode gerar um bundle diferente. Testar é sempre importante.

Isso pode ser muito útil para injetar arquivos de configuração, implementação de features específicas (tracing, logging, metrics, error tracking, etc.) e até incluir módulos específicos de um ambiente, como suporte a source-map, por exemplo.

@geovanisouza92
geovanisouza92 / mapping.json
Created Dec 21, 2017
Remover acentos com TS
View mapping.json
{
"À": "A",
"Á": "A",
"Â": "A",
"Ã": "A",
"Ä": "A",
"Å": "A",
"Ấ": "A",
"Ắ": "A",
"Ẳ": "A",
@geovanisouza92
geovanisouza92 / strict-functions-causes-errors.ts
Last active Dec 14, 2017
--strictFunctionTypes generates errors with generic functions
View strict-functions-causes-errors.ts
type Direction = keyof IDirectionOptions;
interface IDirectionOptions {
"horizontal": { foo: number; };
"vertical": { bar: string; };
"diagonal": { baz: boolean; };
}
// This structure works