Skip to content

Instantly share code, notes, and snippets.

View faustoct1's full-sized avatar
🌍
Indie hacker

Fausto Torres faustoct1

🌍
Indie hacker
View GitHub Profile
@faustoct1
faustoct1 / listaligada.js
Created July 27, 2022 19:31
Lista ligada em javascript
class ListLigada{
obj = {
anterior: null,
proximo: null,
valor: null
}
calda = null
cabeca = null
@faustoct1
faustoct1 / app.js
Created July 29, 2022 15:55
Passar parâmetro para um require
module.exports = (params) => {
const app = {
print: async () => {
console.log(params)
}
}
return app
}
@faustoct1
faustoct1 / fila-listaligada.js
Created July 30, 2022 21:13
Implementando fila com lista ligada em javascript
class ListLigada{
obj = {
anterior: null,
proximo: null,
valor: null
}
calda = null
cabeca = null
@faustoct1
faustoct1 / helperstatic.js
Created August 6, 2022 19:50
Classe helper com funções estáticas em js
class Helper {
static getHelloWorldSync = () => {
return "Hello World Sync"
}
static getHelloWorldAsync = async () => {
return "Hello World Async"
}
}
@faustoct1
faustoct1 / urlsearchparams.js
Last active August 8, 2022 04:00
Obter url query string em javascript
const test = async () => {
const url = new URL('https://example.com?foo=1&bar=2');
const params = new URLSearchParams(url.search);
console.log(params.get('foo'))
console.log(params.get('bar'))
const entries = params.entries()
for (const item of entries) {
@faustoct1
faustoct1 / malloc.c
Last active August 9, 2022 23:47
Alocar dinamicamente um array com malloc em C
#include <stdio.h>
#include <stdlib.h>
int main(){
int size=5,*array;
array=(int*)malloc(size * sizeof(int));
for(int i=0;i<size;i++){
array[i] = i;
}
for(int i=0;i<size;i++){
printf("dobro de %d é %d\n",i,array[i]*2);
@faustoct1
faustoct1 / InputSearch.js
Created September 14, 2022 20:36
Como fazer requests com InputText apenas quando parar de digitar
/*
Esse InputSearch faz o search / request / qq coisa depois de 500ms que parou de digitar a última letra.
Isso evita gerar requests desnecessários e entupir o backend com requests. Essa técnica de delay evita
fazer múltiplos requests e faz o request apenas quando parar de digitar.
Use:
<InputSearch open={true} close={()=>setSearching(false)} />
*/
import React, { useState, useEffect } from 'react';
@faustoct1
faustoct1 / str-seo-friendly.js
Created October 23, 2022 08:52
Converter qualquer string em SEO friendly
const toSeoUrl = (name) => {
return name.toString() // Convert to string
.normalize('NFD') // Change diacritics
.replace(/[\u0300-\u036f]/g,'') // Remove illegal characters
.replace(/\s+/g,'-') // Change whitespace to dashes
.toLowerCase() // Change to lowercase
.replace(/&/g,'-and-') // Replace ampersand
// eslint-disable-next-line
.replace(/[^a-z0-9\-]/g,'') // Remove anything that is not a letter, number or dash
@faustoct1
faustoct1 / shuffle.js
Created November 2, 2022 20:00
Como embaralhar (shuffle) um array em javascript
const shuffle = (array) => array.map((a) => ({sort: Math.random(), value: a}))
.sort((a, b) => a.sort - b.sort)
.map((a) => a.value)
console.log(shuffle([1,2,3,4,5]))
const fetch = require('node-fetch')
const { TwitterApi } = require( 'twitter-api-v2')
const getTabNews = async () => {
const response = await fetch(`https://www.tabnews.com.br/api/v1/contents?page=1&per_page=50&strategy=relevant`)
return await response.json()
}
const tweet = async (text,links) => {
console.log('tweet tab news ranking started')