Skip to content

Instantly share code, notes, and snippets.

View tonivj5's full-sized avatar
👨‍🎓
Studying...

Toni Villena tonivj5

👨‍🎓
Studying...
View GitHub Profile
@fabiospampinato
fabiospampinato / lag_bar.tsx
Created April 23, 2023 19:56
My lag bar implementation for Voby
/* IMPORT */
import {$, $$, useEffect, useInterval} from 'voby';
/* STYLE */
css`
:root {
--lag-bar-color-bg: var(--color-black-bg);
@Andarist
Andarist / gist:0294519c570a52fb14f4cdd3d589c880
Created February 23, 2023 08:49
Reverse mapped types brain dump
mapped types syntax and intro
https://www.typescriptlang.org/play?#code/C4TwDgpgBA8gRgKygXigbwFBW1AZge3wC4oBnYAJwEsA7AcwBosc4BDCkmgVwFs4IKGAL4YMoSFACSAEwg1gVUAB4AKgD4U6ZtgDaAaSi0oAawgh8uKCoC6JFfuvDR46AGVWPaKhlyFy+AhqGAD0wTgAegD8omLg0AAKFPg8VKRUuCCqGqiYOFD6hjQmZhZWtlAAFACUKBqJyakQqg5BIrES9SlpuFQQ0pqdqemZAUGhEdEYsgDGADbs0NP4NORQFGDTJIPdvdKiSyvAeFzAXBReaxsAdGwU1SFheU-PUFGiuCdnEFfAABZyFQqADdWLMasgNLkcCDZtooOM3kIqkA
a tweet that prompted the idea for the talk
https://twitter.com/kentcdodds/status/1608187990215655424
but since this isn't possible with satisfies (it doesn't participate in inference, in an example like that it only provides contextual types) the answer was to use a function with a reverse mapped type
@lukeed
lukeed / cron-human.ts
Last active May 7, 2023 18:53
cron syntax & human readable output — https://t.co/CBThaezwzC
// https://crontab.guru/
// https://www.typescriptlang.org/play?ts=4.9.5#code/C4TwDgpgBAwgSgeQHJQLxQAYBIDe9kB0AogB5gBOEAzlQJYD2AdgL5S75LFmU0Mtt5EnUhWp0mrdkK6jeEgRxk9xLDAG4AUAHotUPVAB6Afg0bQkKABVqwAIxpY0gBIBXALYBDRgB4ARAGYABigATigAKgiI3wA+TR19QxMzcGhrKmAAJgdFV08fX0iwyJLY+N19Y1NzNJt-HOd3Lz9wrXriqPCy7Qq9KpSLdOAAFgbCPObCtoitUZLouJ7E-pqrGwBWMc4Jgtb6+dLFhMrk1aGANi2CHZaZ-c7u477T1LWMgHYrm99bTdbsg6PXpJaqvIYADi+TV2UXuXSOwJWYJsYXQuWhtxK00O5WWL0GNlswTRjXymKg+y0AKBeNBBIytnsJPGGMKsJm2WGNJOdNqDOyzO2rOCmUpAOxs25z15bzs9UF11ZYVFHLuUC5CNpAz5dlGCu+rV+M0ukX2UpB2tlRv1rIOFIWuJ5SwAtK6AMYuYCu52mAAmEDdABsPJQoIwPG5qGAPG7oBwoDgNHoIGR6ORgFBViJlHwHABycJ5qAAHzD7gARhByCXMK1cIwK1XmOpTMnU+nM68bpYoCngBBGL6qI5kDEHEnElZeyR+4Ph9gcLRGAAzKtQACykkXK7XTi3S9X1YAIpuBAe1+vT7hz8eAOrNieTqBGKy0SPeJwAGnXY77A6HmDXju1Y9n+c5QBk5BLgA5g+T6JC+R4eCA3iXp+UAnuhR63r+M7-vOQGHhh06zgBkEwXB8EIcRYEAb4vhQI+VH6C+lhMcxUAAFyATglisEwAhHpRHHcYwEAAG5Vuxk6iRJUlUbJknkJoE4JN6jETmcb4QB+9AuOQ6HrkunoQGO6BMUZDb9iR+FQAWRbSS+Th6dWtHDvZegvnmcnkCAUBuMZ-ZFgk8wAPpQOFoXSdxzn6TZ4ELjeUBOPFAENm4
@shicks
shicks / index.md
Last active August 14, 2023 03:41
My TypeScript generics wishlist

Background: TypeScript Generics Wishlist

There are a handful of issues that are both separate features, but are also loosely related in that they speak to certain problematic aspects of generics today. In particular,

  • [#7061] (specifically later in the thread) asks for a way to assign a private alias to a complex typed derived from the actual type parameters, usable from within the class/function signature. There are suggestions to use namespaces and other hacks, along with explanations of why <T, U extends Foo<T> = Foo<T>> is insufficient.
  • [#26242] and [#16597] both pertain to partial inference of type parameters. The rough summary is that you can write ``, but there's no way to explicitly specify T and still get inference on `U`. If you
@steveruizok
steveruizok / cache.ts
Last active March 31, 2023 14:43
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}

Variables

const shade = 100;
type Shade = 100;

Functions

@avallete
avallete / prisma-transactions-benchmark.ts
Created April 28, 2022 14:06
Prisma transactions benchmark 3.13.0
import { prisma } from "~/config/prisma";
async function executeWithoutTransaction(data: Array<{ name: string }>) {
return await Promise.all(
data.map((d) => prisma.projects.create({ data: d }))
);
}
async function executeWithArrayTransaction(data: Array<{ name: string }>) {
return await prisma.$transaction(
@conartist6
conartist6 / json-parser.js
Last active January 17, 2023 17:33
A human-friendly json parser with parserate
import parserate from '@iter-tools/parserate';
const t = {
token: (value) => ({ type: 'token', value }),
literal: (value) => ({ type: 'literal', value }),
};
const escapes = {
'"': '"',
'\\': '\\',
@dragomirtitian
dragomirtitian / findings.md
Last active November 27, 2023 22:39
`isolatedDeclarations` findings

A few findings from experimenting with isolated declarations:

New required type annotations

Exported variables

Exported variables will need an explicit type annotation (✅ implemented).

export const c1: 1 = 1; // ✔ ok, is explicit