Skip to content

Instantly share code, notes, and snippets.

View Grubba27's full-sized avatar
:shipit:

Gabriel Grubba Grubba27

:shipit:
View GitHub Profile
@Grubba27
Grubba27 / proparoxitítona.ts
Created May 7, 2022 04:27
A simple typescript program to verify if the word is a portuguese proparoxitítona
type Reverse<A> =
`${A}` extends `${infer AH}${infer AT}`
? `${Reverse<AT>}${AH}` : A
type Digs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
type DigsNext<I = Digs, R = {}> =
I extends [infer Head, infer Next, ...infer Tail]
? DigsNext<[Next, ...Tail], R & Record<Head, Next>>
: { [K in keyof R]: R[K] }
@Grubba27
Grubba27 / fib_fat.ts
Created May 9, 2022 23:32
Fibonacci formula and Fatorial one made simple with TS types :D
type Reverse<A> =
`${A}` extends `${infer AH}${infer AT}`
? `${Reverse<AT>}${AH}` : A
type Digs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
type DigsNext<I = Digs, R = {}> =
I extends [infer Head, infer Next, ...infer Tail]
? DigsNext<[Next, ...Tail], R & Record<Head, Next>>
@Grubba27
Grubba27 / normal-calculator
Created May 23, 2022 01:14
Normal TS calculator made with pattern mathing
type Operations = 'sum' | 'sub' | 'mul' | 'div';
type RecursiveReturn = [number, (args: Array<number>, next?: Operations) => RecursiveReturn]
const calculator =
(operation: Operations, prev?: number) =>
(args: Array<number>, next?: Operations): RecursiveReturn => {
const nums = prev === undefined ? [...args] : [...args, prev];
const partial = nums
.reduce((prev: number, curr: number) => ({
['sum']: prev + curr,
@Grubba27
Grubba27 / range.ts
Created June 2, 2022 14:31
Range in typelevel
type GreaterThan<
T extends number,
U extends number,
C extends unknown[] = []
> =
T extends U
? false
: C['length'] extends T
? false
@Grubba27
Grubba27 / pub_sub.ts
Created July 24, 2022 22:39
typed pub sub or something like that
type A = {foo: string};
type B = {bar: number};
type Module = A & B;
type C = {something: () => string}
type Store = Module & C;
class Teste<S = Store> {
sub<T extends keyof S>(key: T, cb: (value: S[T]) => void): void {
}
pub<T extends keyof S>(obj: {[T in keyof Partial<S> ]: S[T]} ): void {
type Numeros = ['zero', 'um', 'dois', 'tres', 'quatro', 'cinco', 'seis', 'sete', 'oito', 'nove'];
type Dezenas = ['','','vinte', 'trinta', 'quarenta', 'cinquenta', 'sessenta', 'setenta', 'oitenta', 'noventa'];
type Cem = ['cem'];
type Centenas = ['cento', 'duzentos', 'trezentos', 'quatrocentos', 'quinhentos', 'seiscentos', 'setecentos', 'oitocentos', 'novecentos'];
type GetWords<Str extends string, Curr extends string = ''> =
Str extends `${infer L}${infer R}`
? L extends ' '
? Curr
: GetWords<R, `${Curr}${L}`>
@Grubba27
Grubba27 / factory_typed.ts
Last active February 22, 2023 02:07
try implementing
type Creator =
<Name extends string, Args, Response>
(name: Name, runner: (args: Args) => Response, subModule?: RCreator<Name, Args, Response>) =>
RCreator<Name, Args, Response>
const createModule: Creator = (name, runner, subModule) => {
return {
...subModule,
@Grubba27
Grubba27 / client.ts
Created September 15, 2022 18:57
Draft of evoved metheor methods
import type {Application} from './server'
const client = () => {
const call = <Args>(name: string, args: Args) => {
// impl....
}
return{
call
} as Application
}
@Grubba27
Grubba27 / Fizzbuzz.js
Created October 6, 2022 01:17
Impl of fizzbuzz
const l = [...Array(100).keys()];
const fizz = (n) => (n % 3 === 0 ? "Fizz" : "");
const buzz = (n) => (n % 5 === 0 ? "Buzz" : "");
const fizzBuzzSolver = (number) =>
`${fizz(number)}${buzz(number)}` || "Nenhum";
l.forEach((number) => console.log(`${number}: ${fizzBuzzSolver(number)}`));
@Grubba27
Grubba27 / this-example.js
Last active October 21, 2022 14:20
simple example of using this
function outer(props) {
const self = this;
self.outer = 'outer';
function inner(props, ctx) {
const self = this;
self.inner = 'inner';
ctx.outer = 'outer-malucao'
return {
inner: self.inner,
ctx: ctx.outer,