Skip to content

Instantly share code, notes, and snippets.

View hariscs's full-sized avatar
🙂
Always Learning

Haris Shah hariscs

🙂
Always Learning
View GitHub Profile
@hariscs
hariscs / git_delete_all_branches.txt
Created April 16, 2024 10:25
Delete All the branches except a few
git branch | grep -v "develop" | grep -v "f/testing" | grep -v "main" | xargs git branch -D
@hariscs
hariscs / auth_middleware.ts
Last active March 2, 2024 16:31
HTTP only Cookie Auth Middleware
import { Request as ExpressRequest, Response, NextFunction } from 'express'
import jwt, { JwtPayload } from 'jsonwebtoken'
import { USER_SCHEMA } from '@/models/user_model'
import { log } from 'console'
interface User {
name?: string
email: string
password: string
}
@hariscs
hariscs / user_model.ts
Created March 2, 2024 13:06
Hash and Match Password in a Model
import mongoose, { Document, Schema } from 'mongoose'
import bcrypt from 'bcrypt'
interface IUserSchema extends Document {
name?: string
email: string
password: string
match_password: (password: string) => Promise<boolean>
}
@hariscs
hariscs / zod_schema_validation_middleware.ts
Created February 25, 2024 17:48
Schema Validation Using Zod
import { Request, Response, NextFunction } from 'express'
import { z } from 'zod'
export function validate_schema(schema: z.AnyZodObject) {
return (req: Request, res: Response, next: NextFunction) => {
try {
schema.parse(req.body)
next()
} catch (error) {
if (error instanceof z.ZodError) {
@hariscs
hariscs / center.css
Created December 6, 2023 07:11
Center an absolutely positioned element in a div
.center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}