Skip to content

Instantly share code, notes, and snippets.

View denjamio's full-sized avatar
🎯
Focusing

Diego Enjamio denjamio

🎯
Focusing
View GitHub Profile
@lazaronixon
lazaronixon / _form.html.erb
Last active April 10, 2025 04:14
Hotwire Event-Driven Update Pattern
<%= form_with model: citizen, class: "card flex flex-col gap", data: { controller: "form" } do |form| %>
<div class="flex flex-col gap mb-2">
<div class="flex flex-col gap-half">
<% countries = Country.order(:name) %>
<%= label_tag :country_id, "Country", class: "text-sm font-medium leading-none" %>
<%= select_tag :country_id, options_from_collection_for_select(countries, :id, :name, citizen.country_id), include_blank: "Select one", class: "input", data: { action: "form#submit", form_submitter_param: "on_country_change" } %>
</div>
<div class="flex flex-col gap-half">
<% states = State.where(country_id: citizen.country_id).order(:name) %>
@schappim
schappim / _webrtc.html.erb
Created December 18, 2024 02:31
OpenAI’s Real-time API (with WebRTC) using StimulusJS and Rails
<%# A partial that can be placed anywhere to utilise the Real-time API (with WebRTC) %>
<div data-controller="webrtc" class="bg-gray-600 rounded-full text-white mb-4 ">
<audio data-webrtc-target="audio"></audio>
<button data-webrtc-target="toggle" data-action="click->webrtc#toggleAudio" class="relative flex items-center justify-center w-full font-medium min-w-[150px] min-h-[40px]">
<div class="w-full text-center" data-button-text>Enable Audio Chat</div>
<div data-webrtc-target="spinner" class="hidden absolute">
<svg class="animate-spin h-5 w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
@Shpigford
Shpigford / .cursorrules
Last active April 1, 2025 08:09
Cursor Rules
# Original instructions: https://forum.cursor.com/t/share-your-rules-for-ai/2377/3
# Original original instructions: https://x.com/NickADobos/status/1814596357879177592
You are an expert AI programming assistant that primarily focuses on producing clear, readable SwiftUI code.
You always use the latest version of SwiftUI and Swift, and you are familiar with the latest features and best practices.
You carefully provide accurate, factual, thoughtful answers, and excel at reasoning.
- Follow the user’s requirements carefully & to the letter.
@dbreunig
dbreunig / file_processing_with_ractor_pool.rb
Created June 7, 2024 15:48
A simple demo for processing files using a Ractor pool
def process_file(filename)
puts "Processing file: #{filename}"
File.open(filename) do |filename|
# Do stuff
end
end
puts "Done processing file: #{filename}"
end
# Define the number of Ractors in the pool
## IDENTITY and PURPOSE
You are programming assistant specialized in {{ DESCRIBE HERE THE LANGUAGE/FRAMEWORKS (React 19, Next.js and Tailwind) }} .
## TONE AND STYLE
You adhere to {{ NAME OF THE TOOLS }} conventions. You respect conventions like camel case, function naming, and best practices.
## HERE EXAMPLES OF THE CODE CONVENTIONS I WANT YOU TO USE
@RStankov
RStankov / belongs_to_polymorphic.rb
Last active March 25, 2025 09:11
Database tips
module AngrySupport::BelongsToPolymorphic
def belongs_to_polymorphic(name, allowed_classes:, **options)
belongs_to name, polymorphic: true, **options
validates "#{name}_type", inclusion: { in: allowed_classes.map(&:name), allow_nil: !!options[:optional] }
define_singleton_method(:"#{name}_types") { allowed_classes }
define_singleton_method(:"with_#{name}") do |type|
type = case type
@zachdaniel
zachdaniel / stream_distribute.ex
Last active June 15, 2024 14:06
A small demo to show how you might, given a stream, do a "fan out", processing different elements in separate streams. Powered by simple primitives like `Stream.resource` and `spawn_link`. Open in Livebook: https://livebook.dev/run?url=https%3A%2F%2Fgist.github.com%2Fzachdaniel%2Fd5ab06a9d2362fceeb6d27c37b206e28
<!-- livebook:{"persist_outputs":true} -->
# Distribute
## Section
A small toy to show how you might, given a stream, do a "fan out", processing different elements in separate streams. Powered by simple primitives like `Stream.resource` and `spawn_link`.
```elixir
defmodule Distribute do
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
require "json"
require "faraday"
# Configure before using or execute this code as-is
# and get a 401
module Configuration
class << self
attr_accessor :organization_id, :api_key
end
end
@IvanIvashchenko
IvanIvashchenko / Dockerfile
Created March 14, 2024 16:23
Example of local docker configuration for simple RoR application
FROM ubuntu:22.04 AS build
SHELL ["/bin/bash", "-c"]
ENV RUBY_MAJOR 3.2
ENV RUBY_VERSION 3.2.2
# Default directory
ENV WORKING_PATH /app
RUN mkdir -p $WORKING_PATH