Skip to content

Instantly share code, notes, and snippets.

View ggstroligo's full-sized avatar
🏠

Augusto Stroligo ggstroligo

🏠
View GitHub Profile
@ggstroligo
ggstroligo / using-uuid-as-pk.md
Created November 1, 2023 13:11 — forked from rponte/using-uuid-as-pk.md
Não use UUID como PK nas tabelas do seu banco de dados

Pretende usar UUID como PK em vez de Int/BigInt no seu banco de dados? Pense novamente...

TL;TD

Não use UUID como PK nas tabelas do seu banco de dados.

Um pouco mais de detalhes

@ggstroligo
ggstroligo / list_indexes_in_rails_console.rb
Created June 23, 2023 00:06 — forked from davygora/list_indexes_in_rails_console.rb
Get list of all indexes in rails console.
# rails console
ActiveRecord::Base.connection.tables.each do |table|
indexes = ActiveRecord::Base.connection.indexes(table)
if indexes.length > 0
puts "====> #{table} <===="
indexes.each do |index|
puts "----> #{index.name}"
end
puts "====> #{table} <===="
@ggstroligo
ggstroligo / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Created November 18, 2022 17:14 — forked from iscott/simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
@ggstroligo
ggstroligo / warden_example.rb
Created November 18, 2022 00:03 — forked from ciaranarcher/warden_example.rb
Warden Example - Basic HTTP Auth
Warden::Manager.before_failure do |env, opts|
# Sinatra/Padrino is very sensitive to the request method and
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block.
env['REQUEST_METHOD'] = "POST"
end
Warden::Strategies.add(:basic_http) do
def valid?
# Check if valid and store an instance var
@ggstroligo
ggstroligo / docker-pry-rails.md
Created September 17, 2022 16:48 — forked from briankung/docker-pry-rails.md
Using pry-rails with Docker

First, add pry-rails to your Gemfile:
https://github.com/rweng/pry-rails

gem 'pry-rails', group: :development

Then you'll want to rebuild your Docker container to install the gems

@ggstroligo
ggstroligo / rails-jsonb-queries
Created June 8, 2022 14:00 — forked from mankind/rails-jsonb-queries
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@ggstroligo
ggstroligo / alias_matchers.md
Created March 25, 2019 19: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