This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var code = document.querySelector(":is(.language-bash, .language-shell, .language-zsh, .language-sh, .language-console).highlighter-rouge pre.highlight > code") | |
code.innerHTML = code.innerHTML.split("\n").map((str) => { | |
return str.replace(/^(\w)/, "<span class='highlight-command-line-start'>$</span>$1") | |
}).join("\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { decode } from "blurhash" | |
export function blurHashToDataURL(hash: string | undefined): string | undefined { | |
if (!hash) return undefined | |
const pixels = decode(hash, 32, 32) | |
const dataURL = parsePixels(pixels, 32, 32) | |
return dataURL | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus"; | |
import { get } from "@rails/request.js"; | |
import { PageSnapshot } from "@hotwired/turbo"; | |
export default class extends Controller { | |
static values = { hoverTime: Number }; | |
connect() { | |
this.element.addEventListener("mouseover", this.prefetch.bind(this)); | |
this.element.addEventListener("touchstart", this.prefetch.bind(this)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cable-car href="/cc/cable_car" csrf-token="94IkWdvagUHWPGVkD+VeBFVjGoM0zXAf6tgm6BPU+kEpOj2BTtI6bXJQzEDXGAF+R6Dc1ek7oNouatTMrbUy"> | |
<button | |
onclick="this.closest('cable-car').post(this, {extra: 123})" | |
data-x="1" | |
output="#show-the-things" | |
> | |
Do a thing! | |
</button> | |
<section id="show-the-things"></section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using a predefined hash | |
hash = { field1: "foo", field2: "bar" } | |
HashStruct = Struct.new(*hash.keys, keyword_init: true) | |
hash_struct = HashStruct.new(hash) | |
hash_struct.field1 # => "foo" | |
hash_struct.field2 # => "bar" | |
hash_struct.field3 # => ERROR! | |
My goal with this was to wrap the terrible YouTube Embed API in a Stimulus controller that would allow me to access the underlying API while providing some convenience methods. One key outcome is that the controller emits youtube
events which contain the current position in the video. This means that other code can now respond to the position you are at in the video.
<div data-controller="youtube" data-youtube-code-value="Lo_1pyQ7xvc">
<button data-action="youtube#play">Play</button>
<button data-action="youtube#pause">Pause</button>
<button data-action="youtube#stop">Stop</button>
<br>
<div data-youtube-target="frame"></div>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
include CableReady::Broadcaster | |
include Toastable | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/jobs/geocode_job.rb | |
class GeocodeJob < ApplicationJob | |
def perform(model) | |
model.geocode | |
end | |
end |
NewerOlder