Skip to content

Instantly share code, notes, and snippets.

View jsstoni's full-sized avatar

BannedNull jsstoni

View GitHub Profile
@jsstoni
jsstoni / action.ts
Created August 22, 2024 20:27
upload image
"use server";
import { writeFile } from "fs/promises";
import path from "path";
export const uploadImage = async (data: FormData): Promise<string> => {
const image = data.get("image") as File | null;
if (!image) {
throw new Error("Image no found");
@jsstoni
jsstoni / route.ts
Created April 3, 2024 22:08
[...nextauth]
import NextAuth from "next-auth";
import CredentialProvider from "next-auth/providers/credentials";
import prisma from "@/libs/prisma";
import bcrypt from "bcrypt";
interface Credentials {
email: string;
password: string;
}
@jsstoni
jsstoni / use-cache.js
Created October 16, 2023 23:55
cache fetch nuxt 3
export default async function (key, endpoint, options = {}) {
const cache = ref();
const { data: cachedData } = useNuxtData(key);
if (cachedData.value) {
cache.value = cachedData.value;
} else {
const { data, error } = await useLazyAsyncData(
key,
() => $fetch(endpoint),
options
// Image guardada: localStorage.image;
// crear un evento onchange al tipo file del formulario o cuando hagas tu submit ejecutar lo siguiente
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
localStorage.imagen = reader.result;
}
reader.readAsDataURL(file);
@jsstoni
jsstoni / mc.php
Created October 22, 2021 12:33
Mercadolibre chile
<?php
require_once 'simple_html_dom.php';
$id = $_GET['id']; //_CustId_328224676
if (isset($id)) {
$url = "https://listado.mercadolibre.cl/{$id}";
$html = file_get_html($url);
$productos = array();
foreach ($html->find("ol.ui-search-layout", 0)->find("li.ui-search-layout__item") as $key => $li) {
$items = array();
$items['title'] = $li->find('h2.ui-search-item__title', 0)->plaintext;
<?php
//@setcookie("user", "", time() - 3600);
//unset($_COOKIE);
//echo session_id();
if (!session_id()) {
session_start();
}
ini_set('display_errors', 0);
date_default_timezone_set('Asia/Kolkata');
<?php
function getRandomString($lng = 12) {
$charset = '0123456789';
$randString = "";
while(strlen($randString) < $lng) {
$randChar = substr(str_shuffle($charset), mt_rand(0, strlen($charset)), 1);
$randString .= $randChar;
}
return $randString;
}
@jsstoni
jsstoni / getPagespeedImage.py
Last active November 20, 2020 14:58
Obtener de una lista de URL las imágenes de los resultados de pagespeed
import os, requests, json, xlsxwriter, base64
import pandas as pd
from time import sleep
"""
@df: variable creada para lectura del archivo excel donde se encuentran todas las urls
@dfx: variable que contiene todos los valos leidos de df.values
@key: apikey generada de google
"""
df = pd.read_excel('urls.xlsx', sheet_name='Hoja1', index=False, header=None)
@jsstoni
jsstoni / functions.php
Created May 15, 2020 16:52
reemplazar texto en wordpress
add_filter('gettext', 'traductor');
add_filter('ngettext', 'traductor');
function traductor($text) {
$text = str_ireplace('Detalles de facturación', 'El texto que quiero aqui', $text);
return $text;
}
@jsstoni
jsstoni / mercadolibre.php
Last active August 26, 2021 14:37
scraping mercado libre
<?php
require_once 'simple_html_dom.php';
$id = $_GET['id']; //_CustId_328224676
if (isset($id)) {
$url = "https://listado.mercadolibre.cl/{$id}";
$html = file_get_html($url);
$productos = array();
foreach ($html->find("ol.ui-search-layout", 0)->find("li.ui-search-layout__item") as $key => $li) {
$items = array();
$items['title'] = $li->find('h2.ui-search-item__title', 0)->plaintext;