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 / get_url_params.ts
Created January 30, 2023 21:09
Get url params
type GetParams<
Text extends string,
Result extends string = ''
> =
Text extends `${ infer L }${ infer R }`
? L extends '/'
? Result
: GetParams<R, `${ Result }${ L }`>
: Result
@Grubba27
Grubba27 / concat.ts
Created January 30, 2023 20:41
concat until
type ConcatUntil
<
Text extends string,
Delimiter extends string,
Result extends string = ''
> =
Text extends `${infer L}${infer R}`
? L extends Delimiter
? Result
: ConcatUntil<R, `${Result}${L}` >
@Grubba27
Grubba27 / 2fa.svelte
Created November 29, 2022 23:47
2fa example
<script>
let twoFactor;
let isCorrect = true;
$: isCorrect
function maybeRight() {
console.log(twoFactor)
Math.random() > 0.5 ? isCorrect = true : isCorrect = false;
}
@Grubba27
Grubba27 / lambdaModule.ts
Created November 24, 2022 00:46
simple prof for lamda in runtime
const ARGUMENT_NAMES = /([^\s,]+)/g;
function stripeFunction(func: Function) {
const fnStr = func.toString()
const args = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
const body = fnStr.slice(fnStr.indexOf('{') + 1, fnStr.lastIndexOf('}'));
return {
args: args || [] as string[],
body: body
@Grubba27
Grubba27 / lambda.ts
Created November 24, 2022 00:31
general idea of creating runtime lambdas
const ARGUMENT_NAMES = /([^\s,]+)/g;
function stripeFunction(func: Function) {
const fnStr = func.toString()
const args = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
const body = fnStr.slice(fnStr.indexOf('{') + 1, fnStr.lastIndexOf('}'));
return {
args: args || [] as string[],
body: body
@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,
@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 / 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 / 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,
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}`>