Skip to content

Instantly share code, notes, and snippets.

View David200197's full-sized avatar

David David200197

View GitHub Profile
@David200197
David200197 / mock-axios.ts
Last active August 8, 2023 05:35 — forked from cowboy/mock-axios.js
axios mocking via interceptors
import axios, { InternalAxiosRequestConfig } from 'axios'
type MockData = {
[x: string]: any
}
class MockError extends Error {
mockData?: MockData
config?: InternalAxiosRequestConfig<any>
code?: number
@David200197
David200197 / start-ngrok.mjs
Last active August 25, 2023 16:16
Auto Reconnect Ngrok with Telegram Notification
/**
* npm install axios dotenv ngrok
* or
* yarn add axios dotenv ngrok
*/
import axios from 'axios'
import dotenv from 'dotenv'
import ngrok from 'ngrok'
dotenv.config()
@David200197
David200197 / paginator.ts
Last active May 30, 2024 21:07
Helper Paginator
type Options = {
page: number
perPage: number
}
export class Paginator {
private page: number
private perPage: number
constructor(readonly options: Options) {
Object.assign(this, options)
// Inspirado en el video de Bettatech https://www.youtube.com/watch?v=K--Lmy8qUCQ
// Esta es mi propia solución sobre una máquina de estado pero eliminando los posibles problemas referentes al consumo de memoria
interface DisconnectSocket {
connect(): ConnectSocket;
}
interface ConnectSocket {
emit(event: string): void;
}
@David200197
David200197 / authentication-1.controller.ts
Created October 16, 2023 23:27 — forked from jengel3/authentication-1.controller.ts
NestJS - Implementing Access & Refresh Token Authentication
// app/modules/authentication/authentication.controller.ts
import { Body, Controller, Post } from '@nestjs/common'
import { RegisterRequest } from './requests'
import { User } from '../../modules/user'
import { UsersService } from '../users/users.service'
@David200197
David200197 / is-deeply-equal.ts
Last active December 20, 2023 19:22 — forked from jsdevtom/deep-equals.ts
fast deep equals in TypeScript
const isArray = Array.isArray;
const keyList = Object.keys;
const hasProp = Object.prototype.hasOwnProperty;
export const isDeeplyEqual = <T = any>(a: T, b: T): boolean => {
if (a === b) return true;
if (typeof a === 'function' && typeof b === 'function') return true;
if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
return a !== a && b !== b;
@David200197
David200197 / decorator_in_vite.md
Last active August 9, 2024 01:28
Using decorators in vite apps

Step - 1: install reflect-metadata

npm install reflect-metadata
pnpm add reflect-metadata
yarn add reflect-metadata
@David200197
David200197 / README.md
Created February 7, 2024 01:10 — forked from backendi/README.md
Ejecutar Python desde Node.js

Ejecutar un script de Python desde Node.js

Código que acompaña al video Ejecutar Python desde Node.js

Descripción

Script de Node.js que ejecuta un script de Python. script_node.js invoca a script_python.py como un subproceso utilizando la función spawn. Se establece una comunicación mediante stdin/stdout donde script_node.js envía un texto simple a script_python.py

Pre-requisitos

@David200197
David200197 / randomInt.ts
Last active August 9, 2024 16:58 — forked from rodrigograca31/randomInt.ts
Random Integer generator (Typescript)
/**
* Generates a random integer between min and max (inclusive)
* @param {number} min
* @param {number} max
* @returns randomly generated integer
*/
const randomInt = (min: number, max: number): number => {
return Math.floor(Math.random() * (max - min + 1) + min);
};