Skip to content

Instantly share code, notes, and snippets.

URI.open(url) do |uri|
base_uri = uri.base_uri
listable_type = case base_uri.to_s
when /soundcloud.com\/(?<artist>.+)\/tracks/
raise UnparsableTrackUrlError
when /soundcloud.com\/(?<artist>.+)\/sets\/(?<title>.+)/
SoundCloudPlaylist
when /soundcloud.com\/(?<artist>.+)\/(?<title>.+)/
SoundCloudTrack
@julianrubisch
julianrubisch / content-element-input.js
Created June 24, 2021 07:12
contenteditable lit-element
import { LitElement, html, css } from "lit";
import { property, customElement } from "lit/decorators.js";
@customElement("content-element-input")
class ContentElementInput extends LitElement {
@property({ type: Boolean })
contentEditable = true;
@property({ type: String })
placeholder = "";
module YieldsMembers
module ClassMethods
mattr_accessor :method_names
def yields_members_for(*method_names)
self.method_names = method_names
end
end
def initialize(...)
super(...)
module YieldsMembers
module ClassMethods
def yields_members_for(*method_names)
module_eval do
# method_names.each do |method_name|
binding.pry
define_method :add do |*members, &proc|
puts "IN PREPENDED MODULE"
binding.pry
super members
// 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));
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
@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
@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) {
# 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
# 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