Skip to content

Instantly share code, notes, and snippets.

View tiagogeraldi's full-sized avatar

Tiago Andre Geraldi tiagogeraldi

  • Toledo, PR - Brasil
View GitHub Profile
@tiagogeraldi
tiagogeraldi / importer.rb
Created July 6, 2021 20:23
Reading a Firebase/Firestore document with Ruby, REST API and Email / password based authentication
# frozen_string_literal: true
# Usage: Importer.new.read
require 'faraday'
class Importer
AUTH_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"
FIREBASE_API_KEY="CHANGE_ME - see the Settings page of your DB"
FIREBASE_PROJECT_ID="CHANGE_ME - the ID / Name of your Firestore project"
FIREBASE_USER_EMAIL="CHANGE_ME - the email of your user"
@tiagogeraldi
tiagogeraldi / install.sh
Created April 27, 2021 12:14
ASDF and ruby in a M1 cpu MacBook
brew install asdf
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" asdf install ruby 2.6.6
gem install bundler
@tiagogeraldi
tiagogeraldi / application_controller.rb
Created August 8, 2018 23:17
Part of Apartment with no subdomain
class ApplicationController < ActionController::Base
before_action :tenant_session
private
def tenant_session
if !session[:tenant]
redirect_to [:new, :tenant_session]
end
end
@tiagogeraldi
tiagogeraldi / routes.rb
Created August 8, 2018 23:16
Part of Apartment with no subdomain
Rails.application.routes.draw do
devise_for :users
resources :posts
resources :tenant_sessions, only: [:new, :create]
root to: 'posts#index'
end
@tiagogeraldi
tiagogeraldi / new.html.slim
Created August 8, 2018 23:12
Part of Apartment with no subdomain
= form_for :tenant, url: tenant_sessions_path do |f|
.form-group
= f.label :name
= f.text_field :name, class: 'form-control'
.form-group
= f.submit 'Go', class: 'btn btn-primary'
@tiagogeraldi
tiagogeraldi / tenant_sessions_controllers.rb
Created August 8, 2018 23:11
Part of Apartment with no subdomain
class TenantSessionsController < ApplicationController
skip_before_action :tenant_session
#layout 'devise'
def new
# clean any logged user up
reset_session
end
@tiagogeraldi
tiagogeraldi / apartment.rb
Last active August 8, 2018 23:38
Part of Apartment with no subdomain
require 'apartment/elevators/generic'
Apartment.configure do |config|
# Your Customer model
config.excluded_models = %w{ Customer }
# Customer name will be the key of the tenant
config.tenant_names = lambda { Customer.pluck :name }
end
@tiagogeraldi
tiagogeraldi / downgrade.sh
Last active July 18, 2017 17:55
Downgrade MySQL 5.7 to 5.6 and update gem mysql2
#Environment:
#- Macos Sierra 10.12.5
#- Ruby 2.2.0 (rbenv)
$ brew uninstall mysql
$ rm -rf /usr/local/mysql # Warning: IT DELETES ALL DBs
$ brew install mysql56
$ brew services start mysql56
$ gem uninstall mysql2
@tiagogeraldi
tiagogeraldi / howtouse.rb
Created December 29, 2015 13:13
Query searcher for string
str = "I'd like to buy a Belina instead of a Pampa"
Search.new(query: 'Belina AND Pampa').test(str) #=> true
Search.new(query: 'Belin*').test(str) #=> true
Search.new(query: '"buy a Belina"').test(str) #=> true
Search.new(query: 'Belina -Pampa').test(str) #=> false
@tiagogeraldi
tiagogeraldi / gist:11255684
Created April 24, 2014 14:02
cross access config
require 'sinatra/cross_origin'
class TweekRecommender < Sinatra::Base
include SinatraSimpleRouter
configure do
enable :cross_origin
set :allow_origin, :any
set :allow_methods, [:get, :post, :options]
set :allow_credentials, true