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
| #!/bin/bash | |
| # Ensure fswatch is installed | |
| if ! command -v fswatch &> /dev/null; then | |
| echo "Installing fswatch with Homebrew..." | |
| brew install fswatch | |
| exit 1 | |
| fi | |
| # Ensure Caddy is installed for serving files |
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
| import { Controller } from '@hotwired/stimulus' | |
| const BANNED_NODES = ['com-1password-button', 'com-1password-menu'] | |
| export default class extends Controller { | |
| connect () { | |
| this.observer = new window.MutationObserver(mutations => { | |
| mutations.forEach(mutation => { | |
| mutation.addedNodes.forEach(node => { | |
| if (BANNED_NODES.includes(node.nodeName.toLowerCase())) { | |
| node.remove() |
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
| # If you have any session variables that should survive a logout, add them to | |
| # the except_for array. Usage from a controller: | |
| # | |
| # ResetsSessionButItsStillThursdayINeedThese.new.reset(self, | |
| # except_for: [:has_logged_in_before]) | |
| class ResetsSessionButItsStillThursdayINeedThese | |
| def reset(receiver, except_for: []) | |
| backup = except_for.map { |key| [key, receiver.session[key]] } | |
| receiver.reset_session |
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
| require "faker" | |
| def lorem_paragraphs | |
| rand(2..4).times.map { | |
| rand(4..6).times.map { | |
| Faker::Lorem.sentence(word_count: rand(10..40)) | |
| }.join(" ") | |
| }.join("\n\n") | |
| 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
| class TailwindClassBuilder | |
| include ActionView::Helpers::TagHelper | |
| def button_classes(options) | |
| button_type = options.delete(:button_type) { :button } | |
| class_names( | |
| # general classes | |
| "mt-4 px-1 sm:px-3 py-sm sm:py-1 font-semibold bg-transparent border rounded", | |
| case button_type |
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
| # This is a stupid utility to squelch stdout output via puts (could do the same | |
| # for warn; could also override stdout entirely) | |
| # | |
| # Usage in a test, after requiring and including it: | |
| # | |
| # setup do | |
| # suppress_puts([ | |
| # /Execution context was destroyed, most likely because of a navigation/ | |
| # ]) | |
| # 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
| class ValidatesDeeply | |
| Failure = Struct.new(:model, :message) | |
| Result = Struct.new(:valid?, :failures) | |
| def validate(model, visited = Set.new) | |
| return Result.new(true) if visited.include?(model) | |
| visited.add(model) | |
| combine_results(Result.new(model.valid?, extract_failures(model)), *validate_associations(model, visited)) | |
| 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
| :root, | |
| .light { | |
| --accent: 183 64 233; | |
| --accent-bright: 183 64 233; | |
| --accent-light: 217 155 244; | |
| --bg-primary: 249 249 249; | |
| --bg-secondary: 230 230 230; | |
| --border-primary: 17 24 39; |
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
| const css4ColorsToLegacyRgbaPlugin = { | |
| postcssPlugin: 'these-colors-dont-run', | |
| Once (root) { | |
| root.walkDecls((decl) => { | |
| const rgbRegex = /rgb\((\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*(?:\/\s*(\d+\.?\d*))?\)/g | |
| decl.value = decl.value.replace(rgbRegex, (match, r, g, b, a) => { | |
| if (!a || a === '1' || a === '1.0') { | |
| return `rgb(${r}, ${g}, ${b})` | |
| } else { | |
| return `rgba(${r}, ${g}, ${b}, ${a})` |
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
| # Leverages the BroadcastLogger introduced in Rails 7.1 to wrap the current | |
| # logger in a new logger that broadcasts to both the current logger and $stdout | |
| # | |
| # (Announcement: https://rubyonrails.org/2023/9/29/this-week-in-rails) | |
| # | |
| # If the current logger already broadcasts to $stdout, it will not be wrapped, | |
| # making it safe to call this method multiple times without knowing the current | |
| # logging "sitch". | |
| # | |
| # Usage probably looks something like this: |