Skip to content

Instantly share code, notes, and snippets.

@JLarky
JLarky / index.ts
Created July 22, 2025 16:15
lift-html solid counter
import { liftHtml } from '@lift-html/core';
import html from "solid-js/html";
import { createSignal } from "solid-js";
import { render } from "solid-js/web";
const css = /*css*/ `
* { font-size: 200%; }
span {
width: 4rem;
@JLarky
JLarky / com.chrome.devtools.json.ts
Created July 15, 2025 20:30
Astro .well-known/appspecific/com.chrome.devtools.json.ts
// put this in src/pages/.well-known/appspecific/com.chrome.devtools.json.ts
import type { APIRoute } from "astro"
import { join } from "node:path"
// https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md
export const GET: APIRoute = () => {
return new Response(
JSON.stringify({
"workspace": {
"root": join(import.meta.dirname, "../../../../../.."),
@JLarky
JLarky / .zshrc
Created May 24, 2025 01:59
tmp function with zsh
# tmp function
function tmp() {
local tmp_dir=$(mktemp -d)
echo "Created temporary directory: $tmp_dir"
cd $tmp_dir
}
@JLarky
JLarky / README.md
Last active April 11, 2025 07:58
Debug JSON with json.pub for Astro
@JLarky
JLarky / HydrationCounter.astro
Created April 5, 2025 03:34
nice and easy "did my React had hydration errors?" script https://x.com/JLarky/status/1908362375490867547
---
declare global {
interface Window {
had_hydration_error?: string;
}
}
---
<script>
const prefix = 'Uncaught Error: ';
<!DOCTYPE html>
<html>
<head is="my-head">
<script>
customElements.define(
"my-head",
class extends HTMLHeadElement {
connectedCallback() {
this.setAttribute("live", "true");
this.appendChild(document.createElement("title")).textContent =
@JLarky
JLarky / DebugJSON.astro
Last active April 11, 2025 07:59
Debug JSON with json.pub for Astro
---
type Props = {
json: unknown;
};
---
<view-as-json><pre data-target="view-as-json:pre" set:text={JSON.stringify(Astro.props.json, null, 2)} /></view-as-json>
<script is:inline type="module">
// @ts-ignore
import { liftHtml } from 'https://esm.sh/@lift-html/[email protected]';
@JLarky
JLarky / Embed.tsx
Created September 10, 2024 06:21
React version of Embed block for react-sdk (sdk v2) for Builder.io
// https://github.com/BuilderIO/builder/blob/21c96eff31434f51adc9ec3e6071256572cd261b/packages/sdks/src/blocks/embed/embed.lite.tsx
import { useEffect, useRef, useState } from 'react';
export interface EmbedProps {
content: string;
}
const SCRIPT_MIME_TYPES = ['text/javascript', 'application/javascript', 'application/ecmascript'];
function isJsScript(script: HTMLScriptElement) {
@JLarky
JLarky / snippet.js
Created September 6, 2024 18:28
How to decode Astro props for <astro-island> element
((raw)=>{let i = { 0: t => m(t), 1: t => a(t), 2: t => new RegExp(t), 3: t => new Date(t), 4: t => new Map(a(t)), 5: t => new Set(a(t)), 6: t => BigInt(t), 7: t => new URL(t), 8: t => new Uint8Array(t), 9: t => new Uint16Array(t), 10: t => new Uint32Array(t) } , o = t => { let[l,e] = t; return l in i ? i[l](e) : void 0 } , a = t => t.map(o) , m = t => typeof t != "object" || t === null ? t : Object.fromEntries(Object.entries(t).map( ([l,e]) => [l, o(e)])); return m(raw)})(JSON.parse($0.getAttribute('props')))
@JLarky
JLarky / ServerOnly.tsx
Created August 22, 2024 00:30
How to render component only on the server
// https://x.com/JLarky/status/1826404005876301882
export function FancyStuff(props: { getFromServer?: undefined | (() => string) }) {
const [mousePos, setMousePos] = useState('0, 0');
useEffect(() => {
document.addEventListener('mousemove', (e) => {
setMousePos(`${e.clientX}, ${e.clientY}`);
});
}, []);
return (