Skip to content

Instantly share code, notes, and snippets.

View ucapistranmtz's full-sized avatar
🚀
Always Learning

Ulises Capistrán ucapistranmtz

🚀
Always Learning
View GitHub Profile
@ucapistranmtz
ucapistranmtz / retry.ts
Last active June 30, 2025 13:12
Retry logic with cli
const controller = new AbortController();
type RetryOptions = {
fetchOptons: RequestInit;
delayMs: number;
timeOutMs: number;
retries: number;
};
const fetchWithRetry = async (url: string, retryOptions: RetryOptions) => {
@ucapistranmtz
ucapistranmtz / errorUtils.ts
Last active May 18, 2025 14:47
Building a production-ready TypeScript API? Here's how I extract error details smartly from native JS errors, Axios, Zod/Joi validation, and more using a single function 👇 ✅ Supports: err.message, err.stack, err.name Axios-style errors: err.response.data.message Schema validation: err.details[]
const getErrorDetails = (err: any) => {
if (!err) return 'Unknown error';
const messages: string[] = [];
// Error name
if (err.name) messages.push(`Name: ${err.name}`);
//Native errors
if (err.message) messages.push(err.message);
@ucapistranmtz
ucapistranmtz / pineTree.js
Created May 17, 2025 17:33
Printing a colorful pine tree
/*
We should find a code to draw a pine tree.
like the o ne below
*
***
*****
*******
|||
*/
@ucapistranmtz
ucapistranmtz / basicFibonacci.js
Created May 17, 2025 16:32
Fibonacci approaches
const basicFibonacci =(n)=> {
//console.log('bassic fibonacci');
if(n<2) return n
return basicFibonacci(n-1)+ basicFibonacci(n-1);
};
module.exports = basicFibonacci;