This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Abort sign off on any error | |
set -e | |
# Start the benchmark timer | |
SECONDS=0 | |
# Repository introspection | |
OWNER=$(gh repo view --json owner --jq .owner.login) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# filename: single_page_rails_app.ru | |
# RUN via: `rackup single_page_rails_app.ru` | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rack", "2.2.9" | |
gem "rails", "~> 7.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KAMAL_REGISTRY_PASSWORD=dckr_pat_xXXxx_x0xXxXx-xX-XXX0xX0x-x | |
RAILS_MASTER_KEY=00x00xxx000xxx000000xx0x000x0x00 | |
POSTGRES_PASSWORD=xXxxx0xXXx0 | |
MEILI_MASTER_KEY=xXxxx0xXXx0 | |
BLAZER_DATABASE_URL=postgres://service:{POSTGRES_PASSWORD}@service-name-postgres:5432/service_production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OAuth::GoogleAuthorizationsController < ApplicationController | |
CLIENT_ID = Rails.application.credentials.google.client_id | |
CLIENT_SECRET = Rails.application.credentials.google.client_secret | |
SCOPE = "openid email profile" | |
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth") | |
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token") | |
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo") | |
before_action :validate_state_token, only: :show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
For apps built before the image_processing
gem became the default, the migration will involve two steps:
- Migrating to the image processing syntax while still using ImageMagick;
- Switching to Vips and updating the compression options;
Before changing from ImageMagick to Vips, it's better to first test the new syntax and ensure everything is still working.
variant(format: :jpg, strip: true, quality: 80)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add color coding based on Rails environment for safety | |
if defined? Rails | |
banner = if Rails.env.production? | |
"\e[41;97;1m #{Rails.env} \e[0m " | |
else | |
"\e[42;97;1m #{Rails.env} \e[0m " | |
end | |
# Build a custom prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Formats a +number+ into an abbreviated string suitable for | |
# displaying social media type metrics | |
# | |
# ==== Options | |
# * start_at - The first number to start abbreviating, defaults | |
# to 10_000. Certain metrics may want to start at e.g. 1000. | |
# | |
# ==== Examples | |
# number_to_social(123) # => 123 | |
# number_to_social(1457) # => 1457 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A memory-saving ActiveRecord setting has been used by just one application ever, according to GitHub | |
There's a common performance problem in many Rails background jobs. | |
Background jobs often do operations across large sets of data. Basically, they do silly things like User.all.each(&:send_daily_newsletter). | |
So, there's a problem with that query. In development and test environments, User.all will probably return a few rows, maybe a dozen at most. Most developers have extremely limited seed data on their local machines. | |
In production, however, User.all will probably return quite a few rows. Depending on the app you work on, maybe a few hundred thousand. | |
There's a tiiiiiny issue with a result set that returns 100,000 rows, and it's not just that the SQL query will take a long time to return. It will have irreversible effects on your Ruby app too! |
NewerOlder