Skip to content

Instantly share code, notes, and snippets.

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

Harman Pannu ihpannu

🏠
Working from home
View GitHub Profile
@fnky
fnky / login.tsx
Last active December 15, 2023 19:56
Remix Form validation with zod
import { json, ActionFunction, useActionData, Form } from "remix";
import { z } from "zod";
// This type infer errors from a ZodType, as produced by `flatten()` of a parsed schema.
type inferSafeParseErrors<T extends z.ZodType<any, any, any>, U = string> = {
formErrors: U[];
fieldErrors: {
[P in keyof z.infer<T>]?: U[];
};
};
@tchak
tchak / remix-refetch.tsx
Last active November 5, 2022 05:10
Remix Refetch
import { useCallback, useEffect, useState, useRef } from 'react';
import { useLocation } from 'react-router-dom';
import type { ActionFunction } from 'remix';
import { redirect, useSubmit } from 'remix';
export const action: ActionFunction = async ({ request }) => {
const body = new URLSearchParams(await request.text());
return redirect(String(body.get('path')));
};
@daniellwdb
daniellwdb / cacheMiddleware.ts
Last active June 14, 2022 17:25
Prisma cache middleware
import type { Prisma } from "@prisma/client"
import { redis } from "../redis"
type CacheMiddlewareOptions = {
model: Prisma.ModelName
action: Prisma.PrismaAction
keys?: string[]
defaultValues?: Record<string, unknown>
ttlInSeconds: number
}
@ghinda
ghinda / object-to-form-data.js
Last active March 30, 2024 18:51
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@paulallies
paulallies / gist:0052fab554b14bbfa3ef
Last active November 12, 2023 23:00
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin <branch-name>