Skip to content

Instantly share code, notes, and snippets.

# Put this in the controller
def filters_for_this_action
_process_action_callbacks.select do |filter|
ifs = filter.options[:if].first || 'true'
unlesses = filter.options[:unless].first || 'false'
eval(ifs) && !eval(unlesses)
end.map { |filter| [filter.kind, filter.filter] }
end
@jameskerr
jameskerr / reduxModel.ts
Last active November 23, 2020 19:16
Redux Model
/* This could be a way to reduce (haha) the redux boilerplate. */
import {createStore} from "redux"
function createReduxModel(prefix, config) {
const actionType = (name) => `${prefix}_${name.toUpperCase()}_SET`
class Model {
constructor(store) {
for (const [name] of Object.entries(config)) {
@jameskerr
jameskerr / react-debut.tsx
Created September 9, 2023 03:11
React Debut: A component for animating elements in an out as they mount and unmount.
import {CSSTransition} from "react-transition-group"
import {forwardRef, useImperativeHandle, useRef, useState} from "react"
import {call} from "src/util/call"
export function useDebut(args: {enter?: () => any; exit: () => any}) {
const ref = useRef<any>()
const api = {
props: {
ref,
onExit: args.exit,
@jameskerr
jameskerr / multi_select_controller.js
Last active July 29, 2025 12:35
Mutli Select Stimulus Controller
import Base from "controllers/base";
export default class extends Base {
static targets = ["checkbox", "toggler", "count", "menu", "hide"];
mount() {
this.on("turbo:morph", document, this.update);
this.on("click", this.togglerTarget, this.toggle);
}
@jameskerr
jameskerr / component.rb
Created August 15, 2025 17:31
View Component Generator Script
#!/usr/bin/env ruby
# Check for -d flag
if ARGV[0] == "-d"
name = ARGV[1]
delete_mode = true
else
name = ARGV[0]
delete_mode = false
end
@jameskerr
jameskerr / compose_attrs.rb
Created August 27, 2025 19:38
Compose Attributes
def compose_attrs(a, b)
result = a.dup
b.each do |key, val|
x = result[key]
y = val
pair = [ x, y ]
if pair.any?(&:nil?)
result[key] = x || y
elsif pair.all? Hash
result[key] = compose_attrs(x, y)
@jameskerr
jameskerr / SKILL.md
Created May 30, 2026 04:20
/img skill for AI
name img
description Use this skill when the user runs /img or asks to process, optimize, or convert images for their Rails app. Converts PNG exports from Sketch (or any PNG) to WebP using cwebp, places the result in app/assets/images/, and outputs the ready-to-use image_tag ERB snippet. Triggers on /img <filename>, "process this image", "convert to webp", "optimize this PNG for Rails".

img skill

Converts a PNG to WebP and outputs the Rails image_tag ERB snippet.

What it does