Skip to content

Instantly share code, notes, and snippets.

View frankyston's full-sized avatar
🎯
Ruby on Rails is Fun

Frankyston Lins frankyston

🎯
Ruby on Rails is Fun
View GitHub Profile
@frankyston
frankyston / teste-foda.md
Created June 5, 2024 00:41 — forked from DanielHe4rt/teste-foda.md
Teste Técnico: Crie seu Discord!

Teste Tecnico: Desenvolvimento de uma Aplicação de Chat em Tempo Real com PHP e Laravel (ou qualquer outra lang)

Introdução

Neste desafio, você será responsável por desenvolver uma aplicação de chat em tempo real utilizando PHP e o framework Laravel. A aplicação deve oferecer funcionalidades básicas similares às encontradas em plataformas de chat como o Discord. O foco principal é a criação de um backend robusto e escalável, utilizando as abstrações e boas práticas do Laravel.

Requisitos do Projeto

Funcionalidades Principais

@frankyston
frankyston / Dockerfile
Last active May 3, 2024 12:03
Exemplo de docker compose para rails + sidekiq + redis + banco de dados
FROM ruby:3.1.2
ARG NODE_MAJOR_VERSION=20
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR_VERSION.x | bash -
RUN apt-get update -qq && \
apt-get install -y build-essential libvips nodejs libpq-dev postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man && \
npm install -g yarn
@frankyston
frankyston / without_foreign_keys.rb
Created March 1, 2024 14:25 — forked from myronmarston/without_foreign_keys.rb
Example of how to disable foreign keys for a particular context
RSpec.shared_context "without foreign key constraints", :disable_foreign_keys do
def without_foreign_key_checks
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0;')
yield
ensure
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 1;')
end
around(:example) { |ex| without_foreign_key_checks(&ex) }
end
@frankyston
frankyston / rails_helper.rb
Created February 27, 2024 22:35 — forked from romulogomes/rails_helper.rb
Factories lowest
def red(text)
"\033[31m#{text}\033[0m"
end
number_of_factories_to_analyze = 10
load_begin = Time.now
stats = {}
ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |_name, start, finish, _id, payload|
execution_time_in_seconds = finish - start
stats[payload[:name]] = stats[payload[:name]].to_f + execution_time_in_seconds
@frankyston
frankyston / presigned_url.rb
Created October 24, 2023 21:33 — forked from miligraf/presigned_url.rb
Rails - Upload an Object Using a Pre-Signed URL (AWS SDK for Ruby)
Aws.config.update({
region: 'us-east-1',
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
})
S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET'])
@post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
post = Aws::S3::Resource.new.bucket("fake").presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
@frankyston
frankyston / login_helpers.rb
Created August 9, 2023 22:46 — forked from Envek/login_helpers.rb
Signing-in user for integration tests via cookie-only session with Rails, Devise, Capybara, and Cuprite
# spec/system/support/login_helpers.rb
# See this blog post for setup guide: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing
module LoginHelpers
def login_as(user)
# Craft session cookie to make request authenticated (to pass even routing constraints)
# Compilation of these:
# - https://dev.to/nejremeslnici/migrating-selenium-system-tests-to-cuprite-42ah#faster-signin-in-tests
# - https://turriate.com/articles/2011/feb/how-to-generate-signed-rails-session-cookie
# - https://github.com/rails/rails/blob/43e29f0f5d54294ed61c31ddecdf76c2e1a474f7/actionpack/test/dispatch/cookies_test.rb#L350
@frankyston
frankyston / README.md
Created August 3, 2023 23:06 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@frankyston
frankyston / iterm2-solarized.md
Created June 9, 2023 20:42 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@frankyston
frankyston / add_unaccent_to_postgres
Created April 26, 2023 17:07 — forked from AlexVKO/add_unaccent_to_postgres
Adding extensions to Postgresql database with Rails
The default Postgresql installation on Mac OS X using homebrew includes a single extension - plpgsql (PL/pgSQL procedural language) but there are a number of them available in the lib directory (/usr/local/Cellar/postgresql/9.2.1/lib on my machine)
To install an extension into the database, the easiest way I found was to open a database console using the 'rails db' command and then create it directly. I have seen mention of doing this in a Rails migration but this did not work for me.
Note that an extension is installed in a specific database, rather than being added to all databases.
The command to list the installed extensions is '\dx'
$ rails db
psql (9.2.1)
@frankyston
frankyston / transaction.rb
Created March 14, 2023 21:16
Usando uma coleção de hash de uma outra API
params = [
{
"id": "00012572000000133723",
"dataRegistro": "15.03.2021",
"dataVencimento": "08.06.2021",
"valorOriginal": 14900,
"valorPagoSacado": 344.6,
"numeroConvenio": 000,
"numeroOperacao": 0000,
"carteiraConvenio": 17,