Skip to content

Instantly share code, notes, and snippets.

View joeypy's full-sized avatar
🏠
Working from home

Joseph Boscan joeypy

🏠
Working from home
  • Designio
  • Caracas - Venezuela
View GitHub Profile
@joeypy
joeypy / toBase64.js
Created December 24, 2022 11:47
Convert to base64 js
const toBase64 = file => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
@joeypy
joeypy / useAxios.ts
Last active December 19, 2022 23:24
Custom hook for request Axios
import axios from 'axios';
import { useEffect, useState, useRef } from 'react';
interface ResponseApi {
data: any;
isLoading: boolean;
isError: Error | null;
errorMessage: any;
refetch: (params?: any) => void;
}
@joeypy
joeypy / search.js
Created October 5, 2022 18:36
Advanced searching for JS with regex
// Code to make match with any character present in the input o query in this case
const values = ['Belgium', 'Brest', 'Britian']
const query = 'Be'
// /.*b.*e.*/
const re = RegExp(`.*${query.toLowerCase().split('').join('.*')}.*`)
// [ 'Belgium', 'Brest' ]
const matches = values.filter(v => v.toLowerCase().match(re))
@joeypy
joeypy / Alias.txt
Created September 8, 2022 13:58
Alias windows and Unix
Creando un ambiente virtual con VENV
Creación de ambiente Virtual:
python3 -m venv nombre_venv
Usualmente el nombre del ambiente virtual es venv.
Activación del ambiente virtual:
Windows:
.\venv\Scripts\activate
@joeypy
joeypy / next.config.js
Created April 18, 2022 21:35
NextJS export cache issue fix. Update cache on every build
/* the trick is to build unique build ID on every build and add it to static files on build time.
* This way the name and URL of static files will change on every build.
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
// Used to set folders as alias to directly use in nextjs
const nextConfiguration = ({
webpack: (config, { buildId, dev }) => {
@joeypy
joeypy / life_days.py
Created April 17, 2022 17:06
How days we have...
# 🚨 Don't change the code below 👇
age = int(input("What is your current age?"))
# 🚨 Don't change the code above 👆
#Write your code below this line 👇
days_per_year = 365
weeks_per_year = 52
months_per_year = 12
max_age = 90
@joeypy
joeypy / gist:a16c07a96e4e14e15f5b882b512f21b0
Created April 12, 2022 15:41
Download data into a file
const downloadFile = ({ data, fileName, fileType }) => {
const blob = new Blob([data], { type: fileType })
const a = document.createElement('a')
a.download = fileName
a.href = window.URL.createObjectURL(blob)
const clickEvt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
@joeypy
joeypy / gist:382dd03c3991de3f7782ef43441c48e0
Created March 17, 2022 11:13
React Components - Modal
import { useEffect } from 'react';
import { BsXLg } from "react-icons/bs";
import { Button } from 'antd'
const Modal = ({
children,
setVisible,
handleSubmit,
visible=false,
title="Title",

Code JS

groupBy

var groupBy = function(xs, key) {
  return xs.reduce(function(rv, x) {
    (rv[x[key]] = rv[x[key]] || []).push(x);
    return rv;
  }, {});
};
18 Python scripts that help you write code faster
Python is a no-BS programming language. Readability and simplicity of design are two of the biggest reasons for its immense popularity.
This is why it is worthwhile to remember some common Python tricks to help improve your code design. These will save you the trouble of surfing Stack Overflow every time you need to do something.
The following tricks will prove handy in your day-to-day coding exercises.
1. Finding Unique Elements in a String
The following snippet can be used to find all the unique elements in a string. We use the property that all elements in a set are unique.
my_string = "aavvccccddddeee"