Skip to content

Instantly share code, notes, and snippets.

View dantldev's full-sized avatar
🐙
Always Coding

Daniel Gomez dantldev

🐙
Always Coding
View GitHub Profile
@dantldev
dantldev / middleware_util_nextjs.js
Last active March 14, 2021 14:54
Helper function to implement middlewares on nextjs
/**
* @description _middleware es un objeto con funciones
* útiles para user dentro de api routes de nextjs
*/
export const _middleware = {
/**
* @description Si esta función es llamada como primera linea
* dentro de un método "handler" en una ruta api de nextjs,
* su finalidad es ejecutar tantos middlewares como sea posible
* antes de la ejecución del resto de la función.
@dantldev
dantldev / ScreenshotComponent.js
Last active March 11, 2024 02:54
A workaround to get screenshots from a url on nextjs
/**
* you can call the api route with fetch and will return the base64 blob as json.
* you can use it on a <img /> tag like so:
*/
import { useEffect, useState } from 'react';
export const WebScreenshot = ({ url }) => {
const [data, setData] = useState(null);
useEffect(() => {
fetch(`/api/get-screenshot${url ? `?url=${url}` : ''}`)
@dantldev
dantldev / docker_wordpress.md
Created June 4, 2021 22:32 — forked from bradtraversy/docker_wordpress.md
Docker Compose FIle For Wordpress, MySQL & phpmyadmin

Wordpress & Docker

This file will setup Wordpress, MySQL & PHPMyAdmin with a single command. Add the code below to a file called "docker-compose.yaml" and run the command

$ docker-compose up -d

# To Tear Down
$ docker-compose down --volumes
@dantldev
dantldev / install_stuffs_ubuntu.sh
Last active October 13, 2021 20:26
A bash script to install stuffs on linux ( Ubuntu )
# some stuffs
sudo apt install -y zsh curl build-essential tmux zip unrar g++ as31 nasm ruby ruby-bundler ruby-dev clang-9 lldb valgrind sqlite3 cmake python3-pip &&
# install node 16.x
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
# config npm without sudo
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
@dantldev
dantldev / useComponentFirstRender.tsx
Last active April 3, 2022 17:38
A custom hook to run a callback on react component first render without any dependency issue
import { useEffect, useState } from "react";
/**
* This hook runs a callback when a component is mounted.
*/
export const useComponentFirstRender = (callback: Function) => {
const [isMounted, setIsMounted] = useState(false);
useEffect(() => {
if (isMounted) {
console.log("Component mounted!");
@dantldev
dantldev / store.tsx
Created February 23, 2024 21:43
zustand quick docs
/**
* live demo https://codesandbox.io/p/devbox/confident-bessie-ldx396?file=%2Fsrc%2FApp.tsx%3A1%2C34&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clsz5b2c400073j6j1kpfsrwy%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clsz5b2c300023j6jd