Skip to content

Instantly share code, notes, and snippets.

@jonathanmdavies
jonathanmdavies / ruby_llm_shrine.rb
Created August 23, 2025 12:00
Monkeypatch RubyLLM to work with Shrine files.
# frozen_string_literal: true
# Monkey patch to add Shrine support to RubyLLM::Attachment
# - Works with Shrine::UploadedFile, Shrine::Attacher (via .file), or Array of UploadedFile (takes first)
# - Reads bytes from storage (open/download), avoiding expiring URLs
# - Pulls filename and mime_type from Shrine metadata when present
module RubyLLM
class Attachment
# ---- Shrine detection helpers ------------------------------------------
@jonathanmdavies
jonathanmdavies / streaming_response.rb
Created August 22, 2025 15:26
Rails concern for streaming response
# frozen_string_literal: true
require "timeout"
module StreamingResponse
extend ActiveSupport::Concern
included do
include ActionController::Live
end
@jonathanmdavies
jonathanmdavies / Summary.md
Created October 15, 2024 18:00 — forked from wking-io/Summary.md
Custom Inertia useForm for uncontrolled form management.

Custom useForm

Inertia comes with a form helper called useForm. However, it requires controlled inputs. This is not best practice for React, but by itself is not a deal breaker. Then I ran into nested data and array data...typed nested object updates is not fun or clean.

So, I built my own version of the useForm hook that allows you to give control back to the DOM. Here is how it works:

  • No manual data updates
  • Data is pulled from the form element on submit and converted into a FormData instance.
  • FormData supports File, nested keys, and array values by default.
  • Can still reset using a key.