Skip to content

Instantly share code, notes, and snippets.

@vedantroy
vedantroy / gist:571d36c2767f3f570b865c528c0f9525
Created May 1, 2025 23:13
Save Rent Cafe Lease As Image
function findActivePageAndSaveCanvas() {
// Get all document pages
const pages = document.querySelectorAll('.document-page');
// Loop through all pages to find the active one (with a canvas)
for (let i = 0; i < pages.length; i++) {
const canvas = pages[i].querySelector('canvas');
// If this page has a canvas, it's active
if (canvas) {
console.log(`Active page found: Page ${i + 1}`);
// Save the canvas as an image
@vedantroy
vedantroy / demo.ts
Last active December 31, 2024 09:15
SQLite-backed key-value store with JS-like object manipulation and automatic JSON serialization.
import Database from 'better-sqlite3';
import { createDatabaseClient } from './proxy.ts';
// 1) Create an in-memory DB and your table(s).
const db = new Database(':memory:');
db.exec(`
CREATE TABLE users (
id TEXT PRIMARY KEY,
data JSON
);
lambda image: blur(color_jitter(random_crop(image))
@vedantroy
vedantroy / job_submission.bash
Created December 15, 2022 22:50
Some neat bash tricks
#! /bin/bash
set -euxo pipefail
job_file="cluster_jobs/${1}.py"
if [[ ! -f "${job_file}" ]]; then
echo "${job_file} not found"
exit 1
fi
RAY_ADDRESS=${RAY_ADDRESS:-""}
@vedantroy
vedantroy / rev_vit.py
Created September 12, 2022 10:24
Reversible VIT
from types import SimpleNamespace
import yahp as hp
import torch
from torch import nn
from torch.autograd import Function as Function
from einops import rearrange
from einops.layers.torch import Rearrange
# A one-file implementation of the reversible VIT architecture
"""run.py:"""
#!/usr/bin/env python
import os
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
def run(rank, size):
""" Distributed function to be implemented later. """
pass
@vedantroy
vedantroy / einsum.py
Created July 17, 2022 23:57
Einsum examples
import numpy as np
def single_matrix():
x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
I, J, K = x.shape
x_ein = np.einsum("ijk->ij", x)
x_loop = np.empty((I, J))
for i in range(I):
@vedantroy
vedantroy / model.py
Created June 29, 2022 07:18
Transformer
import torch
import torch.nn as nn
from params import params
# NOTATION:
# W_k = W (k as subscript)
# Wk = W (k as superscript)
class MultiHeadAttention(nn.Module):
@vedantroy
vedantroy / tailwind-styled.ts
Created June 10, 2022 18:00
Tailwind Styled Components-like API
import React from "react";
import { fromPairs } from "lodash-es";
import clsx from "clsx";
// This is my styled-components replacement
// Taken from:
// https://github.com/MathiasGilson/Tailwind-Styled-Component/blob/master/src/domElements.ts
const elementsArray: (keyof JSX.IntrinsicElements)[] = [
"a",
"abbr",