Skip to content

Instantly share code, notes, and snippets.

<%= form_for(board, html: {class: "space-y-4"}) do |form| %>
<div>
<%= form.label :title, class: "block text-sm font-medium text-gray-700" %>
<%= form.text_field :title %>
</div>
<div>
<%= form.fields_for :embeds do |embed_form| %>
<%= embed_form.label :input, class: "sr-only" %>
<%= embed_form.text_field :input, placeholder: "Enter an embeddable link", data: {reflex_permanent: true} %>
@julianrubisch
julianrubisch / looper.sc
Created March 17, 2021 11:37
Supercollider Variable Length Looper
(
Server.killAll;
~gtranspose = 0;
~rec_end = 0;
~stretch = 1.0;
~density = 0.0;
~num_channels = 12;
~pitch_env_amp = 0.0;
~pitch_range = 0.0;
<!-- app/views/boards/_board.html.erb -->
<%= render partial: "embeds/embed", collection: embeds, locals: {board: board}, cached: true %>
<%= render partial: "embeds/embed", collection: embed_templates %>
@julianrubisch
julianrubisch / deploy_script.sh
Created March 26, 2021 08:58
Hatchbox phoenix configuration
# Phoenix
if grep -q '^ "phoenix"' mix.lock; then
source $HOME/.asdf/asdf.sh
source $HOME/.asdf/completions/asdf.bash
export $(cat $RELEASE_DIR/../../.rbenv-vars | xargs)
echo '
-----> Detected Phoenix app.'
mix local.rebar --force
mix local.hex --force
# app/helpers/application_helper.rb
module ApplicationHelper
def onboarding_step_path(workflow)
board = workflow.user.boards&.first
case workflow.next_step
when :create_board
new_board_path
when :create_embed
board_path(board)
when :create_comment
# app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
cattr_accessor :skip_callbacks
end
# app/models/concerns/user_notifiable.rb
module UserNotifiable
included do
@julianrubisch
julianrubisch / turbo_frame_history_controller.js
Last active May 8, 2021 02:39
Tabbed navigation with turbo
import { navigator } from "@hotwired/turbo";
import { Controller } from "stimulus";
import { useMutation } from "stimulus-use";
export default class extends Controller {
connect() {
useMutation(this, { attributes: true, childList: true, subtree: true });
}
mutate(entries) {
@julianrubisch
julianrubisch / submittable.rb
Last active May 12, 2021 07:58
Allowlist Reflex Resources
module Submittable
extend ActiveSupport::Concern
include StimulusReflex::ConcernEnhancer
included do
prepend_before_reflex do
instance_variable_set("@#{resource_name.underscore}", resource_class.new(submit_params))
end
end
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
identified_by :session_id
def connect
self.current_user = env["warden"].user
self.session_id = request.session.id
reject_unauthorized_connection unless self.current_user || self.session_id
end
// useHotkeys.js
import hotkeys from "hotkeys-js";
export const bindHotkeys = (controller) => {
hotkeys.filter = () => true;
for (const [hotkey, handler] of Object.entries(
controller.constructor.hotkeys
)) {
hotkeys(hotkey, (e) => controller[handler](e));