Skip to content

Instantly share code, notes, and snippets.

@danielalvarenga
danielalvarenga / script-configure-ubuntu18.94-amd64.sh
Created July 17, 2019 23:57
Shell script to configure Ubuntu 18.04.
#!/bin/bash
# Author: Daniel Alvarenga Lima
# Ubuntu version supported: 18.04 LTS 64Bit
# EXECUTE
# sudo chmod +x script-configure-ubuntu18.94-amd64.sh
# ./script-configure-ubuntu18.94-amd64.sh
#INSTRUCTIONS
@danielalvarenga
danielalvarenga / languages-abbr.json
Created February 11, 2019 20:03
Languages ABBR
{
"Abkhazian": "ab",
"Afar": "aa",
"Afrikaans": "af",
"Akan": "ak",
"Albanian": "sq",
"Amharic": "am",
"Arabic": "ar",
"Arabic (AE)": "ar-ae",
"Arabic (BH)": "ar-bh",
@danielalvarenga
danielalvarenga / alias_matchers.md
Created July 17, 2018 13:57 — forked from JunichiIto/alias_matchers.md
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@danielalvarenga
danielalvarenga / uuidable.rb
Created April 30, 2018 21:29
Module to generate UUID in Rails Models
# uuidable.rb
module Uuidable
include ActiveSupport::Concern
def self.included(base)
base.primary_key = :id
base.before_create :assign_uuid
end
@danielalvarenga
danielalvarenga / credential.rb
Last active May 2, 2018 12:50
Bearer Authentication in Rails Model
# credential.rb
class Credential < ApplicationRecord
before_create :initialize_api_key
private
# Assign an API key on create
def initialize_api_key
@danielalvarenga
danielalvarenga / application_controller.rb
Last active April 30, 2018 21:39
Bearer Authentication in Rails Controller
# application_controller.rb
class ApplicationController < ActionController::API
include ActionController::HttpAuthentication::Token::ControllerMethods
before_action :authenticate
protected
def authenticate
@danielalvarenga
danielalvarenga / database_cleaner.rb
Last active April 30, 2018 19:44
Database cleaner configuration for rails applications
# frozen_string_literal: true
require 'database_cleaner'
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
if config.use_transactional_fixtures?
@danielalvarenga
danielalvarenga / puma.rb
Last active October 16, 2021 20:08
Puma config for rails 5 api
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
# More: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#threads
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
@danielalvarenga
danielalvarenga / up.sh
Last active November 24, 2018 14:43
Script inicial para iniciar aplicações rails com docker compose
#!/bin/bash
args="'$*'"
containerRepositoryName='container_name_setted_in_docker_compose_service_web'
docker-compose down
# Create container application image with "latest" tag, set "Dockerfile" path,
# change "rails_env_var" variable inside Dockerfile and context path
@danielalvarenga
danielalvarenga / docker-compose.yml
Last active November 24, 2018 15:26
Docker compose para iniciar a aplicações rails
version: '3'
volumes:
redis: # *** REMOVER SE NÃO UTILIZAR REDIS ***
db:
services:
# Serviço que inicia o contêiner de banco de dados Postgres
# *** REMOVA SE NÃO ESTIVER UTILIZANDO POSTGRES ***