Skip to content

Instantly share code, notes, and snippets.

View jlescalonap's full-sized avatar

Jose Luis Escalona jlescalonap

  • Tuquequesoft
  • Porto Velho, RO. Brasil.
  • 02:21 (UTC -04:00)
  • X @BrlessKoin
View GitHub Profile
@jlescalonap
jlescalonap / validation-action.js
Created February 29, 2024 16:39
Ejemplo de la modificación del validation action, es decir si es error, o un simple warn.
db.runCommand({
collMod: 'posts',
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'text', 'creator', 'comments'],
properties: {
title: {
bsonType: 'string',
description: 'must be a string and is required'
@jlescalonap
jlescalonap / validation.js
Created February 29, 2024 16:30
Ejemplo de validación de schema en MongoDb.
db.createCollection('posts', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'text', 'creator', 'comments'],
properties: {
title: {
bsonType: 'string',
description: 'must be a string and is required'
},
@jlescalonap
jlescalonap / csv_parse.ts
Created February 15, 2024 12:41
CSV Simple parsing example
import fs from 'fs';
const matches = fs
.readFileSync('football.csv', {
encoding: 'utf-8',
})
.split('\n')
.map((row: string): string[] => {
return row.split(',');
});
@jlescalonap
jlescalonap / navigation.tsx
Last active January 27, 2024 18:42
Navigation menu
import { RxHamburgerMenu } from 'react-icons/rx';
import { motion, useCycle, AnimatePresence } from 'framer-motion';
const sidebar = {
open: (height = 1000) => ({
clipPath: `circle(${height * 2 + 200}px at 40px 40px)`,
transition: {
type: 'spring',
stiffness: 20,
restDelta: 2,
@jlescalonap
jlescalonap / route.ts
Created December 20, 2023 20:25
Archivo de configuración del NextAuth
import NextAuth from 'next-auth';
import type { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import User from '@/models/userModel';
import { connectDb } from '@/utils/connect';
import bcrypt from 'bcryptjs';
const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
@jlescalonap
jlescalonap / onSubmit.tsx
Created December 20, 2023 20:25
Función para realizar el registro del usuario.
const handleSubmit = async (e: any) => {
e.preventDefault();
const username = e.target[0].value;
const email = e.target[1].value;
const password = e.target[2].value;
if (!isValidUsername(username)) {
setError('Nombre de usuário inválido');
return;
}
@jlescalonap
jlescalonap / typeguard.ts
Created December 1, 2023 12:26
Example of typeguards implementation
class Sorter {
constructor(public collection: number[] | string) {}
sort(): void {
const { length } = this.collection;
for (let i = 0; i < length; i++) {
for (let j = 0; j < length - i - 1; j++) {
if (this.collection instanceof Array) {
if (this.collection[j] > this.collection[j + 1]) {
@jlescalonap
jlescalonap / ethers.ts
Created November 23, 2023 14:28
How to solve the window.ethereum / window undefined problem in Nextjs
useEffect(() => {
if (
typeof window !== 'undefined' &&
typeof window.ethereum !== 'undefined'
) {
const provider = new ethers.providers.Web3Provider(
window.ethereum as any
);
// @ts-ignore
setSigner(provider.getSigner());
@jlescalonap
jlescalonap / mappable.ts
Last active October 15, 2023 13:42
Typescript class example
export interface mappable {
location: {
lat: number;
lng: number;
};
markerContent(): string;
color: string;
}
export class CustomMap {
@jlescalonap
jlescalonap / index.js
Created July 25, 2023 16:57
Intento de OCR
const Tesseract = require('tesseract.js');
const sharp = require('sharp');
// Ruta de la imagen de entrada (asegúrate de que la imagen exista)
// 0021995m3
const imagePath = 'src/3.jpeg';
// Función para extraer texto de la imagen
async function extractTextFromImage() {
try {