Skip to content

Instantly share code, notes, and snippets.

View KonnorRogers's full-sized avatar

Konnor Rogers KonnorRogers

View GitHub Profile
@KonnorRogers
KonnorRogers / refresh.html
Created September 19, 2024 16:21
Refresh button for Turbo
<button type="button" data-controller="refresh">Refresh</button>
<script type="module">
import { Controller } from "@hotwired/stimulus"
export default class RefreshController extends Controller {
connect () {
this.element.addEventListener("click", this.sendRefresh)
}
@KonnorRogers
KonnorRogers / index.html
Created August 23, 2024 05:11
the joy of SSR
<!-- Case 1 -->
<my-input value="foo">
<template shadowrootmode="open">
<input value="foo">
</template>
</my-input>
<script>
myInput.value = "bar"
customElements.define("my-input", MyInput)
@KonnorRogers
KonnorRogers / cursed.css
Last active August 18, 2024 01:04
Cursed CSS for selected one side of the table
/**
This fancy shenanigans is what allows users to only select 1 side of a diff.
Inspired by this hack: https://stackoverflow.com/posts/73517303/revisions
*/
tr td {
user-select: none;
}
/** I'm not quite sure why its "n+4" instead of "n+3", when <td> 1-3 is the left, and <td> 4-6 is the right */
@KonnorRogers
KonnorRogers / my-element.ts
Last active July 16, 2024 16:17
Catching hydration errors in Lit
class MyElement extends LitElement {
protected update(changedProperties: PropertyValues<this>): void {
try {
super.update(changedProperties)
} catch (e) {
// We should probably check the contents of the message since this could error on a regular update??
// I really dont know. Its hacky, but it works.
const event = new Event("lit-hydration-error", { bubbles: true, composed: true, cancelable: false })
// @ts-expect-error leave me alone TS.
event.error = e
if (typeof ResizeObserver === "undefined") {
globalThis.ResizeObserver = class {
// eslint-disable-next-line
constructor (..._args: ConstructorParameters<typeof ResizeObserver>) {}
// eslint-disable-next-line
observe (..._args: Parameters<ResizeObserver["observe"]>) {}
// eslint-disable-next-line
unobserve (..._args: Parameters<ResizeObserver["unobserve"]>) {}
// eslint-disable-next-line
disconnect (..._args: Parameters<ResizeObserver["disconnect"]>) {}
@KonnorRogers
KonnorRogers / copy-shoelace.bash
Created June 28, 2024 21:31
copying shoelace for next
rm -rf ../../shoelace-nextjs-lazy/node_modules/@shoelace-style/shoelace \
&& mkdir -p ../../shoelace-nextjs-lazy/node_modules/@shoelace-style/shoelace \
&& cp -R ./{LICENSE.md,README.md,cdn,dist,package.json} ../../shoelace-nextjs-lazy/node_modules/@shoelace-style/shoelace/
@KonnorRogers
KonnorRogers / autocmds.lua
Created June 9, 2024 22:03
StandardRB with lazyvim
-- ~/.config/nvim/config/autocmds.lua
-- https://github.com/standardrb/standard/wiki/IDE:-neovim
vim.api.nvim_create_autocmd("FileType", {
pattern = "ruby",
group = vim.api.nvim_create_augroup("StandardRB LSP", { clear = true }), -- also this is not /needed/ but it's good practice
callback = function()
vim.lsp.start {
name = "standard",
cmd = { "~/.asdf/shims/standardrb", "--lsp" },
@KonnorRogers
KonnorRogers / ruby_lsp.lua
Created June 9, 2024 04:18
Lazy vim disable solargraph and use ruby_lsp
return {
-- add ruby_lsp to lspconfig and disable solargraph
{
"neovim/nvim-lspconfig",
---@class PluginLspOpts
opts = {
---@type lspconfig.options
servers = {
-- ruby_lsp will be automatically installed with mason and loaded with lspconfig
ruby_lsp = {},
@KonnorRogers
KonnorRogers / error_dump.txt
Created May 3, 2024 04:46
Tanstack Error Message
Uncaught Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Vs https://tanstack.com/_build/assets/client-1mQvwBVG.js:38
uf https://tanstack.com/_build/assets/client-1mQvwBVG.js:40
sf https://tanstack.com/_build/assets/client-1mQvwBVG.js:40
kh https://tanstack.com/_build/assets/client-1mQvwBVG.js:40
nf https://tanstack.com/_build/assets/client-1mQvwBVG.js:40
S https://tanstack.com/_build/assets/client-1mQvwBVG.js:25
T https://tanstack.com/_build/assets/client-1mQvwBVG.js:25
2 client-1mQvwBVG.js:38:4791
Uncaught Error: Minified React error #422; visit https://reactjs.org/docs/error-decoder.html?invariant=422 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
@KonnorRogers
KonnorRogers / pseudo-morph.js
Created February 5, 2024 17:42
A pseudo-morph algorithm for custom elements
const domParser = new DOMParser()
function morphCustomElement (currentEl) {
const tagName = currentEl.tagName.toLowerCase()
const isRegistered = Boolean(window.customElements.get(tagName))
if (!isRegistered) return
// TODO: This should ideally be a contextualFragment of where the element currently lives so it can have context of