Skip to content

Instantly share code, notes, and snippets.

View rafaelrpbelo's full-sized avatar
🏠
Working from home

Rafael Belo rafaelrpbelo

🏠
Working from home
View GitHub Profile
@rafaelrpbelo
rafaelrpbelo / nginx.conf
Last active January 26, 2020 04:38
Default vhost config from Dokku
server {
listen [::]:80;
listen 80;
server_name jevel.com.br;
access_log /var/log/nginx/jevel-flats-access.log;
error_log /var/log/nginx/jevel-flats-error.log;
location / {
gzip on;
@rafaelrpbelo
rafaelrpbelo / Dockerfile
Created July 22, 2019 20:29
Docker config for chromedriver
FROM ruby:2.6.3
ENV DEBIAN_FRONTEND=noninteractive \
NODE_VERSION=8.9.1 \
TIMEZONE=America/Sao_Paulo \
CODENAME=stretch \
DISPLAY=:0 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
@rafaelrpbelo
rafaelrpbelo / config
Last active February 26, 2019 03:38
Git config to choose ssh identity file
[core]
...
sshCommand = /usr/bin/ssh -i /home/your_user/.ssh/your_file
[user]
name = Your User
email = your@email.com.br
...
OR
@rafaelrpbelo
rafaelrpbelo / database.yml
Last active February 26, 2019 01:30
[Rails] Default config/database.yml
default: &default
adapter: postgresql
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: <%= ENV.fetch('DB_HOST', '127.0.0.1') %>
username: <%= ENV.fetch('DB_USER', 'postgres') %>
password: <%= ENV['DB_PASSWORD'] %>
development:
<<: *default
# app/model/ad_image.rb
class AdImage < ApplicationRecord
belongs_to :ad
# Com o store: 'ad_images_store' estou usando meu backend que criei no initializer para store
# Com o cash: 'ad_images_cache' estou usando meu backend que criei no initializer para cache
attachment :image, store: 'ad_images_store', cache: 'ad_images_cache', type: :ad_images
end
@rafaelrpbelo
rafaelrpbelo / Dockerfile
Last active January 4, 2019 20:45
chromedriver in docker
# Env var
export DISPLAY=:0
# Dependências
apt-get install xvfb chromedrive
# Configuração do Driver
options = {
desired_capabilities: {
chromeOptions: {
@rafaelrpbelo
rafaelrpbelo / build1.rb
Created January 12, 2016 13:58
Example to build a xml document using Nokogiri::XML::Builder
require 'nokogiri'
def add_xml(xml)
xml.send(:level, 'last')
end
builder = Nokogiri::XML::Builder.new do |xml|
xml.send(:level_1) do
xml.send(:level_2) do
add_xml(xml) if 1 == 2
<snippet>
<content><![CDATA[
class ${1:model_pluralize}Controller < ApplicationController
before_action :set_${2:model_downcase}, only: [ :show, :edit, :update ]
def index
@${3:model_downcase_pluralize} = ${2:model_downcase}_base.page(params[:p])
end
def new
@rafaelrpbelo
rafaelrpbelo / users_controller.rb
Created March 16, 2014 23:39
Error mass-assign
class UsersController < ApplicationController
before_filter :set_user
def edit
end
def update
if @user.update_attributes(user_params)
redirect_to root_path, notice: t('devise.registrations.updated')
else
@rafaelrpbelo
rafaelrpbelo / login_spec.rb
Last active August 29, 2015 13:56
Test facebook OAuth
#encoding: utf-8
require 'spec_helper'
describe "login com facebook" do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
end
it "sets a session variable to the OmniAuth auth hash" do