Skip to content

Instantly share code, notes, and snippets.

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

Tanishq Kancharla tanishqkancharla

🏠
Working from home
View GitHub Profile
@tanishqkancharla
tanishqkancharla / logger.ts
Created July 6, 2025 18:14
ORPC Logging Middleware
const loggerMiddleware = os
.$context<{ req: Request }>()
.middleware(async ({ context, next, path }) => {
const start = Date.now();
const method = context.req.method;
const pathname = `/${path.join("/")}`;
try {
const result = await next({});
const duration = Date.now() - start;
@tanishqkancharla
tanishqkancharla / IndexedDbAdapter.ts
Created July 2, 2025 22:04
IndexedDb storage adapter for tuple-db
import { Codec } from "@repo/utils/codec";
import { deleteDB, IDBPDatabase, openDB } from "idb";
import { KeyValuePair, ScanStorageArgs, WriteOps } from "tuple-database";
import { decodeTuple, encodeTuple } from "tuple-database/helpers/codec";
import { AnySchema, Json, StorageApi } from "../types";
const version = 1;
const storeName = "tupledb";
@tanishqkancharla
tanishqkancharla / logger.ts
Created July 1, 2025 01:02
ORPC Logging Plugin
import { Context, ORPCError } from "@orpc/server";
import type {
StandardHandlerOptions,
StandardHandlerPlugin,
} from "@orpc/server/standard";
function formatNow() {
return new Date().toLocaleDateString("en-US", {
month: "short",
day: "numeric",
class ExpoSqliteTupleStorageApi implements AsyncTupleStorageApi {
private db = SQLite.openDatabase("app.db");
constructor() {}
async prepare() {
await this.db.execAsync(
[
{
sql: `
@tanishqkancharla
tanishqkancharla / localDb.ts
Created March 12, 2024 04:20
Tuple-db ORM
import { isFunction, isSymbol } from "lodash-es";
import type {
KeyValuePair,
ReadOnlyTupleDatabaseClientApi,
TupleTransactionApi,
} from "tuple-database";
import {
InMemoryTupleStorage,
TupleDatabase,
TupleDatabaseClient,
@tanishqkancharla
tanishqkancharla / AnimatePresence.tsx
Last active January 16, 2024 04:01
AnimatePresence in React Native
import { unionBy } from "lodash-es";
import React, { ReactElement, useEffect, useState } from "react";
import { Animated, useAnimatedValue } from "react-native";
function diffBy<T>(a: T[], b: T[], key: keyof T) {
const aKeys = a.map((item) => item[key]);
const bKeys = b.map((item) => item[key]);
const added = b.filter((item) => !aKeys.includes(item[key]));
const removed = a.filter((item) => !bKeys.includes(item[key]));