Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.
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
# frozen_string_literal: true | |
module Fingerprinting | |
def full_fingerprint | |
generate_fingerprint( | |
ip_fingerprint, | |
browser_fingerprint | |
) | |
end |
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
while bundle exec rake test; do :; done |
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
namespace :db do | |
desc 'reset the database by dropping the schema' | |
task complete_reset: :environment do | |
raise unless Rails.env.local? | |
FileUtils.rm_f('db/schema.rb') | |
Rake::Task['db:drop'].invoke | |
Rake::Task['db:create'].invoke | |
Rake::Task['db:migrate'].invoke | |
Rake::Task['db:seed'].invoke |
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
# Prompt: | |
What’s your most elegant Ruby code that does this: | |
* takes an array of strings and a target string | |
* if the target string is not in the array, return the array | |
* if the target string is in the array, return the array with the target string moved from its position to the end of the array. | |
What’s your most elegant Ruby code that does this: | |
* takes an array of strings and a target string |
This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!
- Follow me on Twitter for more Ruby AI at https://twitter.com/alexrudall
- Released under the MIT License - use as you wish :)
First, add the ruby-openai gem! Needs to be at least version 4. Add Sidekiq too.
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
def self.included(base) | |
base.instance_variable_set(:@count, 0) unless base.instance_variable_defined?(:@count) | |
base.instance_variable_set(:@count, base.instance_variable_get(:@count) + 1) | |
puts base.name if base.instance_variable_get(:@count) > 1 | |
end |
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
# frozen_string_literal: true | |
# ActiveRecord::Enum validation in Rails API | |
# https://medium.com/nerd-for-tech/using-activerecord-enum-in-rails-35edc2e9070f | |
module EnumValidatable | |
extend ActiveSupport::Concern | |
class_methods do | |
def validatable_enum(*enums_to_fix) | |
enums_to_fix.each do |element| |
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
on: | |
workflow_call: | |
inputs: | |
deploy_target: | |
description: 'Deploy target' | |
required: true | |
type: string | |
default: 'production' | |
secrets: | |
GH_TOKEN: |
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 |
NewerOlder