Skip to content

Instantly share code, notes, and snippets.

View JohanAltamar's full-sized avatar
🎯
Focusing

Johan Altamar JohanAltamar

🎯
Focusing
View GitHub Profile
@JohanAltamar
JohanAltamar / password-property-dto.ts
Created December 13, 2024 21:28 — forked from Klerith/password-property-dto.ts
Password validation - DTO
@IsString()
@MinLength(6)
@MaxLength(50)
@Matches(
/(?:(?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/, {
message: 'The password must have a Uppercase, lowercase letter and a number'
})
password: string;
@JohanAltamar
JohanAltamar / usePersistedState.jsx
Last active September 22, 2020 04:50
Persist react hooks state at LocalStorage
import { useEffect, useState } from 'react';
export function usePersistedState(key, defaultValue) {
const [state, setState] = useState(
() => JSON.parse(localStorage.getItem(key)) || defaultValue
);
useEffect(() => {
localStorage.setItem(key, JSON.stringify(state));
}, [key, state]);
return [state, setState];
@JohanAltamar
JohanAltamar / Carousel.css
Created August 21, 2020 17:41
Carousel component to use inside your React, Gatsby projects. An example can be found on https://johanaltamar.com/portfolio/delivree