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 / 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
@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 / 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 / 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 / jwt_init
Created July 22, 2019 00:53
session jwt init
sha256 = Digest::SHA256.hexdigest "some key goes here you should generate yours"
HMAC_SECRET = sha256
@faustoct1
faustoct1 / redis_init.rb
Created July 22, 2019 00:49
init redis
uricache = URI.parse(ENV["REDIS_URL"])
CACHE = Redis.new(:host => uricache.host, :port => uricache.port, :password => uricache.password)
@faustoct1
faustoct1 / helper.rb
Created July 22, 2019 00:45
handle distributed user session
def auth_user user=nil
#token = JWT.decode(params[:token], hmac_secret, true, { :algorithm => 'HS256' })
token = request.env["HTTP_TOKEN"]
halt 401, "token + user are nil" if (token.blank? && user.blank?)
@user ||= CACHE.get(token)
unless @user.blank?
halt 400, "existent user for a blank token" if token.blank?
@faustoct1
faustoct1 / UsageComponentDate.js
Last active May 30, 2019 05:02
using date component
import React, { Component } from 'react';
import Date from require('./components/Date.js')
export default class App extends Component {
initAsync = async (that) => {
}
constructor(props) {
super(props)
@faustoct1
faustoct1 / ComponentDate.js
Last active May 14, 2019 06:35
react native component example
import React, { Component } from 'react';
import { Text, View } from 'react-native';
let moment = null
class Date extends Component {
initAsync = async () => {
moment = require('moment')
}
constructor(props) {
@faustoct1
faustoct1 / UsageProxySnippet.js
Last active May 14, 2019 05:31
Exemplo de uso do proxy
<TouchableOpacity onPress={()=>{Views.navigator.navigate({
routeName: 'Proxy',
params: {component:'List', title: 'Curtidas'},
key: Backend.uuid() })}}>
<Text style={{fontSize: 16, margin:10}}>Curtidas</Text>
</TouchableOpacity>