Skip to content

Instantly share code, notes, and snippets.

View VitorLuizC's full-sized avatar

Vitor L Cavalcanti VitorLuizC

View GitHub Profile
@leomelzer
leomelzer / Dockerfile
Last active March 9, 2022 19:18
Install private NPM dependencies using git+ssh on Now. Based on https://zeit.co/blog/build-env to work around missing support for git+ssh dependencies in now@2 (https://github.com/zeit/now-builders/issues/49)
# This is a multi-stage build to not spill the contents of the deploy_key
FROM mhart/alpine-node:10 as base
# We need git and openssh to resolve `git+ssh` links in package.json
RUN apk update \
&& apk add git openssh
WORKDIR /usr/src
COPY package*.json ./
@karol-majewski
karol-majewski / fromEntries-with-literal-types.ts
Last active March 31, 2023 09:51
Type inference for literal types with Object.fromEntries
type Primitive =
| boolean
| number
| string
| bigint
| symbol
| null
| undefined;
type Narrowable =
{"lastUpload":"2019-10-22T22:27:38.860Z","extensionVersion":"v3.4.3"}
// funciona somente com v3.1.6, essa estrategia de end/continue
// era um backdoor para fazer recursao em types, recursao funcionava somente com interfaces
// antigamente pela resolucao de tipos ser lazyness e nao acabar fazendo o compiler cair
// potencialmente em um looping infinito na resolucao do tipo, por causa disto tem validacao
// no compiler agora e codigos nesse estilo sao barrados pelo compiler
type Init<T extends any[], TTail extends any[] = TailArray<T>> = CastArray<{
[K in keyof TTail]: T[keyof T & K];
}>
@zeusdeux
zeusdeux / Either.ts
Created September 4, 2018 08:54
Either monad in typescript
export type Either<L,R> = Left<L> | Right<R>
export class Left<L> {
constructor(private readonly value: L) {}
public getValue() {
return this.value
}
}
export class Right<R> {
@itacirgabral
itacirgabral / asyncAnimationFrame.js
Last active December 22, 2022 20:39
async await generator loop for requestAnimationFrame
async function* asyncAnimationFrame () {
const h = {}
h.promise = new Promise(r => h.resolve = r)
h.flipFrame = () => {
h.resolve()
h.promise = new Promise(r => h.resolve = r)
}
try {
while (true) {
h.idAF = requestAnimationFrame(h.flipFrame)
@zorrodg
zorrodg / LICENSE
Last active November 30, 2023 19:37
CLI Integration Test Helper
MIT License
Copyright © 2019 Andrés Zorro
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
const Implementation = { ... } || ( ... ) => { ... };
/**
* Fix some buggy module interoperability strategies.
* @example ```js
* const ModuleName = require('module-name');
* // Or
* const { default: ModuleName } = require('module-name');
* ```
* @param target
@lierdakil
lierdakil / example.ts
Last active September 19, 2022 13:28
An example of Functor in TypeScript. You can run this on https://www.typescriptlang.org/play/
interface Functor<T> {
map<U>(f: (x: T) => U): Functor<U>
}
class Box<T> implements Functor<T> {
value: T
constructor(x: T) {
this.value = x
}
map<U>(f: (x: T) => U): Box<U> {
@jevakallio
jevakallio / HorizontalPicker.js
Created December 14, 2017 12:06
React Native Horizontal Picker
// @flow
// https://twitter.com/jevakallio/status/941258932529614848
import React, { Component, type Node } from 'react';
import styled from 'styled-components/native';
import Touchable from 'react-native-platform-touchable';
import Carousel from 'react-native-snap-carousel';
// $FlowFixMe
import { LinearGradient } from 'expo';