Skip to content

Instantly share code, notes, and snippets.

View PuruVJ's full-sized avatar
🏠
I'm just a simple man trying to quit Vim

Puru Vijay PuruVJ

🏠
I'm just a simple man trying to quit Vim
View GitHub Profile
@PuruVJ
PuruVJ / svelte-compiler-sizes.json
Created June 8, 2024 15:07
All the svelte compiler sizes from v3 onwards, fully bundled with rollup and esbuild
{
"3.0.0": "784.72kb",
"3.0.0-alpha1": "763.83kb",
"3.0.0-alpha10": "789.48kb",
"3.0.0-alpha11": "789.48kb",
"3.0.0-alpha12": "789.48kb",
"3.0.0-alpha13": "788.25kb",
"3.0.0-alpha14": "787.04kb",
"3.0.0-alpha15": "787.04kb",
"3.0.0-alpha16": "787.03kb",
@PuruVJ
PuruVJ / simplify_debt.ts
Last active November 8, 2023 12:44
How to simplify debt among a bunch of users within a group
class Ledger {
users = new Set<string>(); // Holds unique users
balances: Record<string, number> = {}; // Balance of each user
transactions: Record<`${string}:${string}`, number> = {}; // person1:person2 -> amount
simplified = false;
#results: Record<
'simplified' | 'non_simplified',
{
payer_user_id: string;
import { FormError } from '$lib/errors.js';
import { db } from '$lib/server/db.js';
import { GROUP_QUERY } from '$lib/server/queries/group.query.js';
import {
expenses_table,
group_members_table,
ledger_table,
users_table,
} from '$lib/server/schema.js';
import { listify_names, sum_arr } from '$lib/utils.js';
@PuruVJ
PuruVJ / vite-css-inline-plugin.ts
Last active September 19, 2022 11:05
Rollup plugin implementing Vite's CSS Modules, and inline functionality. No preprocessors
// @ts-check
import { dataToEsm } from '@rollup/pluginutils';
import fs from 'fs';
import lightningcss from 'lightningcss';
import { resolve } from 'path';
/** @type {() => import('rollup').Plugin} */
export const processCSS = () => {
/** @type {Map<string, import('lightningcss').TransformResult>} */
const idMap = new Map();
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
@PuruVJ
PuruVJ / Component.svelte
Last active August 1, 2021 12:36
Interval as a Svelte Store
<script>
import { createIntervalStore } from './interval.store.ts'
// Create interval of 6 seconds
const interval = createIntervalStore(6000);
$: $interval, doSomething();
</script>
import { useAtom } from 'jotai';
import { useEffect, useLayoutEffect } from 'preact/hooks';
import { themeAtom } from '__/stores/theme.store';
type Theme = 'light' | 'dark';
// This is needed here
let isFirstUpdate = true;
const localValue = localStorage.getItem<Theme>('theme:type');
@PuruVJ
PuruVJ / jslike.code-snippets
Created March 4, 2021 04:00 — forked from kourge/jslike.code-snippets
a VS Code snippet for typing in JS imports module-first, like the order in Python
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
"Named import": {
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"prefix": "from",
@PuruVJ
PuruVJ / avatar.tsx
Last active September 3, 2020 08:46
import { h } from "@stencil/core";
import { IUser } from "../interfaces/user.interface";
export const UserAvatar = ({ user, size = 36 }: {user: IUser, size: number}) => {
const {name, luminosity, name} = user;
const [r, g, b] = themeColor
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
@PuruVJ
PuruVJ / helmet-example.tsx
Last active April 18, 2020 17:42
Helmet Usage
import { Component, Prop, h } from '@stencil/core';
import Helmet from "/path/to/helmet.tsx";
@Component({
tag: 'my-first-component',
})
export class MyComponent {
// Indicate that name should be a public property on the component
@Prop() name: string;