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
| # SOURCE: https://dev.to/lorankloeze/how-to-create-middleware-in-your-rails-application-ep | |
| # | |
| # frozen_string_literal: true | |
| class RateLimiter | |
| MAX_PER_WINDOW = 50 | |
| WINDOW_SIZE = 1.minute | |
| def initialize(app) | |
| @app = app |
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
| class Cents < ActiveRecord::Type::Integer | |
| def cast(value) | |
| return super if value.is_a?(Numeric) | |
| price_in_dollars = value.to_s.delete("$").to_d | |
| price_in_cents = (price_in_dollars * 100).to_i | |
| super(price_in_cents) | |
| end | |
| def self.dollarize(value) |
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
| # 𝗙𝗮𝘀𝘁𝗲𝗿 𝗗𝗼𝗰𝗸 𝗛𝗶𝗱𝗶𝗻𝗴 | |
| defaults write com.apple.dock autohide-delay -float 0; defaults write com.apple.dock autohide-time-modifier -int 0.05;killall Dock | |
| # Dismiss unmount notifications | |
| sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist DADisableEjectNotification -bool YES && sudo pkill diskarbitrationd |
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
| <style> | |
| .photos img { | |
| width: 15%; | |
| aspect-ration: 3/2; | |
| object-fit: contain; | |
| mix-blend-mode: color-burn; | |
| } | |
| .photos { | |
| background: #dfdfdf; |
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
| <%= turbo_frame_tag "tabs", target: "tab-content" do %> | |
| <%= link_to 'Tab 1', tab_1_path %> | |
| <%= link_to 'Tab 2', tab_2_path %> | |
| <% end -%> | |
| <%= turbo_frame_tag "tab-content", src: tab_1_path, loading: "eager" %> | |
| # Read more: https://turbo.hotwired.dev/handbook/frames |
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
| <div data-controller="modal" data-action-"click@document->modal#close"> | |
| <div class="modal" data-target="modal.modal"> | |
| ... modal content goes here | |
| </div> | |
| </div> |
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
| # frozen_string_literal: true | |
| class ColorPalette | |
| DEFAULT_BASE = 3 | |
| DEFAULT_SATURATION = 0.5 | |
| DEFAULT_LIGHTNESS_MIN = 0.4 | |
| DEFAULT_LIGHTNESS_MAX = 0.8 | |
| DEFAULT_LIGHTNESS_DECAY = 20 | |
| # Generate a color scheme with a given number of colors. |
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
| raw, hashed = Devise.token_generator.generate(User, :reset_password_token) | |
| user = User.find_by(email: '[email protected]') | |
| user.reset_password_token = hashed | |
| user.reset_password_sent_at = Time.now.utc | |
| user.save | |
| # https://mysaas.com/users/password/edit?reset_password_token=raw |
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 Referrable | |
| extend ActiveSupport: :Concern | |
| included do | |
| has_one referral, foreign_key: "referred_user_id", dependent: : destroy has_one referring_user, through: :referral alias_method :referred_by, :referring_user | |
| has_many :referrals, foreign_key: "referring_user_id", dependent: :nullify has_many :referred_users, through: referrals | |
| validates :referral_code, uniqueness: true, allow_nil: true | |
| end | |
| end |
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) |