Skip to content

Instantly share code, notes, and snippets.

View doeixd's full-sized avatar

Patrick G doeixd

View GitHub Profile
@doeixd
doeixd / scopedcss.js
Last active June 25, 2024 16:01
Scoped CSS Code Golf: The following is a "one-line" snippet I have created to enable scoped style tags. It supports, :global, media queries, keyframes, and adding and removing style tags/the scoped attribute. It's pretty hacky, and there may be some unexpected edge cases with the regexes, but it works for me! I mostly created it for fun, and as …
window.addEventListener('DOMContentLoaded',(a,d=document,s='STYLE',p=(d.head.innerHTML+=`<${s} id='g'></${s}>`,'scoped'),f=(e,x,y,i=e?.dataset?.s??new Date%1000,b=((e.dataset.s=i,a='attributes',x='textContent'),e[a][p]))=>{(e?.parentElement??(i='html'))?.classList?.[b?'add':'remove'](i);e[x]=e?.[x]?.replace(/(?<=^([ \t]*):global\s?{\n?)[\S\s]*?(?=^\1})|(?<s>.s-\d+\s)/gm,(...m)=>(!m?.[5]?.s&&(g[x]+=m[0]),''))?.replace(/^(?<i>[ \t]*)(?![@:]|(?:to|from|\d+%))(?<s>(?:\S|(?<=\S)\s(?!{))*)(?=\s?{$)/gm,`$<i>${b?`.${i} `:''}$<s>`)},m=new MutationObserver(l=>l.map(r=>[...r?.addedNodes,r.target].map(n=>n?.tagName==s&&f(n)))).observe(d.documentElement,{[a]:1,childList:1,subtree:1,attributeFilter:[p]}))=>d.querySelectorAll(s+`[${p}]`).forEach(f))
@doeixd
doeixd / lib.js
Last active May 9, 2024 11:48
lib.js
function ensureRunAfterDOM (fn) {
let handleDOMLoaded = Fn(fn)
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', handleDOMLoaded);
} else {
handleDOMLoaded();
}
}
function Fn (fn) {
@doeixd
doeixd / reset.css
Last active June 18, 2024 13:33
my css reset
@layer reset {
*, *::before, *::after { transition: all ease-in-out 100ms; margin:0; padding: 0; box-sizing: border-box; vertical-align: baseline; min-width: 0; scroll-behavior: smooth }
:root { --bodyFontSize: clamp(13.5px, calc(1.2vw * 2), 16px) }
:where(html) { text-size-adjust: none; -webkit-text-size-adjust: none; -moz-text-size-adjust: none; tab-size: 4; font-family: 'Work Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif ; color: #333; }
:where(:not(:defined)) { display: block; }
:where(:is(body, html)) { width: 100%; height: 100%; }
:where(body) { line-height: 1.5; -webkit-font-smoothing: antialiased; font-size: var(--bodyFontSize); }
:where(:is(img, picture, video, canvas, svg)) { display: block; max-width: 100%; vertical-align: middle; }
:where(:is(input, button, textarea, select)) { font: inherit; cursor: pointer; }
:where(*:not(main, body, .prose, .app, .root, #root) > :is(h1, h2, h3, h4, h5, h6)),
@doeixd
doeixd / framework.js
Last active January 22, 2024 20:36
framework.js
import { createContext as unCreateContext } from 'unctx'
import { createFallback, isString } from './utilities.mjs'
// Setup
export function init() {
window.__registry = {
initial_component_contexts: {},
component_instances: {}
}
@doeixd
doeixd / day3.mjs
Created December 4, 2023 13:11
day3.mjs
let isTest = Deno.args.join('').match(/test\d?/)?.[0]
if (isTest && !/\d/.test(isTest.split('').at(-1))) isTest += '1'
let file = await Deno.readTextFile(`./${isTest || `input`}`)
file = file.trim('').split('\n')
let valid_parts_acc = 0
let gear_acc = 0
let part_number_map = {}
@doeixd
doeixd / day5.mjs
Created December 5, 2023 21:16
day5.mjs
let isTest = Deno.args.join('').match(/test\d?/)?.[0]
if (isTest && !/\d/.test(isTest.split('').at(-1))) isTest += '1'
let file = await Deno.readTextFile(`./${isTest || `input`}`)
file = file.trim('').split('\n\n')
let some_seeds = file[0].split(':')?.[1].trim().split(/\s+/).map((l) => +l)
file = file.slice(1)
@doeixd
doeixd / inital.md
Created January 23, 2024 19:33
Behavior Elements

Behavior Elements

The worst part of using web components is dealing with the Shadow DOM, and templating in general. However when web components are just used to add small bits of interactivity to prerendered markup, they become extremely connivent, portable across frameworks/languages, easy to style, don't require immediate hydration, and do not require a custom server-side rendering step.

Behavior Elements is a simple utility function which aids in the creation of the sort of web components whose primary job is to add small bits of simple interactivity to such prerendered markup. Behavior Elements is best used in websites that are server-driven/multi page, because there is no rendering cycle, diffing, dirty-checking, global hydration, etc. it's best that all/most application state / routing reside with the server.

Behavior Elements aims to strike the balance between being simple, familiar, and easy to work with, yet still providing small additions of functionality/magic that reduces friction in common

@doeixd
doeixd / SolidStartup.md
Created January 31, 2024 17:30
SolidStartup

SolidStartup inspired by Blitz.js and Vitesse

drizzle schema, postgres

uses lucia auth for auth

will generate valibot validators, trpc crud functions, and kobalte / modular forms forms, , solid-tanstack tables for tables

uses unocss, unofonts, uno icons, cva, critters, iconify

@doeixd
doeixd / banana.md
Created February 7, 2024 19:31
banana

Banana.js logo character

Banana.js

Banana is a front-end JavaScript framework for adding interactivity to server-driven websites (Think: Astro, HTMX, eCommerce Themes, HTML templates, etc.)

Banana aims to be easily integrated into existing projects, and is mostly unopinionated about state management, templating, or styling, allowing you to pick and choose what works best for your project!

@doeixd
doeixd / dci.ts
Created March 14, 2024 13:11
DCI TS
import { A } from "solid-start";
import Counter from "~/components/Counter";
import capitalize from "lodash.capitalize"
import { match, P } from "ts-pattern";
import { Err, Ok, Result, Option, Some, None } from "ts-results"
import type { Appearances, SubcaptionName, CaptionOverallScore, SubcaptionInitials, CaptionName, DciSeason, Competition } from "~/utils/api_types";
import { Convert } from "~/utils/api_types";
// import type Result from "ts-results"