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 / before-filter.rb
Created July 22, 2019 00:58
filter before quest
App::Api.controllers do
before do
auth_user
end
get '/list/friends'
{friends:['Joao','Maria','May']}.to_json
end
end
@faustoct1
faustoct1 / api.rb
Last active July 22, 2019 01:00
filter before quest
App::Api.controllers do
before do
auth_user
end
get '/me'
{id:@user[:id],name:@user[:name],username:@user[:username]}.to_json
end
end
@faustoct1
faustoct1 / Location.js
Created July 6, 2020 02:47
Encapsulating location
import { Platform, PermissionsAndroid } from 'react-native'
import { Constants, Permissions } from 'react-native-unimodules'
import NetInfo from "@react-native-community/netinfo";
import * as L from 'expo-location'
class Location {
static getAsync = async () => {
if (Platform.OS === 'android' && !Constants.isDevice) {
throw new Exception('Geolocation only in devices not emulators.')
}
@faustoct1
faustoct1 / Backend.js
Created July 6, 2020 02:52
Backend requests
import { AsyncStorage } from 'react-native'
import Location from './Location.js'
class Backend {
static get = async (url,params,callback) => {
let p = ''
params = (params ? params : {})
const {location, status} = await Location.getAsync();
if(!location)return;
let endpoint = null
Views.js
`````
import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
const Stack = createNativeStackNavigator();
const options = (route,params) => {
@faustoct1
faustoct1 / saveMediaToStorageFirebase.js
Last active June 14, 2022 05:12
A simple code to save media (image/video) of remote source or local to firebase storage
/*
Those imports are to react-native-firebase and firebase storage.
If you use other client stuff, you must to replace the imports
by the include/imports of your languange
or framework, as well as the respective calls.
*/
// START ----
import firebase from '@react-native-firebase/app'
@faustoct1
faustoct1 / App.js
Last active June 25, 2022 20:40
Autenticação + React Navigation em 1 minuto
/*
Esse é o entry point default do react-native App.js. Ele contém um AuthProvider que detecta sempre
que o usuário estiver logado/deslogado para exibir a view correta. Views contém as views do usuário
logado/deslogado.
*/
import React from 'react'
import {AuthProvider} from './AuthCtx'
import Views from './Views.js'
@faustoct1
faustoct1 / app.js
Created June 26, 2022 14:32
Usando redis em ambientes serverless
/*
1. require redis wrapper para executar open/close da conexão
2. Setar sua conexão redis na URL, use uma ENV do seu servidor
para não armazenar usuário/senha hardcoded.
*/
const {redis} = require('./redis')
redis(async (client)=>{
return Promise.all([
@faustoct1
faustoct1 / index.js
Created June 28, 2022 23:54
Exemplo simples de api com express nodejs
/*
yarn add express body-parser cors
node index.js
*/
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const cors = require('cors');
@faustoct1
faustoct1 / set.js
Created July 5, 2022 19:55
Eliminar itens duplicados no array com 1 linha em javascript
const set = new Set([1,1,2,2,3,3,4,4,5,5])
const array = Array.from(set)
console.log(array) //(5) [1, 2, 3, 4, 5]