Skip to content

Instantly share code, notes, and snippets.

@mizchi
mizchi / singlefile-frontend.md
Created November 23, 2023 10:27
How to run a minimal front-end stack in Single-File for prototyping.
View singlefile-frontend.md

Original(japanese) https://zenn.dev/mizchi/articles/standalone-html-frontend

Mostly translated by deepl


How to run a minimal front-end stack in Single-File for prototyping.

Note: Do not use in production, tailwind is running in CDN mode and esm.sh builds scripts dynamically, so performance is not good.

View shadcn-preview-plane.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.tailwindcss.com"></script>
<style type="text/tailwindcss">
@tailwind base;
@mizchi
mizchi / backpack-battles-first-round.md
Last active October 24, 2023 13:04
Backpack Battles の1,2 ラウンドの考察
View backpack-battles-first-round.md

1~2 ラウンドの勝敗を分けるものはなにか。

Backpack Battles で 1~2R でスタミナが切れない想定で、ダメージ/回復/ブロックを同じ価値としてゴールドあたりの効率を計算する。 初期バッグや石は考慮しない

野菜の比較

Banana          0.26/gold
Banana(Sale) 0.40/gold
View try-vite-singlefile-inlined.ts
import { test, expect } from 'vitest';
import { build, splitVendorChunkPlugin } from 'vite';
import path from 'path';
import { OutputAsset, OutputBundle, OutputChunk, RollupOutput } from 'rollup';
import ts from 'typescript';
const root = path.join(__dirname, "__fixtures")
test("nested", async () => {
const a = 'export default Math.random()';
View check-b64-instance.ts
import {test, expect} from 'vitest';
test("nested", async () => {
const a = 'export default Math.random()';
const b = `export default () => import('data:text/javascript;base64,${btoa(a)}')`;
const bmod = await import(`data:text/javascript;base64,${btoa(b)}`);
const amod = await import(`data:text/javascript;base64,${btoa(a)}`);
expect(await bmod.default()).not.toBe(await amod.default);
});
View Grid.tsx
/*
Grid css layout utilities for [x, y, w, h] grid areas.
Example:
export default function App() {
return (
<>
<Grid
rows={["32px", "1fr", "1fr", "1fr", "1fr"]}
@mizchi
mizchi / main.rs
Last active September 24, 2023 16:08
View main.rs
fn main() {
let x: Option<Result<(&str, &str), ()>> = Some(Ok(("x", "y")));
// if let
if let Some(Ok((a, _))) = x {
if a == "x" {
println!("a=x");
}
}
// match
match x {
View deno-cli-base.ts
#!/usr/bin/env -S deno run -A
/*
$ edit ~/bin/cmd
$ chmod +x ~/bin/cmd
$ cmd -f
# Run
$ ls -al
total 24
drwxr-xr-x 10 kotaro.chikuba staff 320 Sep 22 20:16 .
drwxr-xr-x 9 kotaro.chikuba staff 288 Sep 22 20:01 .git
@mizchi
mizchi / jsx_pure_adder.ts
Created September 12, 2023 08:29
Add pure annotation to jsx
View jsx_pure_adder.ts
import ts from "typescript";
import { cloneNode } from "ts-clone-node";
import { expect, test } from "vitest";
test("jsx pure adder", async (t) => {
const transformer: ts.TransformerFactory<any> = (context) => {
return (sourceFile) => {
const visitor: ts.Visitor = (node) => {
if (ts.isCallExpression(node)) {
if (ts.isIdentifier(node.expression) && (node.expression.text === "_jsx" || node.expression.text === "_jsxs")) {
@mizchi
mizchi / Root.tsx
Last active September 6, 2023 11:15
Minimum Vite SSR (dev)
View Root.tsx
// src/Root.tsx
import {useState} from "react";
export default function Root() {
const [count, setCount] = useState(0);
return <div>
<h1>App</h1>
<button type="button" onClick={() => setCount(n => n+1)}>{count}</button>
</div>
}