Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
julianrubisch / README.md
Last active February 12, 2026 15:32
WaCombobox server-side pagination & filtering for Rails + Hotwire + Web Awesome

WaCombobox Server-Side Pagination & Filtering

Lazy-loaded, paginated, server-side filtered <wa-combobox> options for Rails 8 + Hotwire + Web Awesome — no extra gems required.

How it works

  1. On connect, the Stimulus controller fetches page 1 via Turbo Stream → turbo_stream.update replaces the combobox with the first N options plus a `` sentinel at the bottom.
@julianrubisch
julianrubisch / ext.c
Created April 17, 2025 17:05
DragonRuby Libpd
static void audio_callback(void *userdata, Uint8 *stream, int len) {
float *inbuf = (float *)stream; // Point inbuf to the stream
int num_samples = len / sizeof(float); // Total number of float samples
int ticks = num_samples / 64 * 2; // Each tick is 64 samples per channel (128 samples total)
float outbuf[num_samples]; // Allocate outbuf on the stack with the same size as inbuf
// Process the samples
libpd_process_float(ticks, inbuf, outbuf);
@julianrubisch
julianrubisch / main.rb
Last active February 2, 2026 17:39
DragonRuby "Async" Multiplayer Sync via HTTP
class Game < HttpRouter
def initialize(players: [])
@players = players
@http_debounce = 0
route do |routes|
@players.each do |player|
routes.get "/#{player.id}/progress" do |req|
if @current_scene_name == :host_scene
req.respond 200, "{ \"progress\": #{player.progress} }"
Rails.application.config.after_initialize do
Sitepress::SiteController.include(Sitepress::HttpCaching)
end
module Sitepress::HttpCaching
extend ActiveSupport::Concern
included do
before_action do
fresh_when current_resource.asset.updated_at if !!current_resource.data["cache"]
@julianrubisch
julianrubisch / _search.html.erb
Created June 7, 2024 10:02
Sitepress Pagefind Integration
<div data-controller="search">
<div data-search-target="button">
<div role="button" data-action="click->search#open keydown.meta+k@document->search#open keydown.ctrl+k@document->search#open" class="outline secondary search">
<%= heroicon "magnifying-glass" %>
<span>Search</span>
<kbd>Cmd/Ctrl+K</kbd>
</div>
<dialog data-search-target="dialog">
<article>
@julianrubisch
julianrubisch / convert_to_webp.rb
Last active October 4, 2024 19:46
Ruby Oneliners to convert images to webp and generate thumbnails
require 'fileutils'
# Loop through all .jpg and .png files in the current directory
Dir.glob("{*.jpg,*.png}").each do |img|
# Construct the output filename with .webp extension
output_filename = "#{File.basename(img, File.extname(img))}.webp"
# Execute ffmpeg command to convert the image
system("ffmpeg -i '#{img}' '#{output_filename}'")
end
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static classes = ['highlight']
connect () {
this.element
.querySelector(`a[name='${window.location.hash.slice(1)}']`)
?.parentElement?.classList?.add(...this.highlightClasses)
}
class PurgeOrphanedNotificationsJob < ApplicationJob
queue_as :default
def perform
Notification.find_each do |n|
n.to_notification.message
rescue
n.destroy
end
end
class PurgeOrphanedNotificationJob < ApplicationJob
queue_as :default
def perform
Notification.find_each do |n|
n.to_notification.message
rescue
n.destroy
end
end
@julianrubisch
julianrubisch / run_pagespeed.rb
Created November 13, 2022 16:01
Pagespeed Runner
#!/usr/bin/env ruby
require_relative "../config/environment"
require "pagespeed_insights"
require "optparse"
require "concurrent"
options = {}
OptionParser.new do |parser|