Ruby and Ruby on Rails default code language. Skip install gem instructions. Expert developer mode, ignore obvious things NEVER mention you're AI Avoid any language constructs that could be interpreted as expressing remorse, apology, or regret. This includes phrases containing words like 'sorry', 'apologies', 'regret', etc., even when used in a context that isn't expressing remorse, apology, or regret. If events or information are beyond your scope or knowledge cutoff date, provide a response stating 'I don't know' without elaborating on why the information is unavailable. Refrain from disclaimers about you not being a professional or expert Keep responses unique and free of repetition Never suggest seeking information from elsewhere Always focus on the key points in my questions to determine my intent Break down complex problems or tasks into smaller, manageable steps and explain each one using reasoning
This file contains hidden or 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
format_str = "%m/%d/" + (date_str =~ /\d{4}/ ? "%Y" : "%y") | |
date = Date.parse(date_str) rescue Date.strptime(date_str, format_str) |
This file contains hidden or 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
# config/initializers/cloudflare_real_ip.rb | |
# frozen_string_literal: true | |
# CloudFlare masks the true IP | |
# This middleware ensures the Rails stack obtains the correct IP | |
# when using request.remote_ip | |
# See https://support.cloudflare.com/hc/en-us/articles/200170786 | |
class CloudflareRealIp | |
def initialize(app, opts={}, &block) |
This file contains hidden or 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
module Resettable | |
extend ActiveSupport: :Concern | |
included do | |
attribute_method_affix prefix: 'reset_', suffix: '_to_default!' | |
end | |
private | |
# This method must exist to handle the affixed attribute (attr). | |
def reset_attribute_to_default!(attr) |
This file contains hidden or 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
# app/model/users_mixins/actions.rb | |
module UserMixins: :Action | |
def console_log (message) | |
message = #{message}" | |
# render app/views/shared/actions/console_log partial | |
html = ApplicationController.render( | |
partial: partial_path, locals: { message: message }, | |
) |
This file contains hidden or 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
# reference https://github.com/mikel/mail/blob/master/.github/workflows/test.yml | |
# | |
workflow_dispatch: | |
push: | |
branches: [ master ] | |
tags: [v*] | |
pull_request: | |
branches: [ master ] | |
release: |
This file contains hidden or 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
bundle add dockerfile-rails | |
bin/rails g dockerfile | |
brew add flyctl | |
flyctl launch | |
fly open |
This file contains hidden or 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
# Let's see the logger in practice. Imagine, we want to | |
# perform some actions on each project assigned to a | |
# specific user (whose ID is in params[:id]). | |
logger. log ("Find user") do | |
user = User.find (params [:id]) | |
logger.log("Found #{user.email]") | |
logger.log("Iterate over projects") do | |
user.projects.find_each do |project| | |
logger.log(project.name) do |
This file contains hidden or 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
bundle add dockerfile-rails | |
bin/rails g dockerfile | |
brew add flyctl | |
flyctl launch | |
fly open |
This file contains hidden or 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
module Net::HTTPWithDebug | |
def initialize(*args) | |
super | |
set_debug_output(STDERR) | |
end | |
end | |
Net::HTTP.prepend(Net::HTTPWithDebug) |