Skip to content

Instantly share code, notes, and snippets.

View saiashirwad's full-sized avatar
🏠
Working from home

texoport saiashirwad

🏠
Working from home
View GitHub Profile
@saiashirwad
saiashirwad / xmllang.ts
Last active October 27, 2024 12:11
xmllang v0
export type merge<O> = { [K in keyof O]: O[K] } & {};
type Type = "number" | "string";
type concatStrings<arr extends any[], acc extends string = ""> = arr extends []
? acc
: arr extends [infer x extends string]
? concatStrings<[], `${acc}${x}`>
: arr extends [infer x extends string, ...infer xs extends string[]]
? concatStrings<xs, `${acc}${x}`>
@saiashirwad
saiashirwad / colors.lua
Created December 18, 2024 13:24
make neovim use terminal's colors
vim.opt.termguicolors = false
vim.env.TERM = "xterm-256color"
vim.cmd("colorscheme default")
vim.cmd("highlight Normal ctermbg=NONE guibg=NONE")
vim.cmd("highlight NonText ctermbg=NONE guibg=NONE")
vim.cmd("highlight SignColumn ctermbg=NONE guibg=NONE")
vim.cmd("highlight VertSplit ctermbg=NONE guibg=NONE")
@saiashirwad
saiashirwad / either.ts
Last active December 30, 2024 17:24
A minimal Either in Typescript, with generator syntax
export type Either<R, L> = Left<L, R> | Right<R, L>
export class Left<L, R = never> {
readonly _tag = "Left"
constructor(public readonly left: L) {}
*[Symbol.iterator](): Generator<Either<R, L>, R, any> {
return yield this
}
}
@saiashirwad
saiashirwad / prisma-to-effect-schema-complete.ts
Last active March 19, 2025 03:02
A prisma -> effect schema codegen script for a very opinionated setup using the parserator library
// this is incredibly hacky, but it works great for me
// for this to work, i have a file called json-types.ts that contains a bunch of exported interfaces, one for each of
// the tables i have that have any JSON fields. json-types.ts should only have Effect Schema imports, like so:
// import { Schema1 } from '../../somewhere'
// import ...
// %
// ^ that is essential lol. that tells the script that the imports section is over
@saiashirwad
saiashirwad / hkt.ts
Last active January 9, 2025 10:30
minimal hkt in ts
export type Fn = (...x: never[]) => unknown
export declare const _: unique symbol
export type _ = typeof _
export declare abstract class Kind<F extends Fn = Fn> {
abstract readonly [_]: unknown
f: F
}
@saiashirwad
saiashirwad / prisma-codegen.ts
Created January 16, 2025 09:47
cursed prisma codegen
import ts from "typescript";
import {
Parser,
alphabet,
char,
digit,
many0,
many1,
optional,
or,
@saiashirwad
saiashirwad / finger_tree.ts
Created January 25, 2025 19:25
a finger tree in type level ts :)
type buildTuple<L extends number, T extends any[] = []> = T["length"] extends L
? T
: buildTuple<L, [...T, unknown]>;
type addTuple<A extends unknown[], B extends unknown[]> = [
...A,
...B,
]["length"] &
number;
type subTuple<A extends unknown[], B extends unknown[]> = A extends [
@saiashirwad
saiashirwad / example.ts
Created February 1, 2025 13:54
webstorm typescript tuple arithmetic
type buildTuple<
n extends number,
acc extends any[] = [],
> = acc["length"] extends n ? acc : buildTuple<n, [...acc, 0]>;
type add<a extends number, b extends number> = [
...buildTuple<a>,
...buildTuple<b>,
]["length"] &
number;
@saiashirwad
saiashirwad / signals.ts
Created February 14, 2025 20:56
ez signals in ts
let activeEffect: (() => void) | null = null;
export function signal<T>(initialValue: T) {
let value = initialValue;
const subscribers = new Set<() => void>();
return {
get(): T {
if (activeEffect) {
subscribers.add(activeEffect);