Skip to content

Instantly share code, notes, and snippets.

View pedrogardim's full-sized avatar
🎯
Focusing

Pedro Gardim pedrogardim

🎯
Focusing
View GitHub Profile
@pedrogardim
pedrogardim / useTypingText.tsx
Created October 19, 2023 17:00
Typing text effect React hook
import { useState, useEffect } from "react";
export default function useTypingText(originalText: string, delay = 50) {
const [letterCount, setLetterCount] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setLetterCount((prev) => {
if (prev === originalText.length) {
clearInterval(interval);
@pedrogardim
pedrogardim / objectId.go
Created October 5, 2023 13:33
Golang | Generate random MongoDB ObjectId
func mongoObjectId() string {
ts := time.Now().UnixMilli() / 1000;
id := strconv.FormatInt(ts, 16)
for i := 0; i < 16; i++ {
id += fmt.Sprintf("%x", rand.Intn(16))
}
return id
}