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

Mazha: A Reactive TypeScript Notebook

1. Core Objective & "North Star"

  • Objective: To provide a reactive notebook environment specifically designed for TypeScript, enabling users to create and manage notebooks programmatically, with a strong emphasis on type safety and developer experience.
  • "North Star" - Deep Project Integration: Mazha's primary differentiator is its deep, native integration with a user's existing TypeScript project environment. This is paramount.
    • tsconfig.json Adherence: Mazha's backend (for execution and module resolution) and frontend (for client-side LSP) will strictly respect the project's tsconfig.json, including paths, baseUrl, compilerOptions, jsxImportSource, etc., ensuring consistent behavior with the rest of the user's project.
  • Seamless Local Imports: Users can import modules, functions, types, and React components directly from their local project files (e.g., ./src/utils, ../components/MyWidget) into Mazha cells, with full t
Objective: To collaboratively build an extensive and deep understanding of a topic, project, problem, or any subject you wish to explore, starting with minimal initial information.
Your Role (LLM): Act as an Expert Inquisitor and Context Synthesizer. Your primary function is not to provide answers initially, but to ask insightful, targeted questions to systematically elicit all necessary information from me (the user). You are building a comprehensive knowledge base about the subject, piece by piece, driven by your questions.
Process:

Let me try a completely different approach then. Let's bypass Conform and use Neovim's built-in functions to run a formatter directly on the TypeScript code:

vim.api.nvim_create_user_command('FormatTSMarkdown', function()
  -- Save cursor position
  local cursor_pos = vim.api.nvim_win_get_cursor(0)
  local bufnr = vim.api.nvim_get_current_buf()
  
  -- Find TypeScript code blocks
  local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
-- Function to collect all diagnostic errors and copy them to clipboard
local function copy_errors_to_clipboard()
-- Get the current buffer number
local current_buf = vim.api.nvim_get_current_buf()
-- Get all diagnostics for the current buffer
local diagnostics = vim.diagnostic.get(current_buf)
-- Format each diagnostic into readable lines
local lines = {}
#!/usr/bin/env bun
import { access, mkdir, readdir, stat } from "node:fs/promises";
import { basename, dirname, extname, join, relative } from "node:path";
// ========================================
// Global Configuration
// Edit these values instead of passing command line args
// ========================================
const DEFAULT_CONFIG: SiteConfig = {
contentDir: './content',
@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);
@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 / 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 / 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 / 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
}