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 / 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 / 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 / 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 / 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 / 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 / fn.ts
Created February 17, 2023 21:52
arrow vs function declaration
const Module = {
value: 0,
someFn: () => {
return this.value;
},
okayFn() {
return this.value;
}
}
class Module2 {
@Grubba27
Grubba27 / godocs.go
Last active February 22, 2023 05:00
new godocs in the terminal (TUI)
package main
import (
"fmt"
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/PuerkitoBio/goquery"
"github.com/charmbracelet/glamour"
"log"
"net/http"
"os"
@Grubba27
Grubba27 / isAsyncCall.js
Last active March 7, 2023 19:00
Meteor 3 know if call is async or not
// server/server.js
Meteor.methods({
'someMethod': async function() {
if (Meteor.isAsyncCall()) {
// here is a when a callAsync
} else {
// when is just call
}
return Meteor.isCallAsync();
})
@Grubba27
Grubba27 / suspensify.ts
Last active March 13, 2023 21:31
making any promise suspendable in react.
const cacheMap = new Map<string, Entry>()
interface Entry {
deps: EJSON[]
promise: Promise<unknown>
result?: unknown // here is what your T should be
error?: unknown
}
// you can use isEqual from lodash in this case
function arraysEqual<T>(a: T[], b: T[]): boolean {
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import {
useReducer,
useMemo,
useEffect,
Reducer,
DependencyList,
useRef,
} from 'react';