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 / wcdt-tweet.js
Created May 3, 2024 00:46
Tweet text & images via api
const admin = require("firebase-admin")
/*
const serviceAccount = require("./../key.json");
const { exit } = require("process");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
})
*/
@faustoct1
faustoct1 / ext-firestore-stripe-payments-handleWebhookEvents.js
Last active January 20, 2024 20:29
Create firestore user after a purchase (onetime payment + subscriptions)
"use strict";
/*
* Copyright 2020 Stripe, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
@faustoct1
faustoct1 / subscribeButtonPlain.html
Created November 28, 2023 04:53
subscribeButtonPlain.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Subscribe button example</title>
<script src="http://daily-launches.web.app/plugins/subscribeButton.js"></script>
</head>
<body>
/**
See the documentation here https://daily-launches.web.app/plugins/subscribe
**/
import React, { useEffect, useState } from 'react';
import { View, Text } from 'react-native';
const ExampleView = ({show,handleClose}) => {
const loadScript = (url) => {
return new Promise((resolve, reject) => {
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')
@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]))
@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 / 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 / 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 / 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) {