Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
julianrubisch / index.html
Last active March 9, 2023 02:09
Simple stimulusjs parallax controller using https://simpleparallax.com/
<img src="img/some-nice-photo.jpg" data-controller="parallax" />
@julianrubisch
julianrubisch / head_tail.scd
Last active November 22, 2020 15:17
Supercollider Head/Tail Recursion
// head tail recursion in SuperCollider
(
~array = Array.exprand(5, 30, 300).round;
f = {
|array, acc|
if(array.isEmpty,
acc,
{
var head;
@julianrubisch
julianrubisch / 01-board.rb
Last active May 6, 2022 09:50
StimulusReflex Patterns - 1 Forms
# app/models/board.rb
class Board < ApplicationRecord
has_many :embeds
end
@julianrubisch
julianrubisch / 02-embed-form.erb
Last active May 13, 2021 15:25
StimulusReflex Patterns - 2 Imports
<!-- app/views/embed_imports/_form.html.erb -->
<%= form_with(model: [board, embed_import]) do |form| %>
<%= form.file_field :upload %>
<%= form.submit "Upload Links", class: "inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-lime-600 hover:bg-lime-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-lime-500" %>
<% end %>
import { Droppable } from "@shopify/draggable";
import ApplicationController from "./application_controller";
export default class extends ApplicationController {
static targets = ["container", "dropzone", "targetDropzone"];
connect() {
this.droppable = new Droppable(this.containerTargets, {
draggable: ".draggable",
dropzone: ".dropzone"
@julianrubisch
julianrubisch / parameterize-stream-identifiers.rb
Last active February 1, 2021 12:31
StimulusReflex Patterns - 3 Optimistic UI
# app/channels/reaction_channel.rb
class ReactionChannel < ApplicationCable::Channel
def subscribed
stream_from "reaction:#{current_user.id}"
end
end
# app/jobs/stream_reaction_job.rb
class StreamReactionJob < ApplicationJob
include CableReady::Broadcaster
(defun jr/gist-carbon-region ()
"Create a gist, upload to carbon and put the gist URL in the kill ring.
This function makes it easy to tweet a marked region: Invoke it and
the region will be uploaded to Github, the gist ID appended to carbon,
and the default browser opened. As a convenience, the created gist URL
is also placed in the kill ring.
gist mode (https://github.com/defunkt/gist.el) is required."
(interactive)
class FilterReflex < ApplicationReflex
include Filterable
def filter
resource, param = element.dataset.to_h.fetch_values(:resource, :param)
value = element.dataset.value || element.value
set_filter_for(resource, param, value)
end
end
# app/filters/base_filter.rb
class BaseFilter
include ActiveModel::Model
include ActiveModel::Attributes
def initialize(session)
@_session = session
super(@_session.fetch(:filters, {})[filter_resource_class])
end
import { Controller } from 'stimulus'
export default class extends Controller {
static targets = ['overlay']
static values = {
hidden: Boolean
}
static classes = ['hidden', 'shown']
toggle () {