Skip to content

Instantly share code, notes, and snippets.

@sina-byn
sina-byn / image-opt-middleware.js
Last active June 26, 2024 15:04
express image optimization middleware
// code for https://medium.com/@sina-byn/code-an-express-middleware-to-optimize-your-images-c9225308e4ba
const { createReadStream } = require('fs');
const express = require('express');
const fs = require('fs/promises');
const sharp = require('sharp');
const path = require('path');
// * utils
const getContentType = fileName => {
const ext = path.extname(fileName).slice(1);
@sina-byn
sina-byn / useAxios.tsx
Last active September 25, 2022 09:31
A react custom hook used to perfrom GET requests using axios - capable of handling both single GET requests and simultaneous GET requests + other options
import axios from 'axios';
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
// types
type Entries = Entry[];
type Setter = Dispatch<SetStateAction<object>>;
type Params = { [key: string]: any };
interface Entry {
key: string;
url: string;