Skip to content

Instantly share code, notes, and snippets.

Dynamic UI Disposition with Kredis

What is Kredis?

Brief introduction to “Keyed Redis”. What are the benefits of using it over “vanilla” Redis access? When does it make sense to use it instead of persisting to the database?

Case Study: Persist and Restore a Collapsed/Expanded State

What problem are we trying to solve?

post "events", to: "events#create", constraints: ->(req) do
req.user_agent == "SavvyCal Webhooks (https://savvycal.com)" &&
req.params["type"] == "event.created"
end
post "events", to: "events#update", constraints: ->(req) do
req.user_agent == "SavvyCal Webhooks (https://savvycal.com)" &&
["event.rescheduled", "event.canceled"].include?(req.params["type"])
end
import { Controller } from '@hotwired/stimulus'
import autoAnimate from '@formkit/auto-animate'
export default class extends Controller {
connect () {
autoAnimate(this.element)
}
}
resources :media, shallow: true,
constraints: ->(req) do
current_user = req.env["warden"].user(:user)
Flipper.enabled?(:media_uploads, current_user)
end
class Chart < ApplicationRecord
validate do |chart|
schema = Rails.cache.fetch("vega_lite_schema/v5") do
Faraday.get("https://vega.github.io/schema/vega-lite/v5.json").body
end
JsonSchemaValidator.new(chart, schema: schema, json: vega_json, field: :vega_json).validate
end
end
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
connect () {
this.element.addEventListener('change', this.handleChange.bind(this))
}
handleChange (event) {
this.traverseDown(event.target, event.target.checked)
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
connect () {
this.element.addEventListener('change', this.handleChange.bind(this))
}
handleChange (event) {
this.traverseDown(event.target, event.target.checked)
}
class Event < ApplicationRecord
# Associations
belongs_to :owner, class_name: "User", optional: true
belongs_to :event_source, polymorphic: true
has_noticed_notifications
# ...
end
@julianrubisch
julianrubisch / script.rb
Last active February 18, 2022 12:03
ActiveStorage DirectUpload via Faraday
require "faraday"
require "faraday/multipart"
token = ARGV.shift
absolute_path = File.expand_path(ARGV.shift)
# TODO how could we require "active_storage/blob" without eager loading the whole app
blob = ActiveStorage::Blob.build_after_unfurling(io: File.open(absolute_path), filename: File.basename(absolute_path))
@julianrubisch
julianrubisch / updates_for_compat.js
Last active January 2, 2022 11:14
CR updates-for SR compat
import { UpdatesForElement } from "cable_ready";
import activeElement from "cable_ready/javascript/active_element";
document.addEventListener("stimulus-reflex:before", (event) => {
recursiveMarkUpdatesForElements(event.detail.element);
});
document.addEventListener("stimulus-reflex:after", (event) => {
setTimeout(() => {
recursiveUnmarkUpdatesForElements(event.detail.element);