var groupBy = function(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toBase64 = file => new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = () => resolve(reader.result); | |
reader.onerror = error => reject(error); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 🚨 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
import { BsXLg } from "react-icons/bs"; | |
import { Button } from 'antd' | |
const Modal = ({ | |
children, | |
setVisible, | |
handleSubmit, | |
visible=false, | |
title="Title", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
NewerOlder